problem_id
stringlengths 6
6
| language
stringclasses 2
values | original_status
stringclasses 3
values | original_src
stringlengths 19
243k
| changed_src
stringlengths 19
243k
| change
stringclasses 3
values | i1
int64 0
8.44k
| i2
int64 0
8.44k
| j1
int64 0
8.44k
| j2
int64 0
8.44k
| error
stringclasses 270
values | stderr
stringlengths 0
226k
|
---|---|---|---|---|---|---|---|---|---|---|---|
p02326
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
// < "D:\D_Download\Visual Studio
// 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
// Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
const int adx[] = {1, 1, 1, 0, -1, -1, -1, 0};
const int ady[] = {1, 0, -1, -1, -1, 0, 1, 1};
int add(const int base, const int plus) {
if (!plus) {
return base + 1;
} else {
return 0;
}
}
// 0 :?????????1:??????2:?????????3:??? 4:?????????5:??? 6:?????? 7:????????????
// ???
vector<vector<vector<int>>>
get_cumulative_sum(const vector<vector<int>> &field) {
const int H = field.size();
const int W = field[0].size();
vector<vector<vector<int>>> sums(4, vector<vector<int>>(H, vector<int>(W)));
for (int ny = 0; ny < H; ++ny) {
for (int nx = 0; nx < W; ++nx) {
for (int k = 0; k < 2; ++k) {
int py = ny - ady[k];
int px = nx - adx[k];
if (!(px >= 0 && px < W && py >= 0 && py < H))
continue;
sums[k][ny][nx] = add(sums[k][py][px], field[ny][nx]);
}
}
}
for (int ny = H - 1; ny >= 0; --ny) {
for (int nx = 0; nx < W; ++nx) {
for (int k = 2; k < 4; ++k) {
int py = ny - ady[k];
int px = nx - adx[k];
if (!(px >= 0 && px < W && py >= 0 && py < H))
continue;
sums[k][ny][nx] = add(sums[k][py][px], field[ny][nx]);
}
}
}
return sums;
}
int getans(vector<int> hs) {
hs.emplace_back(0);
stack<pair<int, int>> que;
que.emplace(-1, 0);
int ans = 0;
for (int x = 0; x < hs.size(); ++x) {
if (que.empty()) {
que.push(make_pair(x, hs[x]));
} else {
while (!que.empty()) {
auto p = que.top();
if (p.second < hs[x]) {
que.push(make_pair(x, hs[x]));
break;
} else if (p.second == hs[x]) {
break;
} else {
int n = min(x - p.first, p.second);
int area = n * n;
ans = max(ans, area);
que.pop();
if (!que.empty()) {
auto np = que.top();
if (np.second < hs[x]) {
que.push(make_pair(p.first, hs[x]));
break;
}
}
}
}
}
}
return ans;
}
int main() {
int H, W;
cin >> H >> W;
vector<vector<int>> field(H + 2, vector<int>(W + 2, 1));
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
cin >> field[i + 1][j + 1];
}
}
auto vs = get_cumulative_sum(field);
int ans = 0;
for (int y = 1; y <= H; ++y) {
vector<int> v;
for (int x = 1; x <= W; ++x) {
v.push_back(vs[y][x][3]);
}
ans = max(ans, getans(v));
}
cout << ans << endl;
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
// < "D:\D_Download\Visual Studio
// 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
// Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
const int adx[] = {1, 1, 1, 0, -1, -1, -1, 0};
const int ady[] = {1, 0, -1, -1, -1, 0, 1, 1};
int add(const int base, const int plus) {
if (!plus) {
return base + 1;
} else {
return 0;
}
}
// 0 :?????????1:??????2:?????????3:??? 4:?????????5:??? 6:?????? 7:????????????
// ???
vector<vector<vector<int>>>
get_cumulative_sum(const vector<vector<int>> &field) {
const int H = field.size();
const int W = field[0].size();
vector<vector<vector<int>>> sums(4, vector<vector<int>>(H, vector<int>(W)));
for (int ny = 0; ny < H; ++ny) {
for (int nx = 0; nx < W; ++nx) {
for (int k = 0; k < 2; ++k) {
int py = ny - ady[k];
int px = nx - adx[k];
if (!(px >= 0 && px < W && py >= 0 && py < H))
continue;
sums[k][ny][nx] = add(sums[k][py][px], field[ny][nx]);
}
}
}
for (int ny = H - 1; ny >= 0; --ny) {
for (int nx = 0; nx < W; ++nx) {
for (int k = 2; k < 4; ++k) {
int py = ny - ady[k];
int px = nx - adx[k];
if (!(px >= 0 && px < W && py >= 0 && py < H))
continue;
sums[k][ny][nx] = add(sums[k][py][px], field[ny][nx]);
}
}
}
return sums;
}
int getans(vector<int> hs) {
hs.emplace_back(0);
stack<pair<int, int>> que;
que.emplace(-1, 0);
int ans = 0;
for (int x = 0; x < hs.size(); ++x) {
if (que.empty()) {
que.push(make_pair(x, hs[x]));
} else {
while (!que.empty()) {
auto p = que.top();
if (p.second < hs[x]) {
que.push(make_pair(x, hs[x]));
break;
} else if (p.second == hs[x]) {
break;
} else {
int n = min(x - p.first, p.second);
int area = n * n;
ans = max(ans, area);
que.pop();
if (!que.empty()) {
auto np = que.top();
if (np.second < hs[x]) {
que.push(make_pair(p.first, hs[x]));
break;
}
}
}
}
}
}
return ans;
}
int main() {
int H, W;
cin >> H >> W;
vector<vector<int>> field(H + 2, vector<int>(W + 2, 1));
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
cin >> field[i + 1][j + 1];
}
}
auto vs = get_cumulative_sum(field);
int ans = 0;
for (int y = 1; y <= H; ++y) {
vector<int> v;
for (int x = 1; x <= W; ++x) {
v.push_back(vs[3][y][x]);
}
ans = max(ans, getans(v));
}
cout << ans << endl;
return 0;
}
|
replace
| 109 | 110 | 109 | 110 |
-11
| |
p02326
|
C++
|
Runtime Error
|
#include <iostream>
#define HMAX 140
#define WMAX 140
using namespace std;
int main() {
int H, W, ms = 0;
int dp[HMAX + 10][WMAX + 10] = {};
cin >> H >> W;
for (int i = 1; i < H + 1; ++i) {
for (int j = 1; j < W + 1; ++j) {
cin >> dp[i][j];
if (dp[i][j] == 0) {
dp[i][j] = 1;
} else {
dp[i][j] = 0;
}
}
}
for (int i = 1; i < H + 1; ++i) {
for (int j = 1; j < W + 1; ++j) {
if (dp[i][j] != 0) {
int m = min(dp[i - 1][j - 1], dp[i - 1][j]);
dp[i][j] += min(m, dp[i][j - 1]);
ms = max(ms, dp[i][j]);
}
}
}
cout << ms * ms << "\n";
return 0;
}
|
#include <iostream>
#define HMAX 1400
#define WMAX 1400
using namespace std;
int main() {
int H, W, ms = 0;
int dp[HMAX + 10][WMAX + 10] = {};
cin >> H >> W;
for (int i = 1; i < H + 1; ++i) {
for (int j = 1; j < W + 1; ++j) {
cin >> dp[i][j];
if (dp[i][j] == 0) {
dp[i][j] = 1;
} else {
dp[i][j] = 0;
}
}
}
for (int i = 1; i < H + 1; ++i) {
for (int j = 1; j < W + 1; ++j) {
if (dp[i][j] != 0) {
int m = min(dp[i - 1][j - 1], dp[i - 1][j]);
dp[i][j] += min(m, dp[i][j - 1]);
ms = max(ms, dp[i][j]);
}
}
}
cout << ms * ms << "\n";
return 0;
}
|
replace
| 1 | 3 | 1 | 3 |
0
| |
p02326
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define mo 1005
int a[mo][mo], dp[mo][mo];
int n, m;
int main() {
while (cin >> n >> m) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
int maxs = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j])
dp[i][j] = 0;
else
dp[i][j] = min(dp[i - 1][j], min(dp[i - 1][j - 1], dp[i][j - 1])) + 1;
maxs = max(maxs, dp[i][j]);
// cout<<dp[i][j]<<' ';
}
// cout<<endl;
}
cout << maxs * maxs << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define mo 1505
int a[mo][mo], dp[mo][mo];
int n, m;
int main() {
while (cin >> n >> m) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
int maxs = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j])
dp[i][j] = 0;
else
dp[i][j] = min(dp[i - 1][j], min(dp[i - 1][j - 1], dp[i][j - 1])) + 1;
maxs = max(maxs, dp[i][j]);
// cout<<dp[i][j]<<' ';
}
// cout<<endl;
}
cout << maxs * maxs << endl;
}
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p02326
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
using namespace std;
int tate[1005][1005] = {};
int yoko[1005][1005] = {};
int dp[1005][1005] = {};
int c[1005][1005];
int main() {
int h, w;
scanf("%d %d", &h, &w);
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++)
scanf("%d", &c[i][j]);
}
int ans = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (c[i][j] == 0) {
tate[i][j] = tate[i - 1][j] + 1;
yoko[i][j] = yoko[i][j - 1] + 1;
dp[i][j] = min(tate[i][j], yoko[i][j]);
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1);
}
ans = max(ans, dp[i][j] * dp[i][j]);
}
}
printf("%d\n", ans);
return (0);
}
|
#include <algorithm>
#include <cstdio>
using namespace std;
int tate[1405][1405] = {};
int yoko[1405][1405] = {};
int dp[1405][1405] = {};
int c[1405][1405];
int main() {
int h, w;
scanf("%d %d", &h, &w);
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++)
scanf("%d", &c[i][j]);
}
int ans = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (c[i][j] == 0) {
tate[i][j] = tate[i - 1][j] + 1;
yoko[i][j] = yoko[i][j - 1] + 1;
dp[i][j] = min(tate[i][j], yoko[i][j]);
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1);
}
ans = max(ans, dp[i][j] * dp[i][j]);
}
}
printf("%d\n", ans);
return (0);
}
|
replace
| 3 | 7 | 3 | 7 |
0
| |
p02326
|
C++
|
Runtime Error
|
#include <algorithm>
#include <stdio.h>
using namespace std;
const int MAX = 140;
int main() {
int H, W;
int tile[MAX][MAX];
int ans = 0;
scanf("%d%d", &H, &W);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
scanf("%d", &tile[i][j]);
}
}
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
if (tile[y][x] == 1)
tile[y][x] = 0;
else if (x < 1 || y < 1)
tile[y][x] = 1;
else
tile[y][x] =
min(tile[y - 1][x - 1], min(tile[y - 1][x], tile[y][x - 1])) + 1;
ans = max(tile[y][x], ans);
}
}
printf("%d\n", ans * ans);
return 0;
}
|
#include <algorithm>
#include <stdio.h>
using namespace std;
const int MAX = 1400;
int main() {
int H, W;
int tile[MAX][MAX];
int ans = 0;
scanf("%d%d", &H, &W);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
scanf("%d", &tile[i][j]);
}
}
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
if (tile[y][x] == 1)
tile[y][x] = 0;
else if (x < 1 || y < 1)
tile[y][x] = 1;
else
tile[y][x] =
min(tile[y - 1][x - 1], min(tile[y - 1][x], tile[y][x - 1])) + 1;
ans = max(tile[y][x], ans);
}
}
printf("%d\n", ans * ans);
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p02327
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
// < "D:\D_Download\Visual Studio
// 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
// Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
const int adx[] = {1, 1, 1, 0, -1, -1, -1, 0};
const int ady[] = {1, 0, -1, -1, -1, 0, 1, 1};
int add(const int base, const int plus) {
if (!plus) {
return base + 1;
} else {
return 0;
}
}
// 0 :?????????1:??????2:?????????3:??? 4:?????????5:??? 6:?????? 7:??? ???
vector<vector<vector<int>>>
get_cumulative_sum(const vector<vector<int>> &field) {
const int H = field.size();
const int W = field[0].size();
vector<vector<vector<int>>> sums(4, vector<vector<int>>(H, vector<int>(W)));
for (int ny = H - 1; ny >= 0; --ny) {
for (int nx = 0; nx < W; ++nx) {
for (int k = 0; k < 3; ++k) {
sums[k].clear();
}
for (int k = 3; k < 4; ++k) {
int py = ny - ady[k];
int px = nx - adx[k];
if (!(px >= 0 && px < W && py >= 0 && py < H))
continue;
sums[k][ny][nx] = add(sums[k][py][px], field[ny][nx]);
}
}
}
return sums;
}
int getans(vector<int> hs) {
hs.emplace_back(0);
stack<pair<int, int>> que;
que.emplace(-1, 0);
int ans = 0;
for (int x = 0; x < hs.size(); ++x) {
if (que.empty()) {
que.push(make_pair(x, hs[x]));
} else {
while (!que.empty()) {
auto p = que.top();
if (p.second < hs[x]) {
que.push(make_pair(x, hs[x]));
break;
} else if (p.second == hs[x]) {
break;
} else {
int area = (x - p.first) * p.second;
ans = max(ans, area);
que.pop();
if (!que.empty()) {
auto np = que.top();
if (np.second < hs[x]) {
que.push(make_pair(p.first, hs[x]));
break;
}
}
}
}
}
}
return ans;
}
int main() {
int H, W;
cin >> H >> W;
vector<vector<int>> field(H + 2, vector<int>(W + 2, 1));
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
cin >> field[i + 1][j + 1];
}
}
auto vs = get_cumulative_sum(field);
int ans = 0;
for (int y = 1; y <= H; ++y) {
vector<int> v;
for (int x = 1; x <= W; ++x) {
v.push_back(vs[y][x][3]);
}
ans = max(ans, getans(v));
}
cout << ans << endl;
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
// < "D:\D_Download\Visual Studio
// 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
// Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
const int adx[] = {1, 1, 1, 0, -1, -1, -1, 0};
const int ady[] = {1, 0, -1, -1, -1, 0, 1, 1};
int add(const int base, const int plus) {
if (!plus) {
return base + 1;
} else {
return 0;
}
}
// 0 :?????????1:??????2:?????????3:??? 4:?????????5:??? 6:?????? 7:??? ???
vector<vector<vector<int>>>
get_cumulative_sum(const vector<vector<int>> &field) {
const int H = field.size();
const int W = field[0].size();
vector<vector<vector<int>>> sums(4, vector<vector<int>>(H, vector<int>(W)));
for (int ny = H - 1; ny >= 0; --ny) {
for (int nx = 0; nx < W; ++nx) {
for (int k = 0; k < 3; ++k) {
sums[k].clear();
}
for (int k = 3; k < 4; ++k) {
int py = ny - ady[k];
int px = nx - adx[k];
if (!(px >= 0 && px < W && py >= 0 && py < H))
continue;
sums[k][ny][nx] = add(sums[k][py][px], field[ny][nx]);
}
}
}
return sums;
}
int getans(vector<int> hs) {
hs.emplace_back(0);
stack<pair<int, int>> que;
que.emplace(-1, 0);
int ans = 0;
for (int x = 0; x < hs.size(); ++x) {
if (que.empty()) {
que.push(make_pair(x, hs[x]));
} else {
while (!que.empty()) {
auto p = que.top();
if (p.second < hs[x]) {
que.push(make_pair(x, hs[x]));
break;
} else if (p.second == hs[x]) {
break;
} else {
int area = (x - p.first) * p.second;
ans = max(ans, area);
que.pop();
if (!que.empty()) {
auto np = que.top();
if (np.second < hs[x]) {
que.push(make_pair(p.first, hs[x]));
break;
}
}
}
}
}
}
return ans;
}
int main() {
int H, W;
cin >> H >> W;
vector<vector<int>> field(H + 2, vector<int>(W + 2, 1));
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
cin >> field[i + 1][j + 1];
}
}
auto vs = get_cumulative_sum(field);
int ans = 0;
for (int y = 1; y <= H; ++y) {
vector<int> v;
for (int x = 1; x <= W; ++x) {
v.push_back(vs[3][y][x]);
}
ans = max(ans, getans(v));
}
cout << ans << endl;
return 0;
}
|
replace
| 100 | 101 | 100 | 101 |
-11
| |
p02327
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<double, int> pdbi;
typedef pair<int, pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n); i > 0; i--)
#define rrep2(i, a, b) for (int i = (a); i > b; i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
const ll mod = 1000000000 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1 << 30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
int h, w;
vector<vector<int>> grid(1005, vector<int>(1005));
struct Rectangle {
int height, pos;
};
int largest_hist(int size, vector<int> &hist) {
stack<Rectangle> s;
int maxv = 0;
hist[size] = 0;
for (int i = 0; i <= size; i++) {
Rectangle rect;
rect.height = hist[i];
rect.pos = i;
if (s.empty()) {
s.push(rect);
} else {
if (s.top().height < rect.height)
s.push(rect);
else if (s.top().height > rect.height) {
int target = i;
while (!s.empty() && s.top().height >= rect.height) {
Rectangle pre = s.top();
s.pop();
int area = pre.height * (i - pre.pos);
maxv = max(maxv, area);
target = pre.pos;
}
rect.pos = target;
s.push(rect);
}
}
}
return maxv;
}
int largest_rect(int h, int w, vector<vector<int>> &grid) {
vector<vector<int>> hist(h, vector<int>(w + 1));
for (int j = 0; j < w; j++) {
for (int i = 0; i < h; i++) {
if (grid[i][j] == 1) {
hist[i][j] = 0;
} else {
hist[i][j] = (i > 0) ? hist[i - 1][j] + 1 : 1;
}
}
}
int ret = 0;
for (int i = 0; i < h; i++) {
ret = max(ret, largest_hist(w, hist[i]));
}
return ret;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> h >> w;
rep(i, h) rep(j, w) cin >> grid[i][j];
cout << largest_rect(h, w, grid) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<double, int> pdbi;
typedef pair<int, pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n); i > 0; i--)
#define rrep2(i, a, b) for (int i = (a); i > b; i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
const ll mod = 1000000000 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1 << 30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
int h, w;
vector<vector<int>> grid(2005, vector<int>(2005));
struct Rectangle {
int height, pos;
};
int largest_hist(int size, vector<int> &hist) {
stack<Rectangle> s;
int maxv = 0;
hist[size] = 0;
for (int i = 0; i <= size; i++) {
Rectangle rect;
rect.height = hist[i];
rect.pos = i;
if (s.empty()) {
s.push(rect);
} else {
if (s.top().height < rect.height)
s.push(rect);
else if (s.top().height > rect.height) {
int target = i;
while (!s.empty() && s.top().height >= rect.height) {
Rectangle pre = s.top();
s.pop();
int area = pre.height * (i - pre.pos);
maxv = max(maxv, area);
target = pre.pos;
}
rect.pos = target;
s.push(rect);
}
}
}
return maxv;
}
int largest_rect(int h, int w, vector<vector<int>> &grid) {
vector<vector<int>> hist(h, vector<int>(w + 1));
for (int j = 0; j < w; j++) {
for (int i = 0; i < h; i++) {
if (grid[i][j] == 1) {
hist[i][j] = 0;
} else {
hist[i][j] = (i > 0) ? hist[i - 1][j] + 1 : 1;
}
}
}
int ret = 0;
for (int i = 0; i < h; i++) {
ret = max(ret, largest_hist(w, hist[i]));
}
return ret;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> h >> w;
rep(i, h) rep(j, w) cin >> grid[i][j];
cout << largest_rect(h, w, grid) << endl;
}
|
replace
| 39 | 40 | 39 | 40 |
0
| |
p02327
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, w;
char c;
int mp[1010][1010] = {0};
int ans = 0;
cin >> h >> w;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
scanf(" %c", &c);
if (c == '1')
mp[i][j] = 0;
if (c == '0')
mp[i][j] = mp[i - 1][j] + 1;
}
}
int mx;
int target;
stack<pair<int, int>> st;
for (int i = 1; i <= h; i++) {
mx = 0;
for (int j = 1; j <= w; j++) {
if (mx < mp[i][j]) {
st.push(make_pair(mp[i][j], j));
mx = mp[i][j];
}
else if (mx > mp[i][j]) {
target = j;
while (!st.empty()) {
pair<int, int> f = st.top();
if (f.first < mp[i][j])
break; // ...?
st.pop();
// Debug
/*
cout<<i<<" "<<j<<" "<<f.first<<" "<<f.second<<endl;
cout<<f.first*(j-f.second)<<endl;
*/
ans = max(ans, (f.first * (j - f.second)));
target = f.second;
}
if (mp[i][j] > 0)
st.push(make_pair(mp[i][j], target));
mx = mp[i][j];
}
}
while (!st.empty()) {
pair<int, int> f = st.top();
st.pop();
// Debug
// cout<<i<<" "<<f.second<<endl;
ans = max(ans, (f.first * (w + 1 - f.second)));
// cout<<ans<<endl;
}
}
cout << ans << endl;
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, w;
char c;
int mp[1410][1410] = {0};
int ans = 0;
cin >> h >> w;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
scanf(" %c", &c);
if (c == '1')
mp[i][j] = 0;
if (c == '0')
mp[i][j] = mp[i - 1][j] + 1;
}
}
int mx;
int target;
stack<pair<int, int>> st;
for (int i = 1; i <= h; i++) {
mx = 0;
for (int j = 1; j <= w; j++) {
if (mx < mp[i][j]) {
st.push(make_pair(mp[i][j], j));
mx = mp[i][j];
}
else if (mx > mp[i][j]) {
target = j;
while (!st.empty()) {
pair<int, int> f = st.top();
if (f.first < mp[i][j])
break; // ...?
st.pop();
// Debug
/*
cout<<i<<" "<<j<<" "<<f.first<<" "<<f.second<<endl;
cout<<f.first*(j-f.second)<<endl;
*/
ans = max(ans, (f.first * (j - f.second)));
target = f.second;
}
if (mp[i][j] > 0)
st.push(make_pair(mp[i][j], target));
mx = mp[i][j];
}
}
while (!st.empty()) {
pair<int, int> f = st.top();
st.pop();
// Debug
// cout<<i<<" "<<f.second<<endl;
ans = max(ans, (f.first * (w + 1 - f.second)));
// cout<<ans<<endl;
}
}
cout << ans << endl;
return (0);
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p02327
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
using namespace std;
#define MAX_N 2000
int x[MAX_N][MAX_N];
int H, W;
int main() {
cin >> H >> W;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> x[i][j];
}
if (x[i][0] == 1) {
x[i][0] = 0;
} else {
x[i][0] = 1;
}
for (int j = 1; j < W; j++) {
if (x[i][j] == 1) {
x[i][j] = 0;
} else {
x[i][j] = x[i][j - 1] + 1;
}
}
}
int maxn = 0;
for (int i = 0; i < W; i++) {
for (int j = 0; j < H; j++) {
int X = x[j][i], cnt = 0;
if (x[j][i] == 0)
continue;
for (int k = j; k >= 0; k--) {
cnt++;
X = min(X, x[k][i]);
if (X == 0) {
break;
}
maxn = max(maxn, X * cnt);
}
}
}
cout << maxn << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
#define MAX_N 2000
int x[MAX_N][MAX_N];
int H, W;
int main() {
cin >> H >> W;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> x[i][j];
}
if (x[i][0] == 1) {
x[i][0] = 0;
} else {
x[i][0] = 1;
}
for (int j = 1; j < W; j++) {
if (x[i][j] == 1) {
x[i][j] = 0;
} else {
x[i][j] = x[i][j - 1] + 1;
}
}
}
int maxn = 0;
for (int i = 0; i < W; i++) {
for (int j = 0; j < H; j++) {
int X = x[j][i], cnt = 0;
if (x[j][i] == 0)
continue;
for (int k = j; k >= 0; k--) {
cnt++;
X = min(X, x[k][i]);
if (X * (j + 1) <= maxn) {
break;
}
maxn = max(maxn, X * cnt);
}
}
}
cout << maxn << endl;
return 0;
}
|
replace
| 35 | 36 | 35 | 36 |
TLE
| |
p02328
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define RFORE(i, a, b) for (int i = (b); i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i, v) for (auto i = v.begin(); i != v.end(); ++i)
#define REACH(i, v) for (auto i = v.rbegin(); i != v.rend(); ++i)
#define LB(c, x) distance((c).begin(), lower_bound(ALL(c), x))
#define UB(c, x) distance((c).begin(), upper_bound(ALL(c), x))
#define COUNT(c, x) (lower_bound(ALL(c), x) - upper_bound(ALL(c), x))
#define UNIQUE(c) \
SORT(c); \
(c).erase(unique(ALL(c)), (c).end());
#define COPY(c1, c2) copy(ALL(c1), (c2).begin())
#define EXIST(s, e) (bool)((s).find(e) != (s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define NL cerr << endl;
using namespace std;
template <typename T, typename U> using P = pair<T, U>;
template <typename T> using V = vector<T>;
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> T sum(vector<T> &v) { return accumulate(ALL(v), T()); }
template <typename T> T sum(vector<T> &v, int a, int b) {
return accumulate(v.begin() + a, v.begin() + b, T());
}
template <typename T> T max(vector<T> &v) { return *max_element(ALL(v)); }
template <typename T> T min(vector<T> &v) { return *min_element(ALL(v)); }
template <typename T> T max_index(vector<T> &v) {
return distance((v).begin(), max_element(ALL(v)));
}
template <typename T> T min_index(vector<T> &v) {
return distance((v).begin(), min_element(ALL(v)));
}
struct edge {
int to, cost;
};
template <typename T> auto &operator<<(ostream &s, const vector<T> &v) {
s << "[";
bool a = 1;
for (auto e : v) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "]";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const pair<T, U> &p) {
s << "(" << p.first << "," << p.second << ")";
return s;
}
template <typename T> auto &operator<<(ostream &s, const set<T> &st) {
s << "{";
bool a = 1;
for (auto e : st) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "}";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const map<T, U> &m) {
s << "{";
bool a = 1;
for (auto e : m) {
s << (a ? "" : " ") << e.first << ":" << e.second;
a = 0;
}
s << "}";
return s;
}
const int INF = 1e18;
const int MOD_N = 1e9 + 7;
signed main() {
int N;
cin >> N;
V<int> h(N + 2);
REP(i, N) { cin >> h[i + 1]; }
deque<P<int, int>> deq;
int ans = 0;
REP(i, N + 2) {
while (!deq.empty() && deq.back().first >= h[i]) {
int m = deq.back().first;
deq.pop_back();
int id = deq.back().second;
chmax(ans, m * (i - id - 1));
}
deq.push_back(MP(h[i], i));
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define RFORE(i, a, b) for (int i = (b); i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i, v) for (auto i = v.begin(); i != v.end(); ++i)
#define REACH(i, v) for (auto i = v.rbegin(); i != v.rend(); ++i)
#define LB(c, x) distance((c).begin(), lower_bound(ALL(c), x))
#define UB(c, x) distance((c).begin(), upper_bound(ALL(c), x))
#define COUNT(c, x) (lower_bound(ALL(c), x) - upper_bound(ALL(c), x))
#define UNIQUE(c) \
SORT(c); \
(c).erase(unique(ALL(c)), (c).end());
#define COPY(c1, c2) copy(ALL(c1), (c2).begin())
#define EXIST(s, e) (bool)((s).find(e) != (s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define NL cerr << endl;
using namespace std;
template <typename T, typename U> using P = pair<T, U>;
template <typename T> using V = vector<T>;
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> T sum(vector<T> &v) { return accumulate(ALL(v), T()); }
template <typename T> T sum(vector<T> &v, int a, int b) {
return accumulate(v.begin() + a, v.begin() + b, T());
}
template <typename T> T max(vector<T> &v) { return *max_element(ALL(v)); }
template <typename T> T min(vector<T> &v) { return *min_element(ALL(v)); }
template <typename T> T max_index(vector<T> &v) {
return distance((v).begin(), max_element(ALL(v)));
}
template <typename T> T min_index(vector<T> &v) {
return distance((v).begin(), min_element(ALL(v)));
}
struct edge {
int to, cost;
};
template <typename T> auto &operator<<(ostream &s, const vector<T> &v) {
s << "[";
bool a = 1;
for (auto e : v) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "]";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const pair<T, U> &p) {
s << "(" << p.first << "," << p.second << ")";
return s;
}
template <typename T> auto &operator<<(ostream &s, const set<T> &st) {
s << "{";
bool a = 1;
for (auto e : st) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "}";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const map<T, U> &m) {
s << "{";
bool a = 1;
for (auto e : m) {
s << (a ? "" : " ") << e.first << ":" << e.second;
a = 0;
}
s << "}";
return s;
}
const int INF = 1e18;
const int MOD_N = 1e9 + 7;
signed main() {
int N;
cin >> N;
V<int> h(N + 2);
h[0] = -1;
REP(i, N) cin >> h[i + 1];
h[N + 1] = 0;
deque<P<int, int>> deq;
int ans = 0;
REP(i, N + 2) {
while (!deq.empty() && deq.back().first >= h[i]) {
int m = deq.back().first;
deq.pop_back();
int id = deq.back().second;
chmax(ans, m * (i - id - 1));
}
deq.push_back(MP(h[i], i));
}
cout << ans << endl;
return 0;
}
|
replace
| 106 | 107 | 106 | 110 |
-11
| |
p02329
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define RFORE(i, a, b) for (int i = (b); i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i, v) for (auto i = v.begin(); i != v.end(); ++i)
#define REACH(i, v) for (auto i = v.rbegin(); i != v.rend(); ++i)
#define LB(c, x) distance((c).begin(), lower_bound(ALL(c), x))
#define UB(c, x) distance((c).begin(), upper_bound(ALL(c), x))
#define COUNT(c, x) (upper_bound(ALL(c), x) - lower_bound(ALL(c), x))
#define UNIQUE(c) \
SORT(c); \
(c).erase(unique(ALL(c)), (c).end());
#define COPY(c1, c2) copy(ALL(c1), (c2).begin())
#define EXIST(s, e) (bool)((s).find(e) != (s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define NL cerr << endl;
using namespace std;
template <typename T, typename U> using P = pair<T, U>;
template <typename T> using V = vector<T>;
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> T sum(vector<T> &v) { return accumulate(ALL(v), T()); }
template <typename T> T sum(vector<T> &v, int a, int b) {
return accumulate(v.begin() + a, v.begin() + b, T());
}
template <typename T> T max(vector<T> &v) { return *max_element(ALL(v)); }
template <typename T> T min(vector<T> &v) { return *min_element(ALL(v)); }
template <typename T> T max_index(vector<T> &v) {
return distance((v).begin(), max_element(ALL(v)));
}
template <typename T> T min_index(vector<T> &v) {
return distance((v).begin(), min_element(ALL(v)));
}
struct edge {
int to, cost;
};
template <typename T> auto &operator<<(ostream &s, const vector<T> &v) {
s << "[";
bool a = 1;
for (auto e : v) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "]";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const pair<T, U> &p) {
s << "(" << p.first << "," << p.second << ")";
return s;
}
template <typename T> auto &operator<<(ostream &s, const set<T> &st) {
s << "{";
bool a = 1;
for (auto e : st) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "}";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const map<T, U> &m) {
s << "{";
bool a = 1;
for (auto e : m) {
s << (a ? "" : " ") << e.first << ":" << e.second;
a = 0;
}
s << "}";
return s;
}
const int INF = 1e18;
const int MOD_N = 1e9 + 7;
signed main() {
int n, v;
cin >> n >> v;
V<int> a(n), b(n), c(n), d(n);
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
REP(i, n) cin >> c[i];
REP(i, n) cin >> d[i];
V<int> ab(n * n);
REP(i, n) REP(j, n) { ab[i * n + j] = a[i] + b[j]; }
SORT(ab);
int ans = 0;
REP(i, n) REP(j, n) { ans += COUNT(ab, v - (c[i] + d[j])); }
DUMP(ans)
return 0;
}
|
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define RFORE(i, a, b) for (int i = (b); i >= (a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i, v) for (auto i = v.begin(); i != v.end(); ++i)
#define REACH(i, v) for (auto i = v.rbegin(); i != v.rend(); ++i)
#define LB(c, x) distance((c).begin(), lower_bound(ALL(c), x))
#define UB(c, x) distance((c).begin(), upper_bound(ALL(c), x))
#define COUNT(c, x) (upper_bound(ALL(c), x) - lower_bound(ALL(c), x))
#define UNIQUE(c) \
SORT(c); \
(c).erase(unique(ALL(c)), (c).end());
#define COPY(c1, c2) copy(ALL(c1), (c2).begin())
#define EXIST(s, e) (bool)((s).find(e) != (s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define NL cerr << endl;
using namespace std;
template <typename T, typename U> using P = pair<T, U>;
template <typename T> using V = vector<T>;
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> T sum(vector<T> &v) { return accumulate(ALL(v), T()); }
template <typename T> T sum(vector<T> &v, int a, int b) {
return accumulate(v.begin() + a, v.begin() + b, T());
}
template <typename T> T max(vector<T> &v) { return *max_element(ALL(v)); }
template <typename T> T min(vector<T> &v) { return *min_element(ALL(v)); }
template <typename T> T max_index(vector<T> &v) {
return distance((v).begin(), max_element(ALL(v)));
}
template <typename T> T min_index(vector<T> &v) {
return distance((v).begin(), min_element(ALL(v)));
}
struct edge {
int to, cost;
};
template <typename T> auto &operator<<(ostream &s, const vector<T> &v) {
s << "[";
bool a = 1;
for (auto e : v) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "]";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const pair<T, U> &p) {
s << "(" << p.first << "," << p.second << ")";
return s;
}
template <typename T> auto &operator<<(ostream &s, const set<T> &st) {
s << "{";
bool a = 1;
for (auto e : st) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "}";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const map<T, U> &m) {
s << "{";
bool a = 1;
for (auto e : m) {
s << (a ? "" : " ") << e.first << ":" << e.second;
a = 0;
}
s << "}";
return s;
}
const int INF = 1e18;
const int MOD_N = 1e9 + 7;
signed main() {
int n, v;
cin >> n >> v;
V<int> a(n), b(n), c(n), d(n);
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
REP(i, n) cin >> c[i];
REP(i, n) cin >> d[i];
V<int> ab(n * n);
REP(i, n) REP(j, n) { ab[i * n + j] = a[i] + b[j]; }
SORT(ab);
int ans = 0;
REP(i, n) REP(j, n) { ans += COUNT(ab, v - (c[i] + d[j])); }
cout << ans << endl;
return 0;
}
|
replace
| 117 | 118 | 117 | 118 |
0
|
ans = 9
|
p02330
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int N, K;
ll L, R;
ll a[41];
ll bitsum(int b, int offset) {
ll s = 0;
for (int i = 1; b > 0; b >>= 1, i += 1) {
if (b & 1) {
s += a[offset + i];
}
}
return s;
}
ll solve() {
int M = N / 2;
vector<vector<ll>> h(M + 1);
for (int i = 0; i < (1 << M); ++i) {
int bc = __builtin_popcount(i);
h[bc].push_back(bitsum(i, 0));
}
for (int i = 1; i <= M; ++i) {
sort(h[i].begin(), h[i].end());
}
ll ans = 0;
for (int i = 0; i < (1 << (N - M)); ++i) {
ll s = bitsum(i, M);
int bc = __builtin_popcount(i);
if (bc > K) {
continue;
}
ans += upper_bound(h[K - bc].begin(), h[K - bc].end(), R - s) -
lower_bound(h[K - bc].begin(), h[K - bc].end(), L - s);
}
return ans;
}
int main() {
cin >> N >> K >> L >> R;
for (int i = 0; i < N; ++i) {
cin >> a[i + 1];
}
cout << solve() << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int N, K;
ll L, R;
ll a[41];
ll bitsum(int b, int offset) {
ll s = 0;
for (int i = 1; b > 0; b >>= 1, i += 1) {
if (b & 1) {
s += a[offset + i];
}
}
return s;
}
ll solve() {
int M = N / 2;
vector<vector<ll>> h(M + 1);
for (int i = 0; i < (1 << M); ++i) {
int bc = __builtin_popcount(i);
h[bc].push_back(bitsum(i, 0));
}
for (int i = 1; i <= M; ++i) {
sort(h[i].begin(), h[i].end());
}
ll ans = 0;
for (int i = 0; i < (1 << (N - M)); ++i) {
ll s = bitsum(i, M);
int bc = __builtin_popcount(i);
if (K < bc || K - bc > M) {
continue;
}
ans += upper_bound(h[K - bc].begin(), h[K - bc].end(), R - s) -
lower_bound(h[K - bc].begin(), h[K - bc].end(), L - s);
}
return ans;
}
int main() {
cin >> N >> K >> L >> R;
for (int i = 0; i < N; ++i) {
cin >> a[i + 1];
}
cout << solve() << endl;
return 0;
}
|
replace
| 36 | 37 | 36 | 37 |
-11
| |
p02335
|
C++
|
Runtime Error
|
#include <iostream>
#include <stack>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7; // 1e9+9
ll add(ll x, ll y) { return (x + y) % mod; }
ll mul(ll x, ll y) { return (x * y) % mod; }
ll mpow(ll x, ll y) {
ll v = 1;
for (; y; x = mul(x, x), y >>= 1)
if (y & 1)
v = mul(v, x);
return v;
}
ll ncr[5000][5000];
ll nCr(ll n, ll r) {
if (n == r)
return 1;
if (r == 0)
return 1;
if (ncr[n][r])
return ncr[n][r];
ncr[n][r] = (nCr(n - 1, r - 1) + nCr(n - 1, r)) % mod;
return ncr[n][r];
}
ll nHr(ll n, ll r) { return nCr(n + r - 1, n); }
int main() {
ll n, k;
cin >> n >> k;
cout << nCr(k, n) << endl;
return 0;
}
|
#include <iostream>
#include <stack>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7; // 1e9+9
ll add(ll x, ll y) { return (x + y) % mod; }
ll mul(ll x, ll y) { return (x * y) % mod; }
ll mpow(ll x, ll y) {
ll v = 1;
for (; y; x = mul(x, x), y >>= 1)
if (y & 1)
v = mul(v, x);
return v;
}
ll ncr[5000][5000];
ll nCr(ll n, ll r) {
if (n < r)
return 0;
if (n == r)
return 1;
if (r == 0)
return 1;
if (ncr[n][r])
return ncr[n][r];
ncr[n][r] = (nCr(n - 1, r - 1) + nCr(n - 1, r)) % mod;
return ncr[n][r];
}
ll nHr(ll n, ll r) { return nCr(n + r - 1, n); }
int main() {
ll n, k;
cin >> n >> k;
cout << nCr(k, n) << endl;
return 0;
}
|
insert
| 21 | 21 | 21 | 23 |
-11
| |
p02336
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <utility>
#include <vector>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
const ll E = 1e18 + 7;
#define F first
#define S second
#define MK make_pair
const ll MOD = 1000000007;
vector<vector<ll>> c;
void mk_c() {
c.resize(3100);
for (int i = 1; i < 2100; i++) {
c[i].resize(3100);
c[i][0] = 1;
c[i][i] = 1;
for (int t = 1; t < i; t++) {
c[i][t] = (c[i - 1][t - 1] + c[i - 1][t]) % MOD;
}
}
}
int main() {
ll n, k;
cin >> n >> k;
n -= k;
if (n < 0) {
cout << 0 << endl;
return 0;
}
mk_c();
cout << c[n + k - 1][k - 1] << endl;
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <utility>
#include <vector>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pi;
const ll E = 1e18 + 7;
#define F first
#define S second
#define MK make_pair
const ll MOD = 1000000007;
vector<vector<ll>> c;
void mk_c() {
c.resize(3100);
for (int i = 1; i < 2100; i++) {
c[i].resize(3100);
c[i][0] = 1;
c[i][i] = 1;
for (int t = 1; t < i; t++) {
c[i][t] = (c[i - 1][t - 1] + c[i - 1][t]) % MOD;
}
}
}
int main() {
ll n, k;
cin >> n >> k;
n -= k;
if (n < 0) {
cout << 0 << endl;
return 0;
}
if (n == 0) {
cout << 1 << endl;
return 0;
}
mk_c();
cout << c[n + k - 1][k - 1] << endl;
return 0;
}
|
insert
| 52 | 52 | 52 | 56 |
0
| |
p02343
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#ifndef LOCAL_
#define fprintf \
if (false) \
fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) \
fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) \
fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, \
#x2, x1, x2);
#define dumplll(x1, x2, x3) \
fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, \
__LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) \
fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) \
fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, \
#x2, x1, x2);
#define loop for (;;)
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;
template <typename T> void scan1(T &x) { fprintf(stderr, "unknown type\n"); }
template <> void scan1(Int &x) {
if (scanf("%" PRId64, &x) < 0)
exit(0);
}
template <> void scan1(std::string &x) {
if (not(std::cin >> x))
exit(0);
}
template <> void scan1(LI &xs) {
for (Int &x : xs)
scan1(x);
}
void scan() {}
template <typename Head, typename... Tail> void scan(Head &x, Tail &...xs) {
scan1(x);
scan(xs...);
}
struct Solver1 {
Int n;
std::vector<Int> ps, ns;
Solver1(Int n_) : n(n_ + 1), ps(n, -1), ns(n, 1) {}
void unite(Int x, Int y) {
Int x2 = find(x);
Int y2 = find(y);
if (not(ns[x2] <= ns[y2]))
std::swap(x2, y2);
ps[x2] = y2;
ns[y2] += ns[x2];
}
bool same(Int x, Int y) { return find(x) == find(y); }
Int find(Int x) { return ps[x] == -1 ? x : (ps[x] = find(ps[x])); }
Int getSize(Int x) { return ns[find(x)]; }
};
struct Solver {
Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
void solve() {
Int n, q;
scan(n, q);
Solver1 uf(n);
for (Int i = 0; i < q; ++i) {
Int a, b, c;
scan(a, b, c);
if (a == 0) {
uf.unite(b, c);
}
if (a == 1) {
puts(uf.same(b, c) ? "1" : "0");
}
}
}
};
int main() { loop std::unique_ptr<Solver>(new Solver())->solve(); }
|
#include <bits/stdc++.h>
#ifndef LOCAL_
#define fprintf \
if (false) \
fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) \
fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) \
fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, \
#x2, x1, x2);
#define dumplll(x1, x2, x3) \
fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, \
__LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) \
fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) \
fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, \
#x2, x1, x2);
#define loop for (;;)
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;
template <typename T> void scan1(T &x) { fprintf(stderr, "unknown type\n"); }
template <> void scan1(Int &x) {
if (scanf("%" PRId64, &x) < 0)
exit(0);
}
template <> void scan1(std::string &x) {
if (not(std::cin >> x))
exit(0);
}
template <> void scan1(LI &xs) {
for (Int &x : xs)
scan1(x);
}
void scan() {}
template <typename Head, typename... Tail> void scan(Head &x, Tail &...xs) {
scan1(x);
scan(xs...);
}
struct Solver1 {
Int n;
std::vector<Int> ps, ns;
Solver1(Int n_) : n(n_ + 1), ps(n, -1), ns(n, 1) {}
void unite(Int x, Int y) {
Int x2 = find(x);
Int y2 = find(y);
if (x2 == y2)
return;
if (not(ns[x2] <= ns[y2]))
std::swap(x2, y2);
ps[x2] = y2;
ns[y2] += ns[x2];
}
bool same(Int x, Int y) { return find(x) == find(y); }
Int find(Int x) { return ps[x] == -1 ? x : (ps[x] = find(ps[x])); }
Int getSize(Int x) { return ns[find(x)]; }
};
struct Solver {
Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
void solve() {
Int n, q;
scan(n, q);
Solver1 uf(n);
for (Int i = 0; i < q; ++i) {
Int a, b, c;
scan(a, b, c);
if (a == 0) {
uf.unite(b, c);
}
if (a == 1) {
puts(uf.same(b, c) ? "1" : "0");
}
}
}
};
int main() { loop std::unique_ptr<Solver>(new Solver())->solve(); }
|
insert
| 53 | 53 | 53 | 55 |
0
| |
p02343
|
C++
|
Runtime Error
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
using namespace std;
const int num = 5000;
vector<int> v[num];
int cnt = -1;
inline void merge(int a, int b) {
int m = -1, n = -1;
for (int i = 0; i <= cnt; i++) {
for (int j = 0; j < v[i].size(); j++) {
if (m != -1 && n != -1)
break;
if (v[i][j] == a)
m = i;
if (v[i][j] == b)
n = i;
}
if (m != -1 && n != -1)
break;
}
if (m != -1 && n != -1 && m != n) {
int x = v[n].size();
for (int i = 0; i < x; i++) {
v[m].push_back(v[n][i]);
v[n].erase(v[n].begin() + i);
}
} else if (m != -1 && n != -1 && m == n)
return;
else if (m != -1 && n == -1)
v[m].push_back(b);
else if (m == -1 && n != -1)
v[n].push_back(a);
else {
cnt++;
v[cnt].push_back(a);
v[cnt].push_back(b);
}
}
inline void same(int a, int b) {
int m = -1, n = -1;
for (int i = 0; i <= cnt; i++) {
for (int j = 0; j < v[i].size(); j++) {
if (m != -1 && n != -1)
break;
if (v[i][j] == a)
m = i;
if (v[i][j] == b)
n = i;
if (m != -1 && n != -1)
break;
}
}
if (m != -1 && n != -1 && m == n)
cout << '1' << endl;
else
cout << '0' << endl;
}
int main() {
int n, q, com, fi, se;
cin >> n >> q;
for (int i = 0; i < q; i++) {
cin >> com >> fi >> se;
if (com == 0)
merge(fi, se);
else
same(fi, se);
}
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
using namespace std;
const int num = 5000;
vector<int> v[num];
int cnt = -1;
inline void merge(int a, int b) {
int m = -1, n = -1;
for (int i = 0; i <= cnt; i++) {
for (int j = 0; j < v[i].size(); j++) {
if (m != -1 && n != -1)
break;
if (v[i][j] == a)
m = i;
if (v[i][j] == b)
n = i;
}
if (m != -1 && n != -1)
break;
}
if (m != -1 && n != -1 && m != n) {
int x = v[n].size();
for (int i = 0; i < x; i++) {
v[m].push_back(v[n][0]);
v[n].erase(v[n].begin());
}
} else if (m != -1 && n != -1 && m == n)
return;
else if (m != -1 && n == -1)
v[m].push_back(b);
else if (m == -1 && n != -1)
v[n].push_back(a);
else {
cnt++;
v[cnt].push_back(a);
v[cnt].push_back(b);
}
}
inline void same(int a, int b) {
int m = -1, n = -1;
for (int i = 0; i <= cnt; i++) {
for (int j = 0; j < v[i].size(); j++) {
if (m != -1 && n != -1)
break;
if (v[i][j] == a)
m = i;
if (v[i][j] == b)
n = i;
if (m != -1 && n != -1)
break;
}
}
if (m != -1 && n != -1 && m == n)
cout << '1' << endl;
else
cout << '0' << endl;
}
int main() {
int n, q, com, fi, se;
cin >> n >> q;
for (int i = 0; i < q; i++) {
cin >> com >> fi >> se;
if (com == 0)
merge(fi, se);
else
same(fi, se);
}
return 0;
}
|
replace
| 25 | 27 | 25 | 27 |
-6
|
double free or corruption (out)
|
p02343
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <vector>
using namespace std;
struct edge {
int dest;
int weight; // = dest minus curr
};
class UF {
public:
vector<edge> v;
UF(int n) { v = vector<edge>(n, {-1, 0}); }
void unite(int x, int y, int y_minus_x) {
int loc_x = find(x);
int loc_y = find(y);
if (v[loc_x].dest <
v[loc_y].dest) { // x's set has more elements -- join y to x
v[loc_x].dest += v[loc_y].dest;
v[loc_y] = {loc_x, -y_minus_x};
} else {
v[loc_y].dest += v[loc_x].dest;
v[loc_x] = {loc_y, y_minus_x};
}
}
void unite(int x, int y) { unite(x, y, 0); }
// if weighted = true, returns the difference of the root and the current node
// if weighted = false, returns the id of the root
int find(int x, bool weighted = false) {
int tmp = 0;
while (v[x].dest >= 0) {
tmp += v[x].weight;
x = v[x].dest;
}
return (weighted ? tmp : x);
}
// pre: x and y are in the same set
// post: returns y - x
int get_difference(int x, int y) {
int root_minus_x = find(x, true);
int root_minus_y = find(y, true);
return root_minus_x - root_minus_y;
}
};
int main() {
int n, q;
cin >> n >> q;
UF uf(n);
int c, x, y;
while (cin >> c >> x >> y) {
if (c == 0)
uf.unite(x, y);
if (c == 1)
cout << (uf.find(x) == uf.find(y)) << endl;
}
}
|
#include <iostream>
#include <vector>
using namespace std;
struct edge {
int dest;
int weight; // = dest minus curr
};
class UF {
public:
vector<edge> v;
UF(int n) { v = vector<edge>(n, {-1, 0}); }
void unite(int x, int y, int y_minus_x) {
int loc_x = find(x);
int loc_y = find(y);
if (loc_x == loc_y)
return;
if (v[loc_x].dest <
v[loc_y].dest) { // x's set has more elements -- join y to x
v[loc_x].dest += v[loc_y].dest;
v[loc_y] = {loc_x, -y_minus_x};
} else {
v[loc_y].dest += v[loc_x].dest;
v[loc_x] = {loc_y, y_minus_x};
}
}
void unite(int x, int y) { unite(x, y, 0); }
// if weighted = true, returns the difference of the root and the current node
// if weighted = false, returns the id of the root
int find(int x, bool weighted = false) {
int tmp = 0;
while (v[x].dest >= 0) {
tmp += v[x].weight;
x = v[x].dest;
}
return (weighted ? tmp : x);
}
// pre: x and y are in the same set
// post: returns y - x
int get_difference(int x, int y) {
int root_minus_x = find(x, true);
int root_minus_y = find(y, true);
return root_minus_x - root_minus_y;
}
};
int main() {
int n, q;
cin >> n >> q;
UF uf(n);
int c, x, y;
while (cin >> c >> x >> y) {
if (c == 0)
uf.unite(x, y);
if (c == 1)
cout << (uf.find(x) == uf.find(y)) << endl;
}
}
|
insert
| 17 | 17 | 17 | 19 |
TLE
| |
p02343
|
C++
|
Runtime Error
|
// Created by Vignesh Manoharan
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
const int INF = 1000000000;
const ll LINF = 1e17;
const double PI = 3.141592653589793238;
#pragma unused(INF, PI, LINF)
#define F(i, a, n) for (int i = (a); i < (n); i++)
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
return s << "(" << t.first << "," << t.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, vector<T> t) {
for (int i = 0; i < (t).size(); i++)
s << t[i] << ((i < (t).size() - 1) ? " " : "");
return s;
}
template <typename T> ostream &operator<<(ostream &s, set<T> t) {
for (T x : t)
s << x << " ";
return s;
}
template <typename T> istream &operator>>(istream &s, vector<T> &t) {
for (int _i = 0; _i < t.size(); _i++)
s >> t[_i];
return s;
}
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
const int MAXN = 1000;
int parent[MAXN];
int root(int v) { return parent[v] < 0 ? v : (parent[v] = root(parent[v])); }
void merge(int x, int y) { // x and y are some vertices
if ((x = root(x)) == (y = root(y)))
return;
if (parent[y] < parent[x]) // balancing the height of the tree
swap(x, y);
parent[x] += parent[y];
parent[y] = x;
}
int main(int argc, const char *argv[]) {
#ifdef local_test
// input
// freopen("input","w",stdout);
// cout<<"1 \n 100 10 \n";
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
int n, q;
cin >> n >> q;
F(i, 0, n) parent[i] = -1;
F(i, 0, q) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
merge(x, y);
} else {
cout << (root(x) == root(y)) << "\n";
}
}
}
|
// Created by Vignesh Manoharan
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
const int INF = 1000000000;
const ll LINF = 1e17;
const double PI = 3.141592653589793238;
#pragma unused(INF, PI, LINF)
#define F(i, a, n) for (int i = (a); i < (n); i++)
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
return s << "(" << t.first << "," << t.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, vector<T> t) {
for (int i = 0; i < (t).size(); i++)
s << t[i] << ((i < (t).size() - 1) ? " " : "");
return s;
}
template <typename T> ostream &operator<<(ostream &s, set<T> t) {
for (T x : t)
s << x << " ";
return s;
}
template <typename T> istream &operator>>(istream &s, vector<T> &t) {
for (int _i = 0; _i < t.size(); _i++)
s >> t[_i];
return s;
}
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
const int MAXN = 10010;
int parent[MAXN];
int root(int v) { return parent[v] < 0 ? v : (parent[v] = root(parent[v])); }
void merge(int x, int y) { // x and y are some vertices
if ((x = root(x)) == (y = root(y)))
return;
if (parent[y] < parent[x]) // balancing the height of the tree
swap(x, y);
parent[x] += parent[y];
parent[y] = x;
}
int main(int argc, const char *argv[]) {
#ifdef local_test
// input
// freopen("input","w",stdout);
// cout<<"1 \n 100 10 \n";
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
int n, q;
cin >> n >> q;
F(i, 0, n) parent[i] = -1;
F(i, 0, q) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
merge(x, y);
} else {
cout << (root(x) == root(y)) << "\n";
}
}
}
|
replace
| 51 | 52 | 51 | 52 |
0
| |
p02343
|
C++
|
Runtime Error
|
#include <cstdio>
#include <vector>
typedef struct node {
int number;
node *parent;
} node;
node *root;
node *find(node *x) {
if (x->parent == root)
return x;
else {
x->parent = find(x->parent);
return x->parent;
}
}
int main(void) {
int n, q;
scanf("%d %d", &n, &q);
std::vector<node> nodes(n);
for (int i = 0; i < n; i++) {
nodes[i].number = i;
nodes[i].parent = root;
}
for (int i = 0; i < q; i++) {
int op, x, y;
node *x_parent, *y_parent;
scanf("%d %d %d", &op, &x, &y);
x_parent = find(&nodes[x]);
y_parent = find(&nodes[y]);
if (op == 0) {
if (x_parent->number > y_parent->number)
x_parent->parent = y_parent;
else
y_parent->parent = x_parent;
} else {
if (x_parent->number == y_parent->number)
printf("1\n");
else
printf("0\n");
}
}
return 0;
}
|
#include <cstdio>
#include <vector>
typedef struct node {
int number;
node *parent;
} node;
node *root;
node *find(node *x) {
if (x->parent == root)
return x;
else {
x->parent = find(x->parent);
return x->parent;
}
}
int main(void) {
int n, q;
scanf("%d %d", &n, &q);
std::vector<node> nodes(n);
for (int i = 0; i < n; i++) {
nodes[i].number = i;
nodes[i].parent = root;
}
for (int i = 0; i < q; i++) {
int op, x, y;
node *x_parent, *y_parent;
scanf("%d %d %d", &op, &x, &y);
x_parent = find(&nodes[x]);
y_parent = find(&nodes[y]);
if (op == 0) {
if (x_parent->number > y_parent->number)
x_parent->parent = y_parent;
else if (x_parent->number < y_parent->number)
y_parent->parent = x_parent;
} else {
if (x_parent->number == y_parent->number)
printf("1\n");
else
printf("0\n");
}
}
return 0;
}
|
replace
| 37 | 38 | 37 | 38 |
0
| |
p02343
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <vector>
using namespace std;
struct UF {
vector<int> a;
vector<int> size;
UF(int n) {
a.assign(n, 0);
size.assign(n, 1);
for (int i = 0; i < n; i++) {
a[i] = i;
}
}
int root(int u) {
int parent = u;
while (a[parent] != parent) {
parent = a[u];
}
return parent;
}
bool same(int u, int v) { return root(u) == root(v); }
void unite(int u, int v) {
int i = root(u);
int j = root(v);
if (i != j) {
if (size[i] > size[j]) {
a[j] = i;
size[i] += size[j];
} else {
a[i] = j;
size[j] += size[i];
}
}
}
};
int main() {
int n, q;
cin >> n >> q;
UF uf = UF(n + 1);
for (int i = 0; i < q; i++) {
int cmd, u, v;
cin >> cmd >> u >> v;
if (cmd == 0) {
uf.unite(u, v);
} else {
cout << (uf.same(u, v) ? 1 : 0) << endl;
}
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
struct UF {
vector<int> a;
vector<int> size;
UF(int n) {
a.assign(n, 0);
size.assign(n, 1);
for (int i = 0; i < n; i++) {
a[i] = i;
}
}
int root(int u) {
int parent = u;
while (a[parent] != parent) {
parent = a[parent];
}
return parent;
}
bool same(int u, int v) { return root(u) == root(v); }
void unite(int u, int v) {
int i = root(u);
int j = root(v);
if (i != j) {
if (size[i] > size[j]) {
a[j] = i;
size[i] += size[j];
} else {
a[i] = j;
size[j] += size[i];
}
}
}
};
int main() {
int n, q;
cin >> n >> q;
UF uf = UF(n + 1);
for (int i = 0; i < q; i++) {
int cmd, u, v;
cin >> cmd >> u >> v;
if (cmd == 0) {
uf.unite(u, v);
} else {
cout << (uf.same(u, v) ? 1 : 0) << endl;
}
}
return 0;
}
|
replace
| 20 | 21 | 20 | 21 |
TLE
| |
p02343
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct union_find_tree {
vector<ll> par;
union_find_tree(ll n) {
par.resize(n);
for (ll i = 0; i < n; i++) {
par[i] = i;
}
}
ll find(ll a) {
if (par[a] == a)
return a;
return par[a] = find(par[a]);
}
void unite(ll a, ll b) { par[find(a)] = b; }
bool same(ll a, ll b) { return find(a) == find(b); }
};
int main() {
ll n, q;
cin >> n >> q;
union_find_tree uni(n);
for (ll i = 0; i < q; i++) {
ll c, x, y;
cin >> c >> x >> y;
if (c == 0) {
uni.unite(x, y);
} else {
if (uni.same(x, y)) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
}
}
}
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct union_find_tree {
vector<ll> par;
union_find_tree(ll n) {
par.resize(n);
for (ll i = 0; i < n; i++) {
par[i] = i;
}
}
ll find(ll a) {
if (par[a] == a)
return a;
return par[a] = find(par[a]);
}
void unite(ll a, ll b) { par[find(a)] = find(b); }
bool same(ll a, ll b) { return find(a) == find(b); }
};
int main() {
ll n, q;
cin >> n >> q;
union_find_tree uni(n);
for (ll i = 0; i < q; i++) {
ll c, x, y;
cin >> c >> x >> y;
if (c == 0) {
uni.unite(x, y);
} else {
if (uni.same(x, y)) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
}
}
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p02343
|
C++
|
Runtime Error
|
#include <algorithm>
#include <array>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <map>
#include <math.h>
#define SENTINEL 1000000001
#define min(a, b) (a) > (b) ? (b) : (a)
#define max(a, b) (a) > (b) ? (a) : (b)
using namespace std;
typedef pair<int, int> pii;
using namespace std;
struct UnionFind {
vector<int> parent;
vector<int> rank;
UnionFind(int n) : parent(n), rank(n, 0) {
for (int i = 0; i < n; i++) {
parent[i] = i;
}
}
int find(int x) {
if (x == parent[x])
return x;
else
return parent[x] = find(parent[x]);
}
bool same(int x, int y) { return find(x) == find(y); }
void unite(int x, int y) {
int a = parent[x];
int b = parent[y];
if (a == b) {
return;
}
if (rank[a] < rank[b]) {
parent[a] = b;
} else {
parent[b] = a;
if (rank[a] == rank[b])
rank[b]++;
}
}
};
int main() {
int n, q;
cin >> n >> q;
UnionFind uf(n);
for (int i = 0; i < q; i++) {
int c, x, y;
cin >> c >> x >> y;
switch (c) {
case 0:
uf.unite(x, y);
break;
case 1:
cout << (uf.same(x, y) ? 1 : 0) << endl;
break;
}
}
return 0;
}
|
#include <algorithm>
#include <array>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <map>
#include <math.h>
#define SENTINEL 1000000001
#define min(a, b) (a) > (b) ? (b) : (a)
#define max(a, b) (a) > (b) ? (a) : (b)
using namespace std;
typedef pair<int, int> pii;
using namespace std;
struct UnionFind {
vector<int> parent;
vector<int> rank;
UnionFind(int n) : parent(n), rank(n, 0) {
for (int i = 0; i < n; i++) {
parent[i] = i;
}
}
int find(int x) {
if (x == parent[x])
return x;
else
return parent[x] = find(parent[x]);
}
bool same(int x, int y) { return find(x) == find(y); }
void unite(int x, int y) {
int a = find(x);
int b = find(y);
if (a == b) {
return;
}
if (rank[a] < rank[b]) {
parent[a] = b;
} else {
parent[b] = a;
if (rank[a] == rank[b])
rank[b]++;
}
}
};
int main() {
int n, q;
cin >> n >> q;
UnionFind uf(n);
for (int i = 0; i < q; i++) {
int c, x, y;
cin >> c >> x >> y;
switch (c) {
case 0:
uf.unite(x, y);
break;
case 1:
cout << (uf.same(x, y) ? 1 : 0) << endl;
break;
}
}
return 0;
}
|
replace
| 49 | 51 | 49 | 51 |
0
| |
p02343
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#define Loop1(i, n) for (int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for (int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
void fastios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
static const int N = 10005;
vi p(N, -1);
vi d(N, 1);
void unite(int x, int y) {
while (p[x] != -1) {
x = p[x];
}
while (p[y] != -1) {
y = p[y];
}
if (d[x] > d[y])
p[y] = x;
else if (d[x] < d[y])
p[x] = y;
else {
p[y] = x;
d[x]++;
}
}
bool same(int x, int y) {
while (p[x] != -1) {
x = p[x];
}
while (p[y] != -1) {
y = p[y];
}
if (x == y)
return 1;
else
return 0;
}
int main() {
fastios();
int n, q;
cin >> n >> q;
Loop(i, q) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0)
unite(x, y);
else
cout << same(x, y) << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#define Loop1(i, n) for (int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for (int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
void fastios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
static const int N = 10005;
vi p(N, -1);
vi d(N, 1);
void unite(int x, int y) {
while (p[x] != -1) {
x = p[x];
}
while (p[y] != -1) {
y = p[y];
}
if (x == y)
return;
if (d[x] > d[y])
p[y] = x;
else if (d[x] < d[y])
p[x] = y;
else {
p[y] = x;
d[x]++;
}
}
bool same(int x, int y) {
while (p[x] != -1) {
x = p[x];
}
while (p[y] != -1) {
y = p[y];
}
if (x == y)
return 1;
else
return 0;
}
int main() {
fastios();
int n, q;
cin >> n >> q;
Loop(i, q) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0)
unite(x, y);
else
cout << same(x, y) << endl;
}
return 0;
}
|
insert
| 42 | 42 | 42 | 44 |
TLE
| |
p02343
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T, vector<T>, greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU \
std::ios::sync_with_stdio(false); \
std::cin.tie(0);
struct UnionFind {
// number of parents(par[i] = i => root)
vector<int> par;
// rank of tree
vector<int> rank;
UnionFind(int n) : par(n), rank(n, 1) {
// initialize
rep(n, i) par[i] = i;
}
// find root (keiroasshuku at the same time)
int root(int x) {
if (par[x] == x)
return x;
else
return par[x] = root(par[x]);
}
// unite
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (rank[x] > rank[y])
swap(x, y);
par[x] = y;
if (rank[x] == rank[y])
rank[y]++;
}
// same tree?
bool same(int x, int y) { return root(x) == root(y); }
};
void solve(void) {
int N, Q;
cin >> N >> Q;
UnionFind uf(N);
while (Q--) {
int c, x, y;
cin >> c >> x >> y;
x--, y--;
if (c)
cout << uf.same(x, y) << endl;
else
uf.unite(x, y);
}
}
int main(void) {
solve();
// cout << "yui(*-v・)yui" << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T, vector<T>, greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU \
std::ios::sync_with_stdio(false); \
std::cin.tie(0);
struct UnionFind {
// number of parents(par[i] = i => root)
vector<int> par;
// rank of tree
vector<int> rank;
UnionFind(int n) : par(n), rank(n, 1) {
// initialize
rep(n, i) par[i] = i;
}
// find root (keiroasshuku at the same time)
int root(int x) {
if (par[x] == x)
return x;
else
return par[x] = root(par[x]);
}
// unite
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (rank[x] > rank[y])
swap(x, y);
par[x] = y;
if (rank[x] == rank[y])
rank[y]++;
}
// same tree?
bool same(int x, int y) { return root(x) == root(y); }
};
void solve(void) {
int N, Q;
cin >> N >> Q;
UnionFind uf(N);
while (Q--) {
int c, x, y;
cin >> c >> x >> y;
if (c)
cout << uf.same(x, y) << endl;
else
uf.unite(x, y);
}
}
int main(void) {
solve();
// cout << "yui(*-v・)yui" << endl;
return 0;
}
|
delete
| 75 | 76 | 75 | 75 |
-6
|
double free or corruption (out)
|
p02343
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define each(a, b) for (auto(a) : (b))
#define all(v) (v).begin(), (v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define cmx(x, y) x = max(x, y)
#define cmn(x, y) x = min(x, y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout << #x << " = " << (x) << endl
#define spair(p) cout << #p << ": " << p.fi << " " << p.se << endl
#define svec(v) \
cout << #v << ":"; \
rep(kbrni, v.size()) cout << " " << v[kbrni]; \
cout << endl
#define sset(s) \
cout << #s << ":"; \
each(kbrni, s) cout << " " << kbrni; \
cout << endl
#define smap(m) \
cout << #m << ":"; \
each(kbrni, m) cout << " {" << kbrni.first << ":" << kbrni.second << "}"; \
cout << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;
const int MAX_N = 100005;
//???????????????????????????????????¨??¨????????¨?????????????????????????????????
//??????splay??¨??????????????¨???????????????????????????????????????
struct node {
node *left;
node *right;
node *par;
bool rev;
int val, size;
node(int t)
: left(nullptr), right(nullptr), par(nullptr), rev(false), val(t),
size(1) {}
//?????????????????????????????????
bool isRoot() { return (!par) || (par->left != this && par->right != this); }
//????????¬?????¨????????¢?????????
void push() {
if (rev) {
rev = false;
swap(left, right);
if (left) {
left->rev = !(left->rev);
}
if (right) {
right->rev = !(right->rev);
}
}
}
};
class LinkCutTree {
private:
int getSize(node *u) { return u ? u->size : 0; }
void updateSize(node *u) {
u->size = 1 + getSize(u->left) + getSize(u->right);
}
// ch??¨p???????????¢????????????(lch:?????????????????????)
void connect(node *ch, node *p, bool lch) {
if (ch) {
ch->par = p;
}
if (lch) {
p->left = ch;
} else {
p->right = ch;
}
}
// zig, zig-zag, zig-zig ???????¨????????????¢?????¨???
void rotate(node *u) {
node *p = u->par;
node *gp = p->par;
bool isRootP = p->isRoot();
bool lch = (u == p->left);
connect(lch ? (u->right) : (u->left), p, lch);
connect(p, u, !lch);
updateSize(p);
updateSize(u);
if (isRootP) {
// zig-step
u->par = gp;
} else {
// zig-zag or zig-zig step
connect(u, gp, (p == gp->left));
updateSize(u);
}
}
// u???????????¬?????¨???????????????
void splay(node *u) {
while (!(u->isRoot())) {
node *p = u->par;
node *gp = p->par;
if (!(p->isRoot())) {
gp->push();
}
p->push();
u->push();
if (!(p->isRoot())) {
// zig-zig, zig-zag
rotate((u == p->left) == (p == gp->left) ? p : u);
}
rotate(u);
}
u->push();
}
node *expose(node *u) {
node *last = nullptr;
for (node *v = u; v; v = v->par) {
splay(v);
v->left = last;
updateSize(v);
last = v;
}
splay(u);
return last;
}
//??????u?????¨????????¨???????????????(????????¬?????¨)???????????????
void evert(node *u) {
expose(u);
u->rev = !(u->rev);
}
public:
node **arr;
LinkCutTree() {}
void build(int node_size) {
arr = new node *[node_size];
for (int i = 0; i < node_size; i++) {
arr[i] = new node(i);
}
}
int TreeSize(node *u) {
evert(u);
return getSize(u);
}
int TreeSize(int unum) { return TreeSize(arr[unum]); }
node *findRoot(node *u) {
expose(u);
while (u->right) {
u = u->right;
}
splay(u);
return u;
}
node *findRoot(int unum) { return findRoot(arr[unum]); }
bool connected(node *u, node *v) {
if (u == v) {
return true;
}
expose(u);
expose(v);
return u->par;
}
bool connected(int unum, int vnum) { return connected(arr[unum], arr[vnum]); }
void link(node *u, node *v) {
evert(u);
u->par = v;
}
void link(int unum, int vnum) { link(arr[unum], arr[vnum]); }
void cut(node *u, node *v) {
evert(u);
expose(v);
v->right->par = nullptr;
v->right = nullptr;
}
void cut(int unum, int vnum) { cut(arr[unum], arr[vnum]); }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
LinkCutTree lt;
int n, m;
cin >> n >> m;
lt.build(n);
rep(i, m) {
int u, v, w;
cin >> u >> v >> w;
if (u) {
cout << lt.connected(v, w) << "\n";
} else {
lt.link(v, w);
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define each(a, b) for (auto(a) : (b))
#define all(v) (v).begin(), (v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define cmx(x, y) x = max(x, y)
#define cmn(x, y) x = min(x, y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout << #x << " = " << (x) << endl
#define spair(p) cout << #p << ": " << p.fi << " " << p.se << endl
#define svec(v) \
cout << #v << ":"; \
rep(kbrni, v.size()) cout << " " << v[kbrni]; \
cout << endl
#define sset(s) \
cout << #s << ":"; \
each(kbrni, s) cout << " " << kbrni; \
cout << endl
#define smap(m) \
cout << #m << ":"; \
each(kbrni, m) cout << " {" << kbrni.first << ":" << kbrni.second << "}"; \
cout << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;
const int MAX_N = 100005;
//???????????????????????????????????¨??¨????????¨?????????????????????????????????
//??????splay??¨??????????????¨???????????????????????????????????????
struct node {
node *left;
node *right;
node *par;
bool rev;
int val, size;
node(int t)
: left(nullptr), right(nullptr), par(nullptr), rev(false), val(t),
size(1) {}
//?????????????????????????????????
bool isRoot() { return (!par) || (par->left != this && par->right != this); }
//????????¬?????¨????????¢?????????
void push() {
if (rev) {
rev = false;
swap(left, right);
if (left) {
left->rev = !(left->rev);
}
if (right) {
right->rev = !(right->rev);
}
}
}
};
class LinkCutTree {
private:
int getSize(node *u) { return u ? u->size : 0; }
void updateSize(node *u) {
u->size = 1 + getSize(u->left) + getSize(u->right);
}
// ch??¨p???????????¢????????????(lch:?????????????????????)
void connect(node *ch, node *p, bool lch) {
if (ch) {
ch->par = p;
}
if (lch) {
p->left = ch;
} else {
p->right = ch;
}
}
// zig, zig-zag, zig-zig ???????¨????????????¢?????¨???
void rotate(node *u) {
node *p = u->par;
node *gp = p->par;
bool isRootP = p->isRoot();
bool lch = (u == p->left);
connect(lch ? (u->right) : (u->left), p, lch);
connect(p, u, !lch);
updateSize(p);
updateSize(u);
if (isRootP) {
// zig-step
u->par = gp;
} else {
// zig-zag or zig-zig step
connect(u, gp, (p == gp->left));
updateSize(u);
}
}
// u???????????¬?????¨???????????????
void splay(node *u) {
while (!(u->isRoot())) {
node *p = u->par;
node *gp = p->par;
if (!(p->isRoot())) {
gp->push();
}
p->push();
u->push();
if (!(p->isRoot())) {
// zig-zig, zig-zag
rotate((u == p->left) == (p == gp->left) ? p : u);
}
rotate(u);
}
u->push();
}
node *expose(node *u) {
node *last = nullptr;
for (node *v = u; v; v = v->par) {
splay(v);
v->left = last;
updateSize(v);
last = v;
}
splay(u);
return last;
}
//??????u?????¨????????¨???????????????(????????¬?????¨)???????????????
void evert(node *u) {
expose(u);
u->rev = !(u->rev);
}
public:
node **arr;
LinkCutTree() {}
void build(int node_size) {
arr = new node *[node_size];
for (int i = 0; i < node_size; i++) {
arr[i] = new node(i);
}
}
int TreeSize(node *u) {
evert(u);
return getSize(u);
}
int TreeSize(int unum) { return TreeSize(arr[unum]); }
node *findRoot(node *u) {
expose(u);
while (u->right) {
u = u->right;
}
splay(u);
return u;
}
node *findRoot(int unum) { return findRoot(arr[unum]); }
bool connected(node *u, node *v) {
if (u == v) {
return true;
}
expose(u);
expose(v);
return u->par;
}
bool connected(int unum, int vnum) { return connected(arr[unum], arr[vnum]); }
void link(node *u, node *v) {
if (connected(u, v))
return;
evert(u);
u->par = v;
}
void link(int unum, int vnum) { link(arr[unum], arr[vnum]); }
void cut(node *u, node *v) {
evert(u);
expose(v);
v->right->par = nullptr;
v->right = nullptr;
}
void cut(int unum, int vnum) { cut(arr[unum], arr[vnum]); }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
LinkCutTree lt;
int n, m;
cin >> n >> m;
lt.build(n);
rep(i, m) {
int u, v, w;
cin >> u >> v >> w;
if (u) {
cout << lt.connected(v, w) << "\n";
} else {
lt.link(v, w);
}
}
return 0;
}
|
insert
| 179 | 179 | 179 | 181 |
TLE
| |
p02343
|
C++
|
Runtime Error
|
#include <iostream>
#include <list>
#include <vector>
using namespace std;
void makeset(int n, vector<list<int>> &set) {
set.resize(n);
for (int i = 0; i < n; i++) {
set[i].push_back(i);
}
}
void unite(vector<list<int>> &set, int x, int y, int n) {
list<int>::iterator itr;
int idx1 = -1, idx2 = -1;
for (int i = 0; i < n; i++) {
if (set[i].empty())
continue;
for (itr = set[i].begin(); itr != set[i].end(); itr++) {
if (*itr == x)
idx1 = i;
if (*itr == y)
idx2 = i;
}
if (idx1 != -1 && idx2 != -1)
break;
}
set[idx1].merge(set[idx2]);
set[idx2].clear();
}
void same(vector<list<int>> &set, int x, int y, int n) {
list<int>::iterator itr;
int idx1 = -1, idx2 = -1;
for (int i = 0; i < n; i++) {
if (set[i].empty())
continue;
for (itr = set[i].begin(); itr != set[i].end(); itr++) {
if (*itr == x)
idx1 = i;
if (*itr == y)
idx2 = i;
}
if (idx1 != -1 && idx2 != -1)
break;
}
if (idx1 == idx2)
cout << '1' << endl;
else
cout << '0' << endl;
}
int main(void) {
int n, q, x, y, c;
cin >> n >> q;
vector<list<int>> set;
makeset(n, set);
for (int i = 0; i < q; i++) {
cin >> c >> x >> y;
if (c == 0)
unite(set, x, y, n);
else
same(set, x, y, n);
}
}
|
#include <iostream>
#include <list>
#include <vector>
using namespace std;
void makeset(int n, vector<list<int>> &set) {
set.resize(n);
for (int i = 0; i < n; i++) {
set[i].push_back(i);
}
}
void unite(vector<list<int>> &set, int x, int y, int n) {
list<int>::iterator itr;
int idx1 = -1, idx2 = -1;
for (int i = 0; i < n; i++) {
if (set[i].empty())
continue;
for (itr = set[i].begin(); itr != set[i].end(); itr++) {
if (*itr == x)
idx1 = i;
if (*itr == y)
idx2 = i;
}
if (idx1 != -1 && idx2 != -1)
break;
}
if (idx1 == idx2)
return;
set[idx1].merge(set[idx2]);
set[idx2].clear();
}
void same(vector<list<int>> &set, int x, int y, int n) {
list<int>::iterator itr;
int idx1 = -1, idx2 = -1;
for (int i = 0; i < n; i++) {
if (set[i].empty())
continue;
for (itr = set[i].begin(); itr != set[i].end(); itr++) {
if (*itr == x)
idx1 = i;
if (*itr == y)
idx2 = i;
}
if (idx1 != -1 && idx2 != -1)
break;
}
if (idx1 == idx2)
cout << '1' << endl;
else
cout << '0' << endl;
}
int main(void) {
int n, q, x, y, c;
cin >> n >> q;
vector<list<int>> set;
makeset(n, set);
for (int i = 0; i < q; i++) {
cin >> c >> x >> y;
if (c == 0)
unite(set, x, y, n);
else
same(set, x, y, n);
}
}
|
insert
| 27 | 27 | 27 | 29 |
0
| |
p02343
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#ifndef LOCAL_
#define fprintf \
if (false) \
fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) \
fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) \
fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, \
#x2, x1, x2);
#define dumplll(x1, x2, x3) \
fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, \
__LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) \
fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) \
fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, \
#x2, x1, x2);
#define loop for (;;)
struct N001 {
std::vector<long> parents;
std::vector<long> numbers;
long n, q;
};
void init(N001 &s, long n) {
s.parents.resize(n + 1, -1);
s.numbers.resize(n + 1, -1);
}
long find(N001 &s, long x) {
if (s.parents[x] == -1)
return x;
return s.parents[x] = find(s, s.parents[x]);
}
bool same(N001 &s, long x, long y) { return find(s, x) == find(s, y); }
void unite(N001 &s, long x, long y) {
long x2 = find(s, x);
long y2 = find(s, y);
if (x2 == y2)
return;
if (not(s.numbers[x2] <= s.numbers[y2]))
std::swap(x2, y2);
s.parents[x2] = y2;
s.numbers[y2] += s.numbers[x2];
}
struct Solver {
Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
N001 u;
void solve() {
long n, q;
scanf("%ld %ld", &n, &q);
init(u, n);
for (long i = 0; i < q; ++i) {
long c, x, y;
scanf("%ld %ld %ld", &c, &x, &y);
if (c == 0)
unite(u, x, y);
else
puts(same(u, x, y) ? "1" : "0");
}
}
};
int main() { loop std::unique_ptr<Solver>(new Solver())->solve(); }
|
#include <bits/stdc++.h>
#ifndef LOCAL_
#define fprintf \
if (false) \
fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) \
fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) \
fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, \
#x2, x1, x2);
#define dumplll(x1, x2, x3) \
fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, \
__LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) \
fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) \
fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, \
#x2, x1, x2);
#define loop for (;;)
struct N001 {
std::vector<long> parents;
std::vector<long> numbers;
long n, q;
};
void init(N001 &s, long n) {
s.parents.resize(n + 1, -1);
s.numbers.resize(n + 1, -1);
}
long find(N001 &s, long x) {
if (s.parents[x] == -1)
return x;
return s.parents[x] = find(s, s.parents[x]);
}
bool same(N001 &s, long x, long y) { return find(s, x) == find(s, y); }
void unite(N001 &s, long x, long y) {
long x2 = find(s, x);
long y2 = find(s, y);
if (x2 == y2)
return;
if (not(s.numbers[x2] <= s.numbers[y2]))
std::swap(x2, y2);
s.parents[x2] = y2;
s.numbers[y2] += s.numbers[x2];
}
struct Solver {
Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
N001 u;
void solve() {
long n, q;
if (scanf("%ld %ld", &n, &q) < 0)
exit(0);
init(u, n);
for (long i = 0; i < q; ++i) {
long c, x, y;
scanf("%ld %ld %ld", &c, &x, &y);
if (c == 0)
unite(u, x, y);
else
puts(same(u, x, y) ? "1" : "0");
}
}
};
int main() { loop std::unique_ptr<Solver>(new Solver())->solve(); }
|
replace
| 55 | 56 | 55 | 57 |
TLE
| |
p02343
|
C++
|
Runtime Error
|
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <nmmintrin.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#define rep(i, s, n) for (int i = (s); (n) > i; i++)
#define REP(i, n) rep(i, 0, n)
#define RANGE(x, a, b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a, b, c, d) \
(RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b))
#define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d))
#define PW(x) ((x) * (x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a, b) ((a >> b) & 1)
#define bitset(a, b) (a |= (1 << b))
#define bitunset(a, b) (a &= ~(1 << b))
#define MP(a, b) make_pair((a), (b))
#define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
class UFNode;
class LNode;
class LNode {
public:
UFNode *Myval;
LNode *Prev, *Next;
LNode() : Prev(NULL), Next(NULL), Myval(NULL) {}
LNode(LNode *pr, LNode *nx, UFNode *val) : Prev(pr), Next(nx), Myval(val) {}
void Isolate() {
if (this->Prev) {
this->Prev->Next = this->Next;
this->Next->Prev = this->Prev;
}
this->Prev = NULL;
this->Next = new LNode;
}
static void Isolate(LNode *st, LNode *en) {
if (st->Prev) {
st->Prev->Next = en->Next;
en->Next->Prev = st->Prev;
}
st->Prev = NULL;
en->Next = new LNode;
}
static void Insert(LNode *lis, LNode *nod) {
nod->Isolate();
delete nod->Next;
nod->Prev = lis->Prev;
nod->Next = lis;
if (lis->Prev)
lis->Prev->Next = nod;
lis->Prev = nod;
}
static void Splice(LNode *pl, LNode *st, LNode *en) {
Isolate(st, en);
delete en->Next;
en->Next = pl;
st->Prev = pl->Prev;
if (pl->Prev)
pl->Prev->Next = st;
pl->Prev = en;
}
};
class UFNode {
public:
UFNode *p;
int rank = 0, elem, NLcou = 0, Ccou = 0;
;
LNode *NLnode, *DFSnode, *Cnode;
LNode *Child, *Chlast, *NLlast;
LNode *DFSlast;
UFNode(int element, UFNode *par) : elem(element), p(par) {
DFSlast = new LNode;
DFSnode = new LNode(NULL, new LNode, this);
NLnode = new LNode(NULL, new LNode, this);
Cnode = new LNode(NULL, new LNode, this);
NLlast = NULL;
Chlast = new LNode;
Child = Chlast;
}
};
class UnionFind_Deletion {
public:
int n, setcou = 0;
vector<UFNode *> element;
UnionFind_Deletion(int size) : n(size), element(n, NULL) {
REP(i, n) {
element[i] = new UFNode(i, NULL);
element[i]->p = element[i];
}
}
bool isReduced(UFNode *root) { return root->Ccou < 4 && !root->NLcou; }
bool isRoot(UFNode *node) { return node->p == node; }
void Unite(int a, int b) {
UFNode *ap = Find(a), *bp = Find(b);
if (ap == bp)
return;
if (ap->rank < bp->rank)
swap(ap, bp);
else if (ap->rank == bp->rank && ap->Ccou < bp->Ccou)
swap(ap, bp);
if (isReduced(bp) && bp->Ccou < 3) {
while (bp->Child->Myval != NULL) {
bp->Child->Myval->p = ap;
bp->Child->Myval->rank = 0;
ap->Ccou++;
LNode *buf = bp->Child->Next;
LNode::Insert(ap->Child, bp->Child);
ap->Child = bp->Child;
LNode::Insert(ap->DFSnode->Next, bp->Child->Myval->DFSnode);
bp->Child = buf;
}
bp->p = ap;
bp->rank = 0;
ap->Ccou++;
LNode::Insert(ap->Child, bp->Cnode);
ap->Child = bp->Cnode;
LNode::Insert(ap->DFSnode->Next, bp->DFSnode);
ap->rank = max(ap->rank, 1);
} else {
bp->p = ap;
if (ap->rank == bp->rank)
ap->rank++;
ap->Ccou++;
LNode::Insert(ap->Child, bp->Cnode);
ap->Child = bp->Cnode;
LNode::Insert(ap->NLnode, bp->NLnode);
LNode::Splice(bp->DFSnode->Next, bp->DFSnode, bp->DFSlast);
}
}
UFNode *Relink(UFNode *a) {
if (isRoot(a->p))
return a;
if (a->p->Chlast->Myval != a) {
LNode::Insert(a->p->p->Cnode->Next, a->Cnode);
LNode::Splice(a->p->DFSnode, a->DFSnode, a->p->DFSnode->Prev);
} else {
LNode::Insert(a->p->p->Chlast, a->Cnode);
LNode::Insert(a->p->p->DFSlast, a->DFSnode);
}
a->Cnode->Isolate();
if (a->p->Ccou) {
a->p->rank = 0;
if (isRoot(a->p->p)) {
a->p->NLnode->Isolate();
if (a->p->p->NLcou)
a->p->p->rank = 1;
}
}
if (a->p->Ccou == 2)
for (auto itr = a->p->Cnode; itr->Myval != NULL; itr = itr->Next)
Relink(itr->Myval);
return a;
}
UFNode *Find(int a) {
UFNode *x = element[a];
while (!isRoot(x->p->p)) {
UFNode *t = x->p;
Relink(x);
x = t;
}
return x->p;
}
void Delete(int a) {
UFNode *x = element[a], *rt = Find(a);
if (!x->Ccou) {
x->p->Ccou--;
x->Cnode->Isolate();
x->DFSnode->Isolate();
} else {
if (isReduced(rt)) {
UFNode *nrt = x->Cnode->Myval;
for (auto itr = x->Cnode; itr->Myval != NULL; itr = itr->Next) {
itr->Myval->p = nrt;
LNode::Insert(nrt->DFSlast, itr);
if (itr->Myval != nrt)
LNode::Insert(nrt->Chlast, itr);
}
delete x;
} else {
UFNode *leaf, *par;
if (isRoot(x->p))
leaf = x->DFSlast->Prev->Myval;
else {
if (x->Cnode->Next)
leaf = x->Cnode->Next->Myval->DFSnode->Prev->Myval;
else
leaf = x->DFSnode->Prev->Myval;
}
swap(x->elem, leaf->elem);
par = leaf->p;
leaf->p->Ccou--;
leaf->Cnode->Isolate();
leaf->DFSnode->Isolate();
if (!isReduced(par)) {
if (isRoot(par)) {
UFNode *nl = par->NLnode->Myval;
Relink(nl->Child->Next->Next->Myval);
Relink(nl->Child->Next->Myval);
Relink(nl->Child->Myval);
} else {
Relink(par->Child->Next->Myval);
Relink(par->Child->Myval);
}
}
}
}
}
};
signed main() {
int n, q;
scanf("%d %d", &n, &q);
UnionFind_Deletion ufd(n);
REP(i, q) {
int mode;
int a, b;
scanf("%d", &mode);
switch (mode) {
case 0: // Unite
scanf("%d %d", &a, &b);
ufd.Unite(a, b);
break;
case 1: // Find
scanf("%d %d", &a, &b);
printf(ufd.Find(a) == ufd.Find(b) ? "1\n" : "0\n");
break;
case 2: // Delete
scanf("%d", &a);
ufd.Delete(a);
break;
}
}
return 0;
}
|
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <nmmintrin.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#define rep(i, s, n) for (int i = (s); (n) > i; i++)
#define REP(i, n) rep(i, 0, n)
#define RANGE(x, a, b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a, b, c, d) \
(RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b))
#define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d))
#define PW(x) ((x) * (x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a, b) ((a >> b) & 1)
#define bitset(a, b) (a |= (1 << b))
#define bitunset(a, b) (a &= ~(1 << b))
#define MP(a, b) make_pair((a), (b))
#define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
class UFNode;
class LNode;
class LNode {
public:
UFNode *Myval;
LNode *Prev, *Next;
LNode() : Prev(NULL), Next(NULL), Myval(NULL) {}
LNode(LNode *pr, LNode *nx, UFNode *val) : Prev(pr), Next(nx), Myval(val) {}
void Isolate() {
if (this->Prev) {
this->Prev->Next = this->Next;
this->Next->Prev = this->Prev;
}
this->Prev = NULL;
this->Next = new LNode;
}
static void Isolate(LNode *st, LNode *en) {
if (st->Prev) {
st->Prev->Next = en->Next;
en->Next->Prev = st->Prev;
}
st->Prev = NULL;
en->Next = new LNode;
}
static void Insert(LNode *lis, LNode *nod) {
nod->Isolate();
delete nod->Next;
nod->Prev = lis->Prev;
nod->Next = lis;
if (lis->Prev)
lis->Prev->Next = nod;
lis->Prev = nod;
}
static void Splice(LNode *pl, LNode *st, LNode *en) {
Isolate(st, en);
delete en->Next;
en->Next = pl;
st->Prev = pl->Prev;
if (pl->Prev)
pl->Prev->Next = st;
pl->Prev = en;
}
};
class UFNode {
public:
UFNode *p;
int rank = 0, elem, NLcou = 0, Ccou = 0;
;
LNode *NLnode, *DFSnode, *Cnode;
LNode *Child, *Chlast, *NLlast;
LNode *DFSlast;
UFNode(int element, UFNode *par) : elem(element), p(par) {
DFSlast = new LNode;
DFSnode = new LNode(NULL, new LNode, this);
NLnode = new LNode(NULL, new LNode, this);
Cnode = new LNode(NULL, new LNode, this);
NLlast = NULL;
Chlast = new LNode;
Child = Chlast;
}
};
class UnionFind_Deletion {
public:
int n, setcou = 0;
vector<UFNode *> element;
UnionFind_Deletion(int size) : n(size), element(n, NULL) {
REP(i, n) {
element[i] = new UFNode(i, NULL);
element[i]->p = element[i];
}
}
bool isReduced(UFNode *root) { return root->Ccou < 4 && !root->NLcou; }
bool isRoot(UFNode *node) { return node->p == node; }
void Unite(int a, int b) {
UFNode *ap = Find(a), *bp = Find(b);
if (ap == bp)
return;
if (ap->rank < bp->rank)
swap(ap, bp);
else if (ap->rank == bp->rank && ap->Ccou < bp->Ccou)
swap(ap, bp);
if (isReduced(bp) && bp->Ccou < 3) {
while (bp->Child->Myval != NULL) {
bp->Child->Myval->p = ap;
bp->Child->Myval->rank = 0;
ap->Ccou++;
LNode *buf = bp->Child->Next;
LNode::Insert(ap->Child, bp->Child);
ap->Child = bp->Child;
LNode::Insert(ap->DFSnode->Next, bp->Child->Myval->DFSnode);
bp->Child = buf;
}
bp->p = ap;
bp->rank = 0;
ap->Ccou++;
LNode::Insert(ap->Child, bp->Cnode);
ap->Child = bp->Cnode;
LNode::Insert(ap->DFSnode->Next, bp->DFSnode);
ap->rank = max(ap->rank, 1);
} else {
bp->p = ap;
if (ap->rank == bp->rank)
ap->rank++;
ap->Ccou++;
LNode::Insert(ap->Child, bp->Cnode);
ap->Child = bp->Cnode;
LNode::Insert(ap->NLnode, bp->NLnode);
LNode::Splice(bp->DFSnode->Next, bp->DFSnode, bp->DFSlast);
}
}
UFNode *Relink(UFNode *a) {
if (isRoot(a->p))
return a;
if (a->p->Chlast->Myval != a) {
LNode::Insert(a->p->p->Cnode->Next, a->Cnode);
LNode::Splice(a->p->DFSnode, a->DFSnode, a->p->DFSnode->Prev);
} else {
LNode::Insert(a->p->p->Chlast, a->Cnode);
LNode::Insert(a->p->p->DFSlast, a->DFSnode);
}
a->Cnode->Isolate();
if (a->p->Ccou) {
a->p->rank = 0;
if (isRoot(a->p->p)) {
a->p->NLnode->Isolate();
if (a->p->p->NLcou)
a->p->p->rank = 1;
}
}
if (a->p->Ccou == 2)
for (auto itr = a->p->Cnode; itr->Myval != NULL; itr = itr->Next)
Relink(itr->Myval);
return a;
}
UFNode *Find(int a) {
UFNode *x = element[a];
while (!isRoot(x->p)) {
UFNode *t = x->p;
Relink(x);
x = t;
}
return x->p;
}
void Delete(int a) {
UFNode *x = element[a], *rt = Find(a);
if (!x->Ccou) {
x->p->Ccou--;
x->Cnode->Isolate();
x->DFSnode->Isolate();
} else {
if (isReduced(rt)) {
UFNode *nrt = x->Cnode->Myval;
for (auto itr = x->Cnode; itr->Myval != NULL; itr = itr->Next) {
itr->Myval->p = nrt;
LNode::Insert(nrt->DFSlast, itr);
if (itr->Myval != nrt)
LNode::Insert(nrt->Chlast, itr);
}
delete x;
} else {
UFNode *leaf, *par;
if (isRoot(x->p))
leaf = x->DFSlast->Prev->Myval;
else {
if (x->Cnode->Next)
leaf = x->Cnode->Next->Myval->DFSnode->Prev->Myval;
else
leaf = x->DFSnode->Prev->Myval;
}
swap(x->elem, leaf->elem);
par = leaf->p;
leaf->p->Ccou--;
leaf->Cnode->Isolate();
leaf->DFSnode->Isolate();
if (!isReduced(par)) {
if (isRoot(par)) {
UFNode *nl = par->NLnode->Myval;
Relink(nl->Child->Next->Next->Myval);
Relink(nl->Child->Next->Myval);
Relink(nl->Child->Myval);
} else {
Relink(par->Child->Next->Myval);
Relink(par->Child->Myval);
}
}
}
}
}
};
signed main() {
int n, q;
scanf("%d %d", &n, &q);
UnionFind_Deletion ufd(n);
REP(i, q) {
int mode;
int a, b;
scanf("%d", &mode);
switch (mode) {
case 0: // Unite
scanf("%d %d", &a, &b);
ufd.Unite(a, b);
break;
case 1: // Find
scanf("%d %d", &a, &b);
printf(ufd.Find(a) == ufd.Find(b) ? "1\n" : "0\n");
break;
case 2: // Delete
scanf("%d", &a);
ufd.Delete(a);
break;
}
}
return 0;
}
|
replace
| 210 | 211 | 210 | 211 |
0
| |
p02343
|
C++
|
Time Limit Exceeded
|
#include <stdio.h>
#define N 10010
int n;
int father[N];
int findfather(int x) { return x == father[x] ? x : findfather(father[x]); }
void init() {
for (int i = 0; i < n; i++)
father[i] = i;
}
int main() {
int m;
scanf("%d %d", &n, &m);
init();
for (int i = 0; i < m; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a == 0) {
father[findfather(c)] = b;
} else {
printf("%s\n", findfather(b) == findfather(c) ? "1" : "0");
}
}
return 0;
}
|
#include <stdio.h>
#define N 10010
int n;
int father[N];
int findfather(int x) { return x == father[x] ? x : findfather(father[x]); }
void init() {
for (int i = 0; i < n; i++)
father[i] = i;
}
int main() {
int m;
scanf("%d %d", &n, &m);
init();
for (int i = 0; i < m; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a == 0) {
father[findfather(c)] = findfather(b);
} else {
printf("%s\n", findfather(b) == findfather(c) ? "1" : "0");
}
}
return 0;
}
|
replace
| 17 | 18 | 17 | 18 |
TLE
| |
p02343
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, -1, sizeof(mat))
#define N 101
struct edge {
int to, cost;
};
int par[N];
int q, n;
void init(int n) { FOR(i, 0, n) par[i] = i; }
int root(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = root(par[x]);
}
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
par[x] = y;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
init(n);
int com, x, y;
FOR(i, 0, q) {
cin >> com >> x >> y;
if (com) {
if (root(x) == root(y)) {
cout << "1" << endl;
} else {
cout << "0" << endl;
}
} else {
unite(x, y);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, -1, sizeof(mat))
#define N 10000
struct edge {
int to, cost;
};
int par[N];
int q, n;
void init(int n) { FOR(i, 0, n) par[i] = i; }
int root(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = root(par[x]);
}
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
par[x] = y;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
init(n);
int com, x, y;
FOR(i, 0, q) {
cin >> com >> x >> y;
if (com) {
if (root(x) == root(y)) {
cout << "1" << endl;
} else {
cout << "0" << endl;
}
} else {
unite(x, y);
}
}
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p02343
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define DEBUG(x) cout << #x << ": " << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define INT(a) int((a) + 1e-9)
int DX[4] = {1, 0, -1, 0};
int DY[4] = {0, 1, 0, -1};
typedef pair<int, int> Pii;
#define SUPnl 10002
int nl;
int p[SUPnl];
int init() {
REP(ni, nl) { p[ni] = -1; }
}
int getRoot(int a) {
while (true) {
if (p[a] == -1)
return a;
a = p[a];
}
}
bool same(int a, int b) {
int pa = getRoot(a);
int pb = getRoot(b);
if (pa == pb) {
p[b] = pa;
return true;
} else
return false;
}
void unite(int a, int b) {
a = getRoot(a);
b = getRoot(b);
if (a == b)
return;
p[b] = a;
}
int main() {
int ol;
cin >> nl >> ol;
init();
int ot, a, b;
REP(oi, ol) {
cin >> ot >> a >> b;
if (ot == 0)
unite(a, b);
if (ot == 1)
cout << same(a, b) << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define DEBUG(x) cout << #x << ": " << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define INT(a) int((a) + 1e-9)
int DX[4] = {1, 0, -1, 0};
int DY[4] = {0, 1, 0, -1};
typedef pair<int, int> Pii;
#define SUPnl 10002
int nl;
int p[SUPnl];
int init() {
REP(ni, nl) { p[ni] = -1; }
}
int getRoot(int a) {
while (true) {
if (p[a] == -1)
return a;
a = p[a];
}
}
bool same(int a, int b) {
int ra = getRoot(a);
int rb = getRoot(b);
if (ra != a)
p[a] = ra;
if (rb != b)
p[b] = rb;
return ra == rb;
}
void unite(int a, int b) {
a = getRoot(a);
b = getRoot(b);
if (a == b)
return;
p[b] = a;
}
int main() {
int ol;
cin >> nl >> ol;
init();
int ot, a, b;
REP(oi, ol) {
cin >> ot >> a >> b;
if (ot == 0)
unite(a, b);
if (ot == 1)
cout << same(a, b) << endl;
}
}
|
replace
| 45 | 52 | 45 | 52 |
TLE
| |
p02343
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long signed int ll;
constexpr ll NIL = -20000000000;
int u[10010];
int main() {
for (int i = 0; i < 10010; i++)
u[i] = -1;
int n, q, x, y, com;
cin >> n >> q;
for (int i = 0; i < q; i++) {
cin >> com >> x >> y;
if (com) {
int c[2] = {x, y};
while (u[c[0]] != -1)
c[0] = u[c[0]];
while (u[c[1]] != -1)
c[1] = u[c[1]];
if (c[0] == c[1])
cout << 1 << endl;
else
cout << 0 << endl;
} else {
int c[2] = {x, y};
while (u[c[0]] != -1)
c[0] = u[c[0]];
while (u[c[1]] != -1)
c[1] = u[c[1]];
u[c[1]] = c[0];
}
}
}
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long signed int ll;
constexpr ll NIL = -20000000000;
int u[10010];
int main() {
for (int i = 0; i < 10010; i++)
u[i] = -1;
int n, q, x, y, com;
cin >> n >> q;
for (int i = 0; i < q; i++) {
cin >> com >> x >> y;
if (com) {
int c[2] = {x, y};
while (u[c[0]] != -1)
c[0] = u[c[0]];
while (u[c[1]] != -1)
c[1] = u[c[1]];
if (c[0] == c[1])
cout << 1 << endl;
else
cout << 0 << endl;
} else {
int c[2] = {x, y};
while (u[c[0]] != -1)
c[0] = u[c[0]];
while (u[c[1]] != -1)
c[1] = u[c[1]];
if (c[0] != c[1])
u[c[1]] = c[0];
}
}
}
|
replace
| 39 | 40 | 39 | 41 |
TLE
| |
p02343
|
C++
|
Runtime Error
|
#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 114514
vector<int> X[MAX_N];
int Group[MAX_N], N, Q, A, B, C;
int main() {
cin >> N >> Q;
for (int i = 0; i < MAX_N; i++) {
X[i].push_back(i);
Group[i] = i;
}
for (int i = 0; i < Q; i++) {
cin >> A >> B >> C;
int D = Group[B], E = Group[C];
if (A == 0) {
if (X[D].size() >= X[E].size()) {
for (int j = 0; j < X[E].size(); j++) {
Group[X[E][j]] = D;
X[D].push_back(X[E][j]);
}
X[E].clear();
} else if (X[D].size() < X[E].size()) {
for (int j = 0; j < X[D].size(); j++) {
Group[X[D][j]] = E;
X[E].push_back(X[D][j]);
}
X[D].clear();
}
}
if (A == 1) {
if (D == E) {
cout << "1" << endl;
} else {
cout << "0" << endl;
}
}
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 114514
vector<int> X[MAX_N];
int Group[MAX_N], N, Q, A, B, C;
int main() {
cin >> N >> Q;
for (int i = 0; i < MAX_N; i++) {
X[i].push_back(i);
Group[i] = i;
}
for (int i = 0; i < Q; i++) {
cin >> A >> B >> C;
int D = Group[B], E = Group[C];
if (A == 0 && D != E) {
if (X[D].size() >= X[E].size()) {
for (int j = 0; j < X[E].size(); j++) {
Group[X[E][j]] = D;
X[D].push_back(X[E][j]);
}
X[E].clear();
} else if (X[D].size() < X[E].size()) {
for (int j = 0; j < X[D].size(); j++) {
Group[X[D][j]] = E;
X[E].push_back(X[D][j]);
}
X[D].clear();
}
}
if (A == 1) {
if (D == E) {
cout << "1" << endl;
} else {
cout << "0" << endl;
}
}
}
return 0;
}
|
replace
| 15 | 16 | 15 | 16 |
0
| |
p02343
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define int long long
#define MOD7 1000000007
#define MOD9 1000000009
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
int nextInt() {
int a;
cin >> a;
return a;
}
char nextChar() {
char a;
cin >> a;
return a;
}
double nextDouble() {
double a;
cin >> a;
return a;
}
string nextString() {
string a;
cin >> a;
return a;
}
void inputVector(vector<int> &v, int &n) {
rep(i, n) { v.push_back(nextInt()); }
}
void inputVector(vector<double> &v, int &n) {
rep(i, n) { v.push_back(nextDouble()); }
}
void inputVector(vector<string> &v, int &n) {
rep(i, n) { v.push_back(nextString()); }
}
class UnionFind {
private:
class Node {
public:
int parent;
Node(int parent) { this->parent = parent; }
};
int root(int x) {
int base = x;
while (x != node[x].parent) {
x = node[x].parent;
}
node[base].parent = x;
return x;
}
vector<Node> node;
public:
UnionFind(int size) {
for (int i = 0; i < size; i++) {
node.push_back(Node(i));
}
}
void unite(int x, int y) { node[root(x)].parent = y; }
bool same(int x, int y) { return root(x) == root(y); }
};
signed main() {
int n, q;
cin >> n >> q;
auto uf = UnionFind(n);
rep(i, q) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
uf.unite(x, y);
} else {
cout << (uf.same(x, y) ? 1 : 0) << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define int long long
#define MOD7 1000000007
#define MOD9 1000000009
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
int nextInt() {
int a;
cin >> a;
return a;
}
char nextChar() {
char a;
cin >> a;
return a;
}
double nextDouble() {
double a;
cin >> a;
return a;
}
string nextString() {
string a;
cin >> a;
return a;
}
void inputVector(vector<int> &v, int &n) {
rep(i, n) { v.push_back(nextInt()); }
}
void inputVector(vector<double> &v, int &n) {
rep(i, n) { v.push_back(nextDouble()); }
}
void inputVector(vector<string> &v, int &n) {
rep(i, n) { v.push_back(nextString()); }
}
class UnionFind {
private:
class Node {
public:
int parent;
Node(int parent) { this->parent = parent; }
};
int root(int x) {
int base = x;
while (x != node[x].parent) {
x = node[x].parent;
}
node[base].parent = x;
return x;
}
vector<Node> node;
public:
UnionFind(int size) {
for (int i = 0; i < size; i++) {
node.push_back(Node(i));
}
}
void unite(int x, int y) { node[root(x)].parent = root(y); }
bool same(int x, int y) { return root(x) == root(y); }
};
signed main() {
int n, q;
cin >> n >> q;
auto uf = UnionFind(n);
rep(i, q) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
uf.unite(x, y);
} else {
cout << (uf.same(x, y) ? 1 : 0) << endl;
}
}
return 0;
}
|
replace
| 83 | 84 | 83 | 84 |
TLE
| |
p02344
|
C++
|
Time Limit Exceeded
|
#include <stack>
#include <stdio.h>
using namespace std;
const int N = 1e5 + 10;
int p[N], val[N];
stack<int> s[N];
int find(int n) {
if (p[n] == n)
return n;
return p[n] = find(p[n]);
}
int main() {
int n, q, l, r, temp, a, b;
scanf("%d%d", &n, &q);
for (int i = 0; i < n; i++) {
p[i] = i;
val[i] = 0;
s[i].push(i);
}
while (q--) {
scanf("%d%d%d", &temp, &l, &r);
if (temp == 1) {
if (find(l) != find(r))
printf("?\n");
else
printf("%d\n", val[r] - val[l]);
} else {
scanf("%d", &temp);
a = find(l);
b = find(r);
if (s[a].size() > s[b].size()) {
p[b] = a;
temp += val[l] - val[r];
while (!s[b].empty()) {
val[s[b].top()] += temp;
s[a].push(s[b].top());
s[b].pop();
}
} else {
p[a] = b;
temp = val[r] - temp - val[l];
while (!s[a].empty()) {
val[s[a].top()] += temp;
s[b].push(s[a].top());
s[a].pop();
}
}
}
}
}
|
#include <stack>
#include <stdio.h>
using namespace std;
const int N = 1e5 + 10;
int p[N], val[N];
stack<int> s[N];
int find(int n) {
if (p[n] == n)
return n;
return p[n] = find(p[n]);
}
int main() {
int n, q, l, r, temp, a, b;
scanf("%d%d", &n, &q);
for (int i = 0; i < n; i++) {
p[i] = i;
val[i] = 0;
s[i].push(i);
}
while (q--) {
scanf("%d%d%d", &temp, &l, &r);
if (temp == 1) {
if (find(l) != find(r))
printf("?\n");
else
printf("%d\n", val[r] - val[l]);
} else {
scanf("%d", &temp);
a = find(l);
b = find(r);
if (a == b)
continue;
if (s[a].size() > s[b].size()) {
p[b] = a;
temp += val[l] - val[r];
while (!s[b].empty()) {
val[s[b].top()] += temp;
s[a].push(s[b].top());
s[b].pop();
}
} else {
p[a] = b;
temp = val[r] - temp - val[l];
while (!s[a].empty()) {
val[s[a].top()] += temp;
s[b].push(s[a].top());
s[a].pop();
}
}
}
}
}
|
insert
| 30 | 30 | 30 | 32 |
TLE
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define ITR(i, c) for (auto i = begin(c); i != end(c); ++i)
#define FORE(x, c) for (auto &x : c)
#define FOR(i, a, n) for (int i = a, i##_len = (int)(n); i < i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (int)(n); i >= 0; --i)
#define ALL(c) begin(c), end(c)
#define RALL(c) rbegin(c), rend(c) // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c, x) (c.find(x) != end(c))
#define dump(...)
const int DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
ITR(i, v) os << *i << (i == end(v) - 1 ? "" : " ");
return os;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
ITR(i, v) is >> *i;
return is;
}
template <class T> istream &operator>>(istream &is, pair<T, T> &p) {
is >> p.first >> p.second;
return is;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
//------------------------------------------------------------------------------
struct before_main_function {
before_main_function() {
#ifdef int
#undef INF
#define INF INFLL
#define stoi stoll
cerr << "\x1b[7m"
<< "'int' is 'long long'"
<< "\x1b[m" << endl;
#endif
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(15) << fixed;
}
} before_main_function;
//------------------------------------------------------------------------------
struct RMQ {
int n;
vector<int> dat;
RMQ(int n_ = 0) {
n = 1;
while (n < n_)
n *= 2;
dat = vector<int>(n * 2 - 1, 2147483647);
}
void update(int i, int x) {
i += n - 1;
dat[i] = x;
while (i > 0) {
i = (i - 1) / 2;
dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
}
}
int query(int a, int b) { return query(a, b, 0, 0, n); }
int query(int a, int b, int k, int l, int r) {
if (r <= a or b <= l)
return 2147483647;
if (a <= l and r <= b)
return dat[k];
int ml = query(a, b, k * 2 + 1, l, (r + l) / 2);
int mr = query(a, b, k * 2 + 2, (r + l) / 2, r);
return min(ml, mr);
}
};
signed main() {
int n, q;
cin >> n >> q;
RMQ segtree(n);
while (q--) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
segtree.update(x, y);
} else {
cout << segtree.query(x, y + 1) << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define ITR(i, c) for (auto i = begin(c); i != end(c); ++i)
#define FORE(x, c) for (auto &x : c)
#define FOR(i, a, n) for (int i = a, i##_len = (int)(n); i < i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (int)(n); i >= 0; --i)
#define ALL(c) begin(c), end(c)
#define RALL(c) rbegin(c), rend(c) // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c, x) (c.find(x) != end(c))
#define dump(...)
const int DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
ITR(i, v) os << *i << (i == end(v) - 1 ? "" : " ");
return os;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
ITR(i, v) is >> *i;
return is;
}
template <class T> istream &operator>>(istream &is, pair<T, T> &p) {
is >> p.first >> p.second;
return is;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
//------------------------------------------------------------------------------
// struct before_main_function {
// before_main_function() {
// #ifdef int
// #undef INF
// #define INF INFLL
// #define stoi stoll
// cerr<<"\x1b[7m"<<"'int' is 'long long'"<<"\x1b[m"<<endl;
// #endif
// cin.tie(0);ios::sync_with_stdio(false);
// cout<<setprecision(15)<<fixed;
// }
// } before_main_function;
//------------------------------------------------------------------------------
struct RMQ {
int n;
vector<int> dat;
RMQ(int n_ = 0) {
n = 1;
while (n < n_)
n *= 2;
dat = vector<int>(n * 2 - 1, 2147483647);
}
void update(int i, int x) {
i += n - 1;
dat[i] = x;
while (i > 0) {
i = (i - 1) / 2;
dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
}
}
int query(int a, int b) { return query(a, b, 0, 0, n); }
int query(int a, int b, int k, int l, int r) {
if (r <= a or b <= l)
return 2147483647;
if (a <= l and r <= b)
return dat[k];
int ml = query(a, b, k * 2 + 1, l, (r + l) / 2);
int mr = query(a, b, k * 2 + 2, (r + l) / 2, r);
return min(ml, mr);
}
};
signed main() {
int n, q;
cin >> n >> q;
RMQ segtree(n);
while (q--) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
segtree.update(x, y);
} else {
cout << segtree.query(x, y + 1) << endl;
}
}
return 0;
}
|
replace
| 49 | 64 | 49 | 61 |
0
|
[7m'int' is 'long long'[m
|
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
struct edge {
int /*from,*/ to, cost;
};
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
static const int INF = 2147483647;
// static const long long INF = 9223372000000000000;
// static const long long INF = 9223372000000000000/2;
// static const int INF = 1000010000;
// int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
// int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
// int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
// int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a, b, c) max((a), max((b), (c)))
#define MIN(a, b, c) min((a), min((b), (c)))
#define SORT(c) sort((c).begin(), (c).end())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
// #define int ll
// Range Minimum Query????????°???????????¨??§
const int MAXN = 114514;
//?????°???????????¨???????????°??????????????????
int n, dat[2 * MAXN - 1];
//?????????
void init(int n_) {
//?°????????????????????´???°???2???????????????
n = 1;
while (n < n_)
n *= 2;
//??¨????????????INT_MAX???
REP(i, 2 * n - 1) dat[i] = INF;
}
// k????????????(0-indexed)???a????????´
void update(int k, int a) {
//????????????
k += n - 1;
dat[k] = a;
//?????????????????´??°
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
//[a,b)???????°????????±???????
//????????????query(a,b,0,0,n)??¨???????????¶
int query(int a, int b, int k, int l, int r) {
//[a,b)??¨[l,r)?????????????????????????????°INF?????????
if (r <= a || b <= l)
return INF;
//[a,b)???[l,r)????????¨???????????§????????°?????????????????????
if (a <= l && r <= b)
return dat[k];
else {
//????????§???????????°??????????????????????°????
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
signed main() {
int q;
scanf("%d%d", &n, &q);
init(n);
REP(i, q) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if (a)
printf("%d\n", query(b, c + 1, 0, 0, n));
else
update(b, c);
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
struct edge {
int /*from,*/ to, cost;
};
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int>> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
static const int INF = 2147483647;
// static const long long INF = 9223372000000000000;
// static const long long INF = 9223372000000000000/2;
// static const int INF = 1000010000;
// int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
// int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
// int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
// int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a, b, c) max((a), max((b), (c)))
#define MIN(a, b, c) min((a), min((b), (c)))
#define SORT(c) sort((c).begin(), (c).end())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
// #define int ll
// Range Minimum Query????????°???????????¨??§
const int MAXN = 1145140;
//?????°???????????¨???????????°??????????????????
int n, dat[2 * MAXN - 1];
//?????????
void init(int n_) {
//?°????????????????????´???°???2???????????????
n = 1;
while (n < n_)
n *= 2;
//??¨????????????INT_MAX???
REP(i, 2 * n - 1) dat[i] = INF;
}
// k????????????(0-indexed)???a????????´
void update(int k, int a) {
//????????????
k += n - 1;
dat[k] = a;
//?????????????????´??°
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
//[a,b)???????°????????±???????
//????????????query(a,b,0,0,n)??¨???????????¶
int query(int a, int b, int k, int l, int r) {
//[a,b)??¨[l,r)?????????????????????????????°INF?????????
if (r <= a || b <= l)
return INF;
//[a,b)???[l,r)????????¨???????????§????????°?????????????????????
if (a <= l && r <= b)
return dat[k];
else {
//????????§???????????°??????????????????????°????
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
signed main() {
int q;
scanf("%d%d", &n, &q);
init(n);
REP(i, q) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if (a)
printf("%d\n", query(b, c + 1, 0, 0, n));
else
update(b, c);
}
return 0;
}
|
replace
| 62 | 63 | 62 | 63 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; }
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
out << '(' << a.first << ',' << a.second << ')';
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &a) {
out << '[';
for (const T &i : a)
out << i << ',';
out << ']';
return out;
}
template <class T> ostream &operator<<(ostream &out, const set<T> &a) {
out << '{';
for (const T &i : a)
out << i << ',';
out << '}';
return out;
}
template <class T, class S>
ostream &operator<<(ostream &out, const map<T, S> &a) {
out << '{';
for (auto &i : a)
out << i << ',';
out << '}';
return out;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
template <typename Monoid> struct lazysegtree {
using T = typename Monoid::T;
using E = typename Monoid::E;
int n, height;
vector<T> dat;
vector<E> lazy;
lazysegtree() {}
lazysegtree(int n_) {
n = 1;
while (n < n_)
n *= 2, height++;
dat.assign(n * 2, Monoid::dt());
lazy.assign(n * 2, Monoid::de());
}
void build(vector<T> v) {
REP(i, v.size()) dat[i + n] = v[i];
for (int i = n - 1; i > 0; --i)
dat[i] = Monoid::f(dat[i * 2], dat[i * 2 + 1]);
}
inline T reflect(int k) {
return lazy[k] == Monoid::de() ? dat[k] : Monoid::g(dat[k], lazy[k]);
}
inline void eval(int k) {
if (lazy[k] == Monoid::de())
return;
lazy[2 * k] = Monoid::h(lazy[k * 2], lazy[k]);
lazy[2 * k + 1] = Monoid::h(lazy[k * 2 + 1], lazy[k]);
dat[k] = reflect(k);
lazy[k] = Monoid::de();
}
inline void thrust(int k) {
for (int i = height; i; --i)
eval(k >> i);
}
inline void recalc(int k) {
while (k >>= 1)
dat[k] = Monoid::f(reflect(k * 2), reflect(k * 2 + 1));
}
void update(int a, int b, E x) {
thrust(a += n);
thrust(b += n - 1);
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
lazy[l] = Monoid::h(lazy[l], x), ++l;
if (r & 1)
--r, lazy[r] = Monoid::h(lazy[r], x);
}
recalc(a);
recalc(b);
}
T query(int a, int b) {
thrust(a += n);
thrust(b += n - 1);
T vl = Monoid::dt(), vr = Monoid::dt();
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
vl = Monoid::f(vl, reflect(l++));
if (r & 1)
vr = Monoid::f(reflect(--r), vr);
}
return Monoid::f(vl, vr);
}
friend ostream &operator<<(ostream &out, const lazysegtree<Monoid> &seg) {
out << "---------------------" << endl;
int cnt = 0;
for (int i = 1; i <= seg.n; i *= 2) {
REP(j, i) {
out << "(" << seg.dat[cnt] << "," << seg.lazy[cnt] << ") ";
cnt++;
}
out << endl;
}
out << "---------------------" << endl;
return out;
}
};
struct update_min {
using T = ll;
using E = ll;
static constexpr T dt() { return INT_MAX; }
static constexpr E de() { return INT_MAX; }
static T f(const T &a, const T &b) { return min(a, b); }
static T g(const T &a, const E &b) { return b; }
static E h(const E &a, const E &b) { return b; }
};
struct add_sum {
using T = PII; // (頂点の値, 頂点の区間長)
using E = ll;
static constexpr T dt() { return PII(0, 1); }
static constexpr E de() { return 0; }
static T f(const T &a, const T &b) {
return PII(a.first + b.first, a.second + b.second);
}
static T g(const T &a, const E &b) {
return PII(a.first + b * a.second, a.second);
}
static E h(const E &a, const E &b) { return a + b; }
};
struct update_sum {
using T = ll;
using E = ll;
static constexpr T dt() { return 0; }
static constexpr E de() { return 0; }
static T f(const T &a, const T &b) { return a + b; }
static T g(const T &a, const E &b) { return b; }
static E h(const E &a, const E &b) { return b; }
};
struct add_min {
using T = PII; // (頂点の値, 頂点の区間長)
using E = ll;
static constexpr T dt() { return PII(0, 1); }
static constexpr E de() { return 0; }
static T f(const T &a, const T &b) { return min(a, b); }
static T g(const T &a, const E &b) {
return PII(a.first + b * a.second, a.second);
}
static E h(const E &a, const E &b) { return a + b; }
};
struct xor_sum {
using T = PII; // (頂点の値, 頂点の区間長)
using E = ll;
static constexpr T dt() { return PII(0, 1); }
static constexpr E de() { return 0; }
static T f(const T &a, const T &b) {
return PII(a.first + b.first, a.second + b.second);
}
static T g(const T &a, const E &b) {
return PII((b >= 1 ? b - a.first : a.first) * a.second, a.second);
}
static E h(const E &a, const E &b) { return a ^ b; }
};
// 点更新区間最小
namespace DSL2A {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<update_min> seg(n);
while (q--) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0) {
seg.update(x, x + 1, y);
} else {
cout << seg.query(x, y + 1) << endl;
}
}
}
} // namespace DSL2A
// 点加算区間和
namespace DSL2B {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<add_sum> seg(n);
while (q--) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0) {
x--;
seg.update(x, x + 1, y);
} else {
x--, y--;
cout << seg.query(x, y + 1) << endl;
}
}
}
} // namespace DSL2B
// 区間更新区間最小
namespace DSL2F {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<update_min> seg(n);
while (q--) {
int c, s, t;
cin >> c >> s >> t;
if (c == 0) {
int x;
cin >> x;
seg.update(s, t + 1, x);
} else {
cout << seg.query(s, t + 1) << endl;
}
}
}
} // namespace DSL2F
// 区間加算区間和
namespace DSL2G {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<add_sum> seg(n);
while (q--) {
int c, s, t;
cin >> c >> s >> t;
s--, t--;
if (c == 0) {
int x;
cin >> x;
seg.update(s, t + 1, x);
} else {
cout << seg.query(s, t + 1) << endl;
}
}
}
} // namespace DSL2G
// 区間加算区間最小
namespace DSL2H {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<add_min> seg(n);
while (q--) {
int c, s, t;
cin >> c >> s >> t;
if (c == 0) {
int x;
cin >> x;
seg.update(s, t + 1, x);
} else {
cout << seg.query(s, t + 1) << endl;
}
}
}
} // namespace DSL2H
// 区間更新区間和
namespace DSL2I {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<update_sum> seg(n);
while (q--) {
int c, s, t;
cin >> c >> s >> t;
if (c == 0) {
int x;
cin >> x;
seg.update(s, t + 1, x);
} else {
cout << seg.query(s, t + 1) << endl;
}
}
}
} // namespace DSL2I
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
DSL2A::solve();
// DSL2B::solve();
// DSL2F::solve();
// DSL2G::solve();
// DSL2H::solve();
// DSL2I::solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; }
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
out << '(' << a.first << ',' << a.second << ')';
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &a) {
out << '[';
for (const T &i : a)
out << i << ',';
out << ']';
return out;
}
template <class T> ostream &operator<<(ostream &out, const set<T> &a) {
out << '{';
for (const T &i : a)
out << i << ',';
out << '}';
return out;
}
template <class T, class S>
ostream &operator<<(ostream &out, const map<T, S> &a) {
out << '{';
for (auto &i : a)
out << i << ',';
out << '}';
return out;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
template <typename Monoid> struct lazysegtree {
using T = typename Monoid::T;
using E = typename Monoid::E;
int n, height;
vector<T> dat;
vector<E> lazy;
lazysegtree() {}
lazysegtree(int n_) {
n = 1, height = 0;
while (n < n_) {
n *= 2;
height++;
}
dat.assign(n * 2, Monoid::dt());
lazy.assign(n * 2, Monoid::de());
}
void build(vector<T> v) {
REP(i, v.size()) dat[i + n] = v[i];
for (int i = n - 1; i > 0; --i)
dat[i] = Monoid::f(dat[i * 2], dat[i * 2 + 1]);
}
inline T reflect(int k) {
return lazy[k] == Monoid::de() ? dat[k] : Monoid::g(dat[k], lazy[k]);
}
inline void eval(int k) {
if (lazy[k] == Monoid::de())
return;
lazy[2 * k] = Monoid::h(lazy[k * 2], lazy[k]);
lazy[2 * k + 1] = Monoid::h(lazy[k * 2 + 1], lazy[k]);
dat[k] = reflect(k);
lazy[k] = Monoid::de();
}
inline void thrust(int k) {
for (int i = height; i; --i)
eval(k >> i);
}
inline void recalc(int k) {
while (k >>= 1)
dat[k] = Monoid::f(reflect(k * 2), reflect(k * 2 + 1));
}
void update(int a, int b, E x) {
thrust(a += n);
thrust(b += n - 1);
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
lazy[l] = Monoid::h(lazy[l], x), ++l;
if (r & 1)
--r, lazy[r] = Monoid::h(lazy[r], x);
}
recalc(a);
recalc(b);
}
T query(int a, int b) {
thrust(a += n);
thrust(b += n - 1);
T vl = Monoid::dt(), vr = Monoid::dt();
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
vl = Monoid::f(vl, reflect(l++));
if (r & 1)
vr = Monoid::f(reflect(--r), vr);
}
return Monoid::f(vl, vr);
}
friend ostream &operator<<(ostream &out, const lazysegtree<Monoid> &seg) {
out << "---------------------" << endl;
int cnt = 0;
for (int i = 1; i <= seg.n; i *= 2) {
REP(j, i) {
out << "(" << seg.dat[cnt] << "," << seg.lazy[cnt] << ") ";
cnt++;
}
out << endl;
}
out << "---------------------" << endl;
return out;
}
};
struct update_min {
using T = ll;
using E = ll;
static constexpr T dt() { return INT_MAX; }
static constexpr E de() { return INT_MAX; }
static T f(const T &a, const T &b) { return min(a, b); }
static T g(const T &a, const E &b) { return b; }
static E h(const E &a, const E &b) { return b; }
};
struct add_sum {
using T = PII; // (頂点の値, 頂点の区間長)
using E = ll;
static constexpr T dt() { return PII(0, 1); }
static constexpr E de() { return 0; }
static T f(const T &a, const T &b) {
return PII(a.first + b.first, a.second + b.second);
}
static T g(const T &a, const E &b) {
return PII(a.first + b * a.second, a.second);
}
static E h(const E &a, const E &b) { return a + b; }
};
struct update_sum {
using T = ll;
using E = ll;
static constexpr T dt() { return 0; }
static constexpr E de() { return 0; }
static T f(const T &a, const T &b) { return a + b; }
static T g(const T &a, const E &b) { return b; }
static E h(const E &a, const E &b) { return b; }
};
struct add_min {
using T = PII; // (頂点の値, 頂点の区間長)
using E = ll;
static constexpr T dt() { return PII(0, 1); }
static constexpr E de() { return 0; }
static T f(const T &a, const T &b) { return min(a, b); }
static T g(const T &a, const E &b) {
return PII(a.first + b * a.second, a.second);
}
static E h(const E &a, const E &b) { return a + b; }
};
struct xor_sum {
using T = PII; // (頂点の値, 頂点の区間長)
using E = ll;
static constexpr T dt() { return PII(0, 1); }
static constexpr E de() { return 0; }
static T f(const T &a, const T &b) {
return PII(a.first + b.first, a.second + b.second);
}
static T g(const T &a, const E &b) {
return PII((b >= 1 ? b - a.first : a.first) * a.second, a.second);
}
static E h(const E &a, const E &b) { return a ^ b; }
};
// 点更新区間最小
namespace DSL2A {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<update_min> seg(n);
while (q--) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0) {
seg.update(x, x + 1, y);
} else {
cout << seg.query(x, y + 1) << endl;
}
}
}
} // namespace DSL2A
// 点加算区間和
namespace DSL2B {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<add_sum> seg(n);
while (q--) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0) {
x--;
seg.update(x, x + 1, y);
} else {
x--, y--;
cout << seg.query(x, y + 1) << endl;
}
}
}
} // namespace DSL2B
// 区間更新区間最小
namespace DSL2F {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<update_min> seg(n);
while (q--) {
int c, s, t;
cin >> c >> s >> t;
if (c == 0) {
int x;
cin >> x;
seg.update(s, t + 1, x);
} else {
cout << seg.query(s, t + 1) << endl;
}
}
}
} // namespace DSL2F
// 区間加算区間和
namespace DSL2G {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<add_sum> seg(n);
while (q--) {
int c, s, t;
cin >> c >> s >> t;
s--, t--;
if (c == 0) {
int x;
cin >> x;
seg.update(s, t + 1, x);
} else {
cout << seg.query(s, t + 1) << endl;
}
}
}
} // namespace DSL2G
// 区間加算区間最小
namespace DSL2H {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<add_min> seg(n);
while (q--) {
int c, s, t;
cin >> c >> s >> t;
if (c == 0) {
int x;
cin >> x;
seg.update(s, t + 1, x);
} else {
cout << seg.query(s, t + 1) << endl;
}
}
}
} // namespace DSL2H
// 区間更新区間和
namespace DSL2I {
void solve() {
int n, q;
cin >> n >> q;
lazysegtree<update_sum> seg(n);
while (q--) {
int c, s, t;
cin >> c >> s >> t;
if (c == 0) {
int x;
cin >> x;
seg.update(s, t + 1, x);
} else {
cout << seg.query(s, t + 1) << endl;
}
}
}
} // namespace DSL2I
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
DSL2A::solve();
// DSL2B::solve();
// DSL2F::solve();
// DSL2G::solve();
// DSL2H::solve();
// DSL2I::solve();
return 0;
}
|
replace
| 72 | 75 | 72 | 77 |
0
| |
p02345
|
C++
|
Runtime Error
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// ?????¢
// XCode??§???EOF??\??????Ctrl+D
// ?\???Alt+\
// ans???????§?INT?????????2,147,483,647????¶????????????¨??????????????§long
// long?????£???????????????????????????
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////
// RMQ (Range Minimum Query)
//??????????????§?????§?????????????????°???????????¨(?????¨????????¨)??§????????£?????????
////////////////////////////////////////
// #define debug
// //*******************************************************************************************************************************************
#ifdef debug
#include <chrono>
#endif
#include <algorithm> // next_permutation
#include <cmath>
#include <cstdio>
#include <cstring> //memcpy
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric> //accumulate
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// #include <map>
// #include <unordered_map> //hash func.
#include <fstream> //ifstream, ofstream
#include <iterator> //insert_iterator::inserter
#define NDEBUG // If NDEBUG is defined before #include <cassert>, assert will be
// ignored. You had better define NDEBUG when u submit the code.
#include <cassert> //assert
using namespace std;
#define dout cout
// If u wanna output to a text file instead of standard output, plz define
// OUTPUTFILE. #define OUTPUTFILE "output.txt"
// //*******************************************************************************************************************************************
#ifdef OUTPUTFILE
#define dout outputfile
ofstream outputfile(OUTPUTFILE);
#define OutputFilePath \
"/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/" \
"output.txt"
#endif
#define din cin
// If u wanna input from a text file instead of standard input, plz define
// INPUTFROMTEXTFILE???. #define INPUTFILE "input.txt"
// //*******************************************************************************************************************************************
#ifdef INPUTFILE
#define din inputfile
ifstream inputfile(INPUTFILE);
#endif
#define scand(A) scanf("%d", &(A))
#define scans(A) scanf("%s", (A))
#define disp(A) dout << #A << " = " << setw(3) << (A) << endl
#define disP(A) dout << setw(3) << (A) << " "
#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define dispAll(A, n) \
dout << #A << " = "; \
rep(j, 0, (n)) { disP(A[j]); } \
dout << endl
// #define dispAll(A,n) cout << #A << " = "; rep(j, 0, (n)) {cout << setw(3) <<
// A[j] << " ";} cout << endl
#define sign(x) ((x) > 0) - ((x) < 0) // x<0: -1, x=0: 0, x>0: +1
#define p(i) (i) / 2
#define l(i) (i) * 2
#define r(i) (i) * 2 + 1
int dx[] = {
1, -1, 0, 0, 1,
1, -1, -1}; //???????????????????????????????¨??????????????????????????????????
int dy[] = {0, 0, -1, 1, -1, 1, 1, -1};
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long ull;
const int INF = (1 << 31) - 1;
const ll INF_LL = (ll)9e18 - 1LL; // Be careful for overflow.
const ull INF_ULL = (ull)1e19 - 1ULL;
const int NONE = -1;
const ll MOD =
(ll)1e9 + 7; //??§???????´???°?????£??¨??¨????????°????????????10???7??????
const int N_MAX = 100010; // num of vertex or element
const int M_MAX = 100010; // num of edge
const int DATA_MAX = 1010;
int N;
int a[N_MAX * 2];
int k;
int pow2k;
int B = 316; // floor(sqrt(N_MAX))
int b[N_MAX]; // B+1 elements
int tmp[N_MAX];
void initialize() {
k = 0;
pow2k = 1;
while (pow2k < N) {
pow2k *= 2;
k++;
}
rep(i, 0, 2 * pow2k) { a[i] = INF; }
}
int find(int from, int to) {
#ifdef debug
dout << "------ find( " << from << ", " << to << ")\n";
#endif
assert(from <= to);
assert(to < N);
int i = from + pow2k;
int j = to + pow2k;
int ans = INF;
int limit = pow2k;
#ifdef debug
disp(i);
disp(j);
disp(limit);
disp(ans);
#endif
while (i < j and limit <= i and j < 2 * limit) {
if (i == r(p(i)))
ans = min(ans, a[i]), i = p(i) + 1;
else
i = p(i);
if (j == l(p(j)))
ans = min(ans, a[j]), j = p(j) - 1;
else
j = p(j);
limit /= 2;
#ifdef debug
dout << "--- while-loop --- \n";
disp(i);
disp(j);
disp(limit);
disp(ans);
#endif
}
if (i == j and limit <= i and j < 2 * limit) {
#ifdef debug
dout << "--- last check --- \n";
dout << "check a[" << i << "] = " << a[i] << endl;
#endif
assert(i == j);
ans = min(ans, a[i]);
}
#ifdef debug
dout << "--- FINAL --- \n";
disp(i);
disp(j);
disp(limit);
disp(ans);
#endif
return ans;
}
void update(int i, int x) {
#ifdef debug
dout << "------ update( i=" << i << ", x=" << x << ")\n";
#endif
i = i + pow2k;
a[i] = x;
i = p(i);
while (i > 0) {
a[i] = min(a[l(i)], a[r(i)]);
i = p(i);
}
}
void display() {
#ifdef debug
dout << "---------------------\n";
dout << "i = ";
rep(i, 0, 2 * pow2k) { disP(i); }
dout << endl;
dout << "a = ";
rep(i, 0, 2 * pow2k) { disP(a[i] == INF ? 999 : a[i]); }
dout << endl;
dout << "---------------------\n";
dout << endl;
#endif
}
int main() {
// cin, cout????????????
// ?????¨??????cin?????????????????¨??¨cin??§???scanf?????????????????¨??¨scanf??§??±?????????????????????
cin.tie(0); // cin??¨cout??????????????????
ios::sync_with_stdio(false); // iostream??¨stdio??????????????????
// read input data
scand(N);
int Q;
scand(Q);
//------------------------------------------------------------------------------------------
#ifdef debug
// start timer
auto startTime = chrono::system_clock::now();
#endif
//------------------------------------------------------------------------------------------
initialize();
display();
int command, x, y;
rep(i, 0, Q) {
scanf("%d%d%d", &command, &x, &y);
if (command) {
printf("%d\n", find(x, y));
} else {
update(x, y);
}
display();
}
//------------------------------------------------------------------------------------------
#ifdef debug
// stop timer
auto endTime = chrono::system_clock::now();
auto dur = endTime - startTime;
auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
dout << fixed << setprecision(4) << (double)msec / 1000 << " sec \n";
#endif
//------------------------------------------------------------------------------------------
#ifdef INPUTFILE
inputfile.close();
#endif
#ifdef OUTPUTFILE
outputfile.close();
cout << "\"" << OutputFilePath << "\"" << endl;
#endif
return 0;
}
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// ?????¢
// XCode??§???EOF??\??????Ctrl+D
// ?\???Alt+\
// ans???????§?INT?????????2,147,483,647????¶????????????¨??????????????§long
// long?????£???????????????????????????
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////
// RMQ (Range Minimum Query)
//??????????????§?????§?????????????????°???????????¨(?????¨????????¨)??§????????£?????????
////////////////////////////////////////
// #define debug
// //*******************************************************************************************************************************************
#ifdef debug
#include <chrono>
#endif
#include <algorithm> // next_permutation
#include <cmath>
#include <cstdio>
#include <cstring> //memcpy
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric> //accumulate
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// #include <map>
// #include <unordered_map> //hash func.
#include <fstream> //ifstream, ofstream
#include <iterator> //insert_iterator::inserter
#define NDEBUG // If NDEBUG is defined before #include <cassert>, assert will be
// ignored. You had better define NDEBUG when u submit the code.
#include <cassert> //assert
using namespace std;
#define dout cout
// If u wanna output to a text file instead of standard output, plz define
// OUTPUTFILE. #define OUTPUTFILE "output.txt"
// //*******************************************************************************************************************************************
#ifdef OUTPUTFILE
#define dout outputfile
ofstream outputfile(OUTPUTFILE);
#define OutputFilePath \
"/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/" \
"output.txt"
#endif
#define din cin
// If u wanna input from a text file instead of standard input, plz define
// INPUTFROMTEXTFILE???. #define INPUTFILE "input.txt"
// //*******************************************************************************************************************************************
#ifdef INPUTFILE
#define din inputfile
ifstream inputfile(INPUTFILE);
#endif
#define scand(A) scanf("%d", &(A))
#define scans(A) scanf("%s", (A))
#define disp(A) dout << #A << " = " << setw(3) << (A) << endl
#define disP(A) dout << setw(3) << (A) << " "
#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define dispAll(A, n) \
dout << #A << " = "; \
rep(j, 0, (n)) { disP(A[j]); } \
dout << endl
// #define dispAll(A,n) cout << #A << " = "; rep(j, 0, (n)) {cout << setw(3) <<
// A[j] << " ";} cout << endl
#define sign(x) ((x) > 0) - ((x) < 0) // x<0: -1, x=0: 0, x>0: +1
#define p(i) (i) / 2
#define l(i) (i) * 2
#define r(i) (i) * 2 + 1
int dx[] = {
1, -1, 0, 0, 1,
1, -1, -1}; //???????????????????????????????¨??????????????????????????????????
int dy[] = {0, 0, -1, 1, -1, 1, 1, -1};
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long ull;
const int INF = (1 << 31) - 1;
const ll INF_LL = (ll)9e18 - 1LL; // Be careful for overflow.
const ull INF_ULL = (ull)1e19 - 1ULL;
const int NONE = -1;
const ll MOD =
(ll)1e9 + 7; //??§???????´???°?????£??¨??¨????????°????????????10???7??????
const int N_MAX = 100010; // num of vertex or element
const int M_MAX = 100010; // num of edge
const int DATA_MAX = 1010;
int N;
int a[N_MAX * 3];
int k;
int pow2k;
int B = 316; // floor(sqrt(N_MAX))
int b[N_MAX]; // B+1 elements
int tmp[N_MAX];
void initialize() {
k = 0;
pow2k = 1;
while (pow2k < N) {
pow2k *= 2;
k++;
}
rep(i, 0, 2 * pow2k) { a[i] = INF; }
}
int find(int from, int to) {
#ifdef debug
dout << "------ find( " << from << ", " << to << ")\n";
#endif
assert(from <= to);
assert(to < N);
int i = from + pow2k;
int j = to + pow2k;
int ans = INF;
int limit = pow2k;
#ifdef debug
disp(i);
disp(j);
disp(limit);
disp(ans);
#endif
while (i < j and limit <= i and j < 2 * limit) {
if (i == r(p(i)))
ans = min(ans, a[i]), i = p(i) + 1;
else
i = p(i);
if (j == l(p(j)))
ans = min(ans, a[j]), j = p(j) - 1;
else
j = p(j);
limit /= 2;
#ifdef debug
dout << "--- while-loop --- \n";
disp(i);
disp(j);
disp(limit);
disp(ans);
#endif
}
if (i == j and limit <= i and j < 2 * limit) {
#ifdef debug
dout << "--- last check --- \n";
dout << "check a[" << i << "] = " << a[i] << endl;
#endif
assert(i == j);
ans = min(ans, a[i]);
}
#ifdef debug
dout << "--- FINAL --- \n";
disp(i);
disp(j);
disp(limit);
disp(ans);
#endif
return ans;
}
void update(int i, int x) {
#ifdef debug
dout << "------ update( i=" << i << ", x=" << x << ")\n";
#endif
i = i + pow2k;
a[i] = x;
i = p(i);
while (i > 0) {
a[i] = min(a[l(i)], a[r(i)]);
i = p(i);
}
}
void display() {
#ifdef debug
dout << "---------------------\n";
dout << "i = ";
rep(i, 0, 2 * pow2k) { disP(i); }
dout << endl;
dout << "a = ";
rep(i, 0, 2 * pow2k) { disP(a[i] == INF ? 999 : a[i]); }
dout << endl;
dout << "---------------------\n";
dout << endl;
#endif
}
int main() {
// cin, cout????????????
// ?????¨??????cin?????????????????¨??¨cin??§???scanf?????????????????¨??¨scanf??§??±?????????????????????
cin.tie(0); // cin??¨cout??????????????????
ios::sync_with_stdio(false); // iostream??¨stdio??????????????????
// read input data
scand(N);
int Q;
scand(Q);
//------------------------------------------------------------------------------------------
#ifdef debug
// start timer
auto startTime = chrono::system_clock::now();
#endif
//------------------------------------------------------------------------------------------
initialize();
display();
int command, x, y;
rep(i, 0, Q) {
scanf("%d%d%d", &command, &x, &y);
if (command) {
printf("%d\n", find(x, y));
} else {
update(x, y);
}
display();
}
//------------------------------------------------------------------------------------------
#ifdef debug
// stop timer
auto endTime = chrono::system_clock::now();
auto dur = endTime - startTime;
auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
dout << fixed << setprecision(4) << (double)msec / 1000 << " sec \n";
#endif
//------------------------------------------------------------------------------------------
#ifdef INPUTFILE
inputfile.close();
#endif
#ifdef OUTPUTFILE
outputfile.close();
cout << "\"" << OutputFilePath << "\"" << endl;
#endif
return 0;
}
|
replace
| 104 | 105 | 104 | 105 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
int n, dat[(1LL << 17) - 1];
void init(int _n) {
n = 1;
while (n < _n)
n *= 2;
for (int i = 0; i < n * 2 - 1; i++)
dat[i] = (1LL << 31) - 1;
}
void updata(int k, long long v) {
k += n - 1;
dat[k] = v;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
long long query(int a, int b, int k = 0, int l = 0, int r = n) {
if (r <= a || b <= l)
return (1LL << 31) - 1;
if (a <= l && r <= b)
return dat[k];
long long vl = query(a, b, 2 * k + 1, l, (l + r) / 2),
vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
int main() {
int q;
cin >> n >> q;
init(n);
while (q--) {
long long a, b, c;
cin >> a >> b >> c;
if (a) {
cout << query(b, c + 1) << endl;
} else {
updata(b, c);
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
int n, dat[10000000];
void init(int _n) {
n = 1;
while (n < _n)
n *= 2;
for (int i = 0; i < n * 2 - 1; i++)
dat[i] = (1LL << 31) - 1;
}
void updata(int k, long long v) {
k += n - 1;
dat[k] = v;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
long long query(int a, int b, int k = 0, int l = 0, int r = n) {
if (r <= a || b <= l)
return (1LL << 31) - 1;
if (a <= l && r <= b)
return dat[k];
long long vl = query(a, b, 2 * k + 1, l, (l + r) / 2),
vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
int main() {
int q;
cin >> n >> q;
init(n);
while (q--) {
long long a, b, c;
cin >> a >> b >> c;
if (a) {
cout << query(b, c + 1) << endl;
} else {
updata(b, c);
}
}
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
// Shrotening
#define fst first
#define snd second
#define pb push_back
// Loop
#define FOR(i, a, b) for (long i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (long i = (a); i >= (b); --i)
#define REP(i, a) FOR(i, 0, a)
#define RREP(i, a) RFOR(i, a, 0)
#define EACH(i, a) for (auto(i) = (a).begin(), _END = (a).end(); i != _END; ++i)
#define REACH(i, a) \
for (auto(i) = (a).rbegin(), _END = (a).rend(); i != _END; ++i)
// Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a, x) ((a).find(x) != (a).end())
#define SORT(a) sort(ALL(a))
// Setting
#define OPT \
std::cin.tie(0); \
std::ios::sync_with_stdio(false);
// debug message
bool debug = true;
#define MSG(s) \
if (debug) { \
std::cout << s << std::endl; \
}
#define DEBUG(x) \
if (debug) { \
std::cout << "debug(" << #x << "): " << x << std::endl; \
}
// alias
typedef long long LL;
typedef std::vector<int> VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::pair<int, int> PII;
template <class T> struct RMQ {
T sz;
T sq;
std::vector<T> data;
std::vector<T> bucket;
RMQ(T size) {
sq = std::ceil(std::sqrt(size));
sz = size;
data.resize(size, -1);
bucket.resize(sq, -1);
}
RMQ(T size, T init) : data(size, init) {
sq = std::ceil(std::sqrt(size));
sz = size;
data.resize(size, init);
bucket.resize(sq, init);
}
void update(T i, T x) {
data[i] = x;
T minVal = data[i];
T k = i / sq;
FOR(j, k * sq, (k + 1) * sq) { minVal = std::min(minVal, data[j]); }
bucket[k] = minVal;
}
T find(T s, T t) {
if (s == t)
return data[s];
T val = (1LL << 31) - 1;
REP(i, sq) {
T l = i * sq, r = (i + 1) * sq;
if (r <= s || t <= l) {
continue;
}
if (s <= l && r <= t) {
val = std::min(val, bucket[i]);
} else {
FOR(j, std::max(s, l), std::min(t, r) + 1) {
val = std::min(val, data[j]);
}
}
}
return val;
}
};
int main() {
int n, q, c, x, y;
std::cin >> n >> q;
RMQ<long> rmq = RMQ<long>(std::pow(n, 2), (1LL << 31) - 1);
REP(i, q) {
std::cin >> c >> x >> y;
if (c == 0) {
rmq.update(x, y);
} else {
std::cout << rmq.find(x, y) << std::endl;
}
}
}
|
#include <bits/stdc++.h>
// Shrotening
#define fst first
#define snd second
#define pb push_back
// Loop
#define FOR(i, a, b) for (long i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (long i = (a); i >= (b); --i)
#define REP(i, a) FOR(i, 0, a)
#define RREP(i, a) RFOR(i, a, 0)
#define EACH(i, a) for (auto(i) = (a).begin(), _END = (a).end(); i != _END; ++i)
#define REACH(i, a) \
for (auto(i) = (a).rbegin(), _END = (a).rend(); i != _END; ++i)
// Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a, x) ((a).find(x) != (a).end())
#define SORT(a) sort(ALL(a))
// Setting
#define OPT \
std::cin.tie(0); \
std::ios::sync_with_stdio(false);
// debug message
bool debug = true;
#define MSG(s) \
if (debug) { \
std::cout << s << std::endl; \
}
#define DEBUG(x) \
if (debug) { \
std::cout << "debug(" << #x << "): " << x << std::endl; \
}
// alias
typedef long long LL;
typedef std::vector<int> VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::pair<int, int> PII;
template <class T> struct RMQ {
T sz;
T sq;
std::vector<T> data;
std::vector<T> bucket;
RMQ(T size) {
sq = std::ceil(std::sqrt(size));
sz = size;
data.resize(size, -1);
bucket.resize(sq, -1);
}
RMQ(T size, T init) : data(size, init) {
sq = std::ceil(std::sqrt(size));
sz = size;
data.resize(size, init);
bucket.resize(sq, init);
}
void update(T i, T x) {
data[i] = x;
T minVal = data[i];
T k = i / sq;
FOR(j, k * sq, (k + 1) * sq) { minVal = std::min(minVal, data[j]); }
bucket[k] = minVal;
}
T find(T s, T t) {
if (s == t)
return data[s];
T val = (1LL << 31) - 1;
REP(i, sq) {
T l = i * sq, r = (i + 1) * sq;
if (r <= s || t <= l) {
continue;
}
if (s <= l && r <= t) {
val = std::min(val, bucket[i]);
} else {
FOR(j, std::max(s, l), std::min(t, r) + 1) {
val = std::min(val, data[j]);
}
}
}
return val;
}
};
int main() {
int n, q, c, x, y;
std::cin >> n >> q;
RMQ<long> rmq = RMQ<long>(100000, (1LL << 31) - 1);
REP(i, q) {
std::cin >> c >> x >> y;
if (c == 0) {
rmq.update(x, y);
} else {
std::cout << rmq.find(x, y) << std::endl;
}
}
}
|
replace
| 97 | 98 | 97 | 98 |
0
| |
p02345
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define rep(i, a, b) for (uint32 i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define rep(i, a, b) for (uint32 i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
template <typename Monoid, typename Operand> struct RBnode {
RBnode *ch[2], *par;
Monoid value, sum;
Operand lazy;
uint32 size, height;
bool color, reversed; // true=black
};
template <typename Monoid, typename Operand> class RBTrees {
using Node = RBnode<Monoid, Operand>;
std::vector<Node> nodes;
uint32 itr;
bool balanced;
Node *data;
public:
RBTrees(size_t maxsize) {
nodes.resize(maxsize + 1);
itr = 0;
nodes[0].ch[0] = &nodes[0];
nodes[0].ch[1] = &nodes[0];
nodes[0].par = nullptr;
nodes[0].size = 0;
nodes[0].height = 1;
nodes[0].color = 1;
}
Node *nil(void) { return &nodes[0]; }
Node *update(Node *node) {
node->sum = node->value;
if (node->ch[0] != &nodes[0]) {
node->sum = node->ch[0]->sum + node->sum;
}
if (node->ch[1] != &nodes[0]) {
node->sum = node->sum + node->ch[1]->sum;
}
node->size = node->ch[0]->size + 1 + node->ch[1]->size;
return node;
}
void push(Node *node) {
node->ch[0]->lazy = node->ch[0]->lazy * node->lazy;
node->ch[1]->lazy = node->ch[1]->lazy * node->lazy;
node->value = node->value * node->lazy;
node->sum = node->sum * node->lazy;
node->lazy.inactive();
if (node->reversed) {
node->ch[0]->reversed ^= 1;
node->ch[1]->reversed ^= 1;
std::swap(node->ch[0], node->ch[1]);
node->sum.reverse();
node->value.reverse();
node->reversed = 0;
}
return;
}
Node *rotate(Node *node, uint32 dir) {
Node *t = node->ch[dir ^ 1];
node->ch[dir ^ 1] = t->ch[dir];
t->ch[dir]->par = node;
node->height = t->ch[dir]->height;
t->height = node->height + node->color;
t->color = node->color;
node->color = 0;
t->par = node->par;
node->par = t;
t->ch[dir] = update(node);
return update(t);
}
Node *insert(Node *root, const Monoid &value, uint32 position) {
nodes[++itr].ch[0] = &nodes[0];
nodes[itr].ch[1] = &nodes[0];
nodes[itr].value = value;
nodes[itr].sum = value;
nodes[itr].lazy.inactive();
nodes[itr].size = 1;
nodes[itr].height = 1;
nodes[itr].color = 0;
nodes[itr].reversed = 0;
push(root);
root = _subins(root, position);
if (!root->color) {
root->height += 1;
root->color = 1;
}
return root;
}
Node *_subins(Node *node, uint32 pos) {
if (node == &nodes[0]) {
balanced = 1;
return &nodes[itr];
}
push(node->ch[0]);
push(node->ch[1]);
if (node->ch[0]->size < pos) {
node->ch[1] = _subins(node->ch[1], pos - node->ch[0]->size - 1);
node->ch[1]->par = node;
if (balanced) {
return _inbal(node, 1);
}
} else {
node->ch[0] = _subins(node->ch[0], pos);
node->ch[0]->par = node;
if (balanced) {
return _inbal(node, 0);
}
}
return update(node);
}
Node *_inbal(Node *node, uint32 dir) {
if (!node->color) {
push(node->ch[dir ^ 1]);
return update(node);
}
if (!node->ch[dir ^ 1]->color) {
if (node->ch[dir]->ch[dir]->color && node->ch[dir]->ch[dir ^ 1]->color) {
balanced = 0;
return update(node);
}
return flip(update(node));
}
balanced = 0;
if (!node->ch[dir]->ch[dir ^ 1]->color) {
node->ch[dir] = rotate(node->ch[dir], dir);
}
if (node->ch[dir]->ch[dir]->color) {
return update(node);
}
return rotate(node, dir ^ 1);
}
Node *flip(Node *node) {
node->ch[0]->color = 1;
node->ch[0]->height += 1;
node->ch[1]->color = 1;
node->ch[1]->height += 1;
node->color = 0;
return node;
}
Node *access(Node *root, uint32 position) {
while (1) {
if (position > root->ch[0]->size) {
position -= root->ch[0]->size + 1;
root = root->ch[1];
} else if (position < root->ch[0]->size) {
root = root->ch[0];
} else {
return root;
}
}
}
Node *erase(Node *root, uint32 position) {
push(root);
if (root->ch[0]->size > position) {
root->ch[0] = erase(root->ch[0], position);
if (balanced) {
return _erbal(update(root), 0);
}
return update(root);
} else if (root->ch[0]->size < position) {
root->ch[1] = erase(root->ch[1], position - root->ch[0]->size - 1);
if (balanced) {
return _erbal(update(root), 1);
}
return update(root);
}
if (root->ch[0] != &nodes[0]) {
if (root->ch[1] != &nodes[0]) {
root->ch[1] = erase(root->ch[1], 0);
root->value = data->value;
if (balanced) {
return _erbal(update(root), 1);
}
return update(root);
}
root->ch[0]->par = root->par;
root->ch[0]->color = 1;
++root->ch[0]->height;
balanced = 0;
return root->ch[0];
} else {
data = root;
if (root->ch[1] != &nodes[0]) {
root->ch[1]->par = root->par;
root->ch[1]->color = 1;
++root->ch[1]->height;
balanced = 0;
return root->ch[1];
}
balanced = root->color;
return &nodes[0];
}
}
Node *_erbal(Node *node, uint32 dir) {
if (node->ch[dir ^ 1]->ch[0]->color && node->ch[dir ^ 1]->ch[1]->color) {
node->height = node->ch[dir ^ 1]->height + node->color;
if (node->ch[dir ^ 1]->color) {
if (node->color) {
node->ch[dir ^ 1]->color = 0;
node->ch[dir ^ 1]->height -= 1;
node->height -= 1;
return node;
}
node->ch[dir ^ 1]->color = 0;
node->ch[dir ^ 1]->height -= 1;
node->color = 1;
balanced = 0;
return node;
}
node = rotate(node, dir);
node->ch[dir] = _erbal(node->ch[dir], dir);
node->height = node->ch[dir]->height + node->color;
return node;
}
balanced = 0;
if (node->ch[dir ^ 1]->ch[dir ^ 1]->color) {
node->ch[dir ^ 1] = rotate(node->ch[dir ^ 1], dir ^ 1);
}
node = rotate(node, dir);
++node->height;
++node->ch[0]->height;
node->ch[0]->color = 1;
++node->ch[1]->height;
node->ch[1]->color = 1;
return node;
}
Monoid range(Node *root, uint32 begin, uint32 end) {
Node *t = root;
Monoid ret;
while (1) {
if (t->ch[0]->size < begin) {
begin -= t->ch[0]->size + 1;
end -= t->ch[0]->size + 1;
t = t->ch[1];
continue;
}
if (t->ch[0]->size < end) {
end -= t->ch[0]->size + 1;
ret = t->value;
root = t->ch[0];
t = t->ch[1];
break;
}
t = t->ch[0];
}
while (root != &nodes[0]) {
if (root->ch[0]->size < begin) {
begin -= root->ch[0]->size + 1;
root = root->ch[1];
continue;
}
if (root->ch[1] != &nodes[0])
ret = (root->value + root->ch[1]->sum) + ret;
else
ret = root->value + ret;
root = root->ch[0];
}
while (t != &nodes[0]) {
if (t->ch[0]->size < end) {
end -= t->ch[0]->size + 1;
if (t->ch[0] != &nodes[0])
ret = ret + (t->ch[0]->sum + t->value);
else
ret = ret + t->value;
t = t->ch[1];
continue;
}
t = t->ch[0];
}
return ret;
}
void show(Node *node) {
std::cout << "(";
if (node->ch[0] != &nodes[0]) {
show(node->ch[0]);
std::cout << "←";
}
std::cout << node->value.e << " " << node->color << " " << node->height;
if (node->ch[1] != &nodes[0]) {
std::cout << "→";
show(node->ch[1]);
}
std::cout << ")";
return;
}
void check(Node *node) {
if (node->ch[0] != &nodes[0]) {
if (node->ch[0]->par != node)
std::cerr << "#\n";
check(node->ch[0]);
}
if (node->ch[1] != &nodes[0]) {
if (node->ch[1]->par != node)
std::cerr << "#\n";
check(node->ch[1]);
}
}
};
struct SUB {
int32 e;
bool a;
SUB() { set(); }
SUB(int32 x, bool y) {
e = x;
a = y;
}
void set() { a = false; }
void inactive(void) { a = false; }
SUB operator*(const SUB &other) {
if (other.a)
return other;
return *this;
}
};
struct MIN {
int32 e;
MIN() { set(); }
MIN(int32 x) { e = x; }
void set() { e = 2147483647; }
void reverse(void) {}
MIN operator+(const MIN &other) {
if (e < other.e)
return *this;
return other;
};
MIN operator*(const SUB &other) {
if (other.a)
return MIN(other.e);
return *this;
}
};
int main(void) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
uint32 n, q;
std::cin >> n >> q;
RBTrees<MIN, SUB> T(n + q);
RBnode<MIN, SUB> *r = T.nil();
int64 com, y;
uint32 x;
rep(i, 0, n) {
r = T.insert(r, MIN(2147483647), 0);
T.check(r);
}
// T.show(r);std::cout << "\n";T.check(r);
rep(i, 0, q) {
std::cin >> com >> x >> y;
if (com == 0) {
r = T.erase(r, x);
// T.show(r);std::cout << "\n";
// T.check(r);
r = T.insert(r, MIN(y), x);
// T.show(r);std::cout << "\n";
// T.check(r);
} else {
std::cout << T.range(r, x, y + 1).e << "\n";
}
}
return 0;
}
|
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define rep(i, a, b) for (uint32 i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define rep(i, a, b) for (uint32 i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
template <typename Monoid, typename Operand> struct RBnode {
RBnode *ch[2], *par;
Monoid value, sum;
Operand lazy;
uint32 size, height;
bool color, reversed; // true=black
};
template <typename Monoid, typename Operand> class RBTrees {
using Node = RBnode<Monoid, Operand>;
std::vector<Node> nodes;
uint32 itr;
bool balanced;
Node *data;
public:
RBTrees(size_t maxsize) {
nodes.resize(maxsize + 1);
itr = 0;
nodes[0].ch[0] = &nodes[0];
nodes[0].ch[1] = &nodes[0];
nodes[0].par = nullptr;
nodes[0].size = 0;
nodes[0].height = 1;
nodes[0].color = 1;
}
Node *nil(void) { return &nodes[0]; }
Node *update(Node *node) {
node->sum = node->value;
if (node->ch[0] != &nodes[0]) {
node->sum = node->ch[0]->sum + node->sum;
}
if (node->ch[1] != &nodes[0]) {
node->sum = node->sum + node->ch[1]->sum;
}
node->size = node->ch[0]->size + 1 + node->ch[1]->size;
return node;
}
void push(Node *node) {
node->ch[0]->lazy = node->ch[0]->lazy * node->lazy;
node->ch[1]->lazy = node->ch[1]->lazy * node->lazy;
node->value = node->value * node->lazy;
node->sum = node->sum * node->lazy;
node->lazy.inactive();
if (node->reversed) {
node->ch[0]->reversed ^= 1;
node->ch[1]->reversed ^= 1;
std::swap(node->ch[0], node->ch[1]);
node->sum.reverse();
node->value.reverse();
node->reversed = 0;
}
return;
}
Node *rotate(Node *node, uint32 dir) {
Node *t = node->ch[dir ^ 1];
node->ch[dir ^ 1] = t->ch[dir];
t->ch[dir]->par = node;
node->height = t->ch[dir]->height;
t->height = node->height + node->color;
t->color = node->color;
node->color = 0;
t->par = node->par;
node->par = t;
t->ch[dir] = update(node);
return update(t);
}
Node *insert(Node *root, const Monoid &value, uint32 position) {
nodes[++itr].ch[0] = &nodes[0];
nodes[itr].ch[1] = &nodes[0];
nodes[itr].value = value;
nodes[itr].sum = value;
nodes[itr].lazy.inactive();
nodes[itr].size = 1;
nodes[itr].height = 1;
nodes[itr].color = 0;
nodes[itr].reversed = 0;
push(root);
root = _subins(root, position);
if (!root->color) {
root->height += 1;
root->color = 1;
}
return root;
}
Node *_subins(Node *node, uint32 pos) {
if (node == &nodes[0]) {
balanced = 1;
return &nodes[itr];
}
push(node->ch[0]);
push(node->ch[1]);
if (node->ch[0]->size < pos) {
node->ch[1] = _subins(node->ch[1], pos - node->ch[0]->size - 1);
node->ch[1]->par = node;
if (balanced) {
return _inbal(node, 1);
}
} else {
node->ch[0] = _subins(node->ch[0], pos);
node->ch[0]->par = node;
if (balanced) {
return _inbal(node, 0);
}
}
return update(node);
}
Node *_inbal(Node *node, uint32 dir) {
if (!node->color) {
push(node->ch[dir ^ 1]);
return update(node);
}
if (!node->ch[dir ^ 1]->color) {
if (node->ch[dir]->ch[dir]->color && node->ch[dir]->ch[dir ^ 1]->color) {
balanced = 0;
return update(node);
}
return flip(update(node));
}
balanced = 0;
if (!node->ch[dir]->ch[dir ^ 1]->color) {
node->ch[dir] = rotate(node->ch[dir], dir);
}
if (node->ch[dir]->ch[dir]->color) {
return update(node);
}
return rotate(node, dir ^ 1);
}
Node *flip(Node *node) {
node->ch[0]->color = 1;
node->ch[0]->height += 1;
node->ch[1]->color = 1;
node->ch[1]->height += 1;
node->color = 0;
return node;
}
Node *access(Node *root, uint32 position) {
while (1) {
if (position > root->ch[0]->size) {
position -= root->ch[0]->size + 1;
root = root->ch[1];
} else if (position < root->ch[0]->size) {
root = root->ch[0];
} else {
return root;
}
}
}
Node *erase(Node *root, uint32 position) {
push(root);
if (root->ch[0]->size > position) {
root->ch[0] = erase(root->ch[0], position);
if (balanced) {
return _erbal(update(root), 0);
}
return update(root);
} else if (root->ch[0]->size < position) {
root->ch[1] = erase(root->ch[1], position - root->ch[0]->size - 1);
if (balanced) {
return _erbal(update(root), 1);
}
return update(root);
}
if (root->ch[0] != &nodes[0]) {
if (root->ch[1] != &nodes[0]) {
root->ch[1] = erase(root->ch[1], 0);
root->value = data->value;
if (balanced) {
return _erbal(update(root), 1);
}
return update(root);
}
root->ch[0]->par = root->par;
root->ch[0]->color = 1;
++root->ch[0]->height;
balanced = 0;
return root->ch[0];
} else {
data = root;
if (root->ch[1] != &nodes[0]) {
root->ch[1]->par = root->par;
root->ch[1]->color = 1;
++root->ch[1]->height;
balanced = 0;
return root->ch[1];
}
balanced = root->color;
return &nodes[0];
}
}
Node *_erbal(Node *node, uint32 dir) {
if (node->ch[dir ^ 1]->ch[0]->color && node->ch[dir ^ 1]->ch[1]->color) {
node->height = node->ch[dir ^ 1]->height + node->color;
if (node->ch[dir ^ 1]->color) {
if (node->color) {
node->ch[dir ^ 1]->color = 0;
node->ch[dir ^ 1]->height -= 1;
node->height -= 1;
return node;
}
node->ch[dir ^ 1]->color = 0;
node->ch[dir ^ 1]->height -= 1;
node->color = 1;
balanced = 0;
return node;
}
node = rotate(node, dir);
node->ch[dir] = _erbal(node->ch[dir], dir);
node->height = node->ch[dir]->height + node->color;
return node;
}
balanced = 0;
if (node->ch[dir ^ 1]->ch[dir ^ 1]->color) {
node->ch[dir ^ 1] = rotate(node->ch[dir ^ 1], dir ^ 1);
}
node = rotate(node, dir);
++node->height;
++node->ch[0]->height;
node->ch[0]->color = 1;
++node->ch[1]->height;
node->ch[1]->color = 1;
return node;
}
Monoid range(Node *root, uint32 begin, uint32 end) {
Node *t = root;
Monoid ret;
while (1) {
if (t->ch[0]->size < begin) {
begin -= t->ch[0]->size + 1;
end -= t->ch[0]->size + 1;
t = t->ch[1];
continue;
}
if (t->ch[0]->size < end) {
end -= t->ch[0]->size + 1;
ret = t->value;
root = t->ch[0];
t = t->ch[1];
break;
}
t = t->ch[0];
}
while (root != &nodes[0]) {
if (root->ch[0]->size < begin) {
begin -= root->ch[0]->size + 1;
root = root->ch[1];
continue;
}
if (root->ch[1] != &nodes[0])
ret = (root->value + root->ch[1]->sum) + ret;
else
ret = root->value + ret;
root = root->ch[0];
}
while (t != &nodes[0]) {
if (t->ch[0]->size < end) {
end -= t->ch[0]->size + 1;
if (t->ch[0] != &nodes[0])
ret = ret + (t->ch[0]->sum + t->value);
else
ret = ret + t->value;
t = t->ch[1];
continue;
}
t = t->ch[0];
}
return ret;
}
void show(Node *node) {
std::cout << "(";
if (node->ch[0] != &nodes[0]) {
show(node->ch[0]);
std::cout << "←";
}
std::cout << node->value.e << " " << node->color << " " << node->height;
if (node->ch[1] != &nodes[0]) {
std::cout << "→";
show(node->ch[1]);
}
std::cout << ")";
return;
}
void check(Node *node) {
if (node->ch[0] != &nodes[0]) {
if (node->ch[0]->par != node)
std::cerr << "#\n";
check(node->ch[0]);
}
if (node->ch[1] != &nodes[0]) {
if (node->ch[1]->par != node)
std::cerr << "#\n";
check(node->ch[1]);
}
}
};
struct SUB {
int32 e;
bool a;
SUB() { set(); }
SUB(int32 x, bool y) {
e = x;
a = y;
}
void set() { a = false; }
void inactive(void) { a = false; }
SUB operator*(const SUB &other) {
if (other.a)
return other;
return *this;
}
};
struct MIN {
int32 e;
MIN() { set(); }
MIN(int32 x) { e = x; }
void set() { e = 2147483647; }
void reverse(void) {}
MIN operator+(const MIN &other) {
if (e < other.e)
return *this;
return other;
};
MIN operator*(const SUB &other) {
if (other.a)
return MIN(other.e);
return *this;
}
};
int main(void) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
uint32 n, q;
std::cin >> n >> q;
RBTrees<MIN, SUB> T(n + q);
RBnode<MIN, SUB> *r = T.nil();
int64 com, y;
uint32 x;
rep(i, 0, n) { r = T.insert(r, MIN(2147483647), 0); }
// T.show(r);std::cout << "\n";T.check(r);
rep(i, 0, q) {
std::cin >> com >> x >> y;
if (com == 0) {
r = T.erase(r, x);
// T.show(r);std::cout << "\n";
// T.check(r);
r = T.insert(r, MIN(y), x);
// T.show(r);std::cout << "\n";
// T.check(r);
} else {
std::cout << T.range(r, x, y + 1).e << "\n";
}
}
return 0;
}
|
replace
| 394 | 398 | 394 | 395 |
TLE
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;
#include <map>
#include <queue>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
// const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);
// segtree
// memeory error??
const int MAX_N = 100000; // 1 << 20; // > 10^6
class SegTree {
public:
int n;
int dat[2 * MAX_N - 1];
int dummy = 2147483647; // (1 << 31) - 1;
SegTree(int _n) { init(_n); }
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
// initialize
rep(i, 2 * n - 1) dat[i] = dummy;
}
void update(int k, int a) {
// update from bottom
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// min of [a, b)
int query(int a, int b) { return _query(a, b, 0, 0, n); }
// min of [a, b)
// node k, corresponding [l, r)
int _query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return dummy;
if (a <= l && r <= b)
return dat[k];
else {
int vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
};
int N, Q;
int main() {
cin >> N >> Q;
SegTree ST(N);
rep(q, Q) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0) {
// update
ST.update(x, y);
} else {
// find
cout << ST.query(x, y + 1) << endl;
}
}
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;
#include <map>
#include <queue>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
// const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);
// segtree
// memeory error??
const int MAX_N = 200000; // 1 << 20; // > 10^6
class SegTree {
public:
int n;
int dat[2 * MAX_N - 1];
int dummy = 2147483647; // (1 << 31) - 1;
SegTree(int _n) { init(_n); }
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
// initialize
rep(i, 2 * n - 1) dat[i] = dummy;
}
void update(int k, int a) {
// update from bottom
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// min of [a, b)
int query(int a, int b) { return _query(a, b, 0, 0, n); }
// min of [a, b)
// node k, corresponding [l, r)
int _query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return dummy;
if (a <= l && r <= b)
return dat[k];
else {
int vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
};
int N, Q;
int main() {
cin >> N >> Q;
SegTree ST(N);
rep(q, Q) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0) {
// update
ST.update(x, y);
} else {
// find
cout << ST.query(x, y + 1) << endl;
}
}
}
|
replace
| 30 | 31 | 30 | 31 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define inf (2147483647)
#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define MAX_N 100010
using namespace std;
template <class T> class RMQ {
private:
int n;
T dat[2 * MAX_N - 1];
public:
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = inf; //
}
// k????????????(0-indexed)???a????????卒
void update(int k, T a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
T query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return inf;
else if (a <= l && r <= b)
return dat[k];
T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
// n???????????則?????????????????????????\?????????贈???????????即
T _query(int a, int b) { return query(a, b, 0, 0, n); }
};
int main() {
int n, q, com, x, y;
// scanf("%d%d",&n,&q);
cin >> n >> q;
RMQ<int> rmq;
rmq.init(n + 1);
rep(i, q) {
// scanf("%d%d%d",&com,&x,&y);
cin >> com >> x >> y;
if (com == 0)
rmq.update(x, y);
else
cout << rmq._query(x, y + 1) << endl;
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define inf (2147483647)
#define EPS 1e-10
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define MAX_N 500010
using namespace std;
template <class T> class RMQ {
private:
int n;
T dat[2 * MAX_N - 1];
public:
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = inf; //
}
// k????????????(0-indexed)???a????????卒
void update(int k, T a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
T query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return inf;
else if (a <= l && r <= b)
return dat[k];
T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
// n???????????則?????????????????????????\?????????贈???????????即
T _query(int a, int b) { return query(a, b, 0, 0, n); }
};
int main() {
int n, q, com, x, y;
// scanf("%d%d",&n,&q);
cin >> n >> q;
RMQ<int> rmq;
rmq.init(n + 1);
rep(i, q) {
// scanf("%d%d%d",&com,&x,&y);
cin >> com >> x >> y;
if (com == 0)
rmq.update(x, y);
else
cout << rmq._query(x, y + 1) << endl;
}
return 0;
}
|
replace
| 23 | 24 | 23 | 24 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
const int INF = (1LL << 31) - 1;
struct SegmentTree {
int n;
vector<int> v;
SegmentTree(int n_, int x) : v(n_ * 4) {
for (int i = 0; (1 << i) <= n_; ++i, n = 1 << i)
;
for (int i = 0; i < n * 4; ++i)
v[i] = x;
}
void set(int i, int x) {
i += n - 1;
v[i] = x;
for (; i > 0;) {
i = (i - 1) / 2;
v[i] = min(v[2 * i + 1], v[2 * i + 2]);
}
}
int find(int l, int r) { return find(l, r, 0, 0, n); }
int find(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b) {
return v[k];
} else {
int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
};
int main() {
int n, q;
scanf("%d %d", &n, &q);
SegmentTree st(n, INF);
for (int i = 0; i < q; ++i) {
// for (int i = 0; i < st.n * 2 - 1; ++i) printf(" %d", st.v[i]); puts("");
int c, x, y;
scanf("%d %d %d", &c, &x, &y);
if (c == 0) {
st.set(x, y);
} else /*if (c == 1)*/ {
printf("%d\n", st.find(x, y + 1));
}
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
const int INF = (1LL << 31) - 1;
struct SegmentTree {
int n;
vector<int> v;
SegmentTree(int n_, int x) : v(n_ * 4) {
for (int i = 0; (1 << i) <= n_; ++i, n = 1 << i)
;
for (int i = 0; i < n_ * 4; ++i)
v[i] = x;
}
void set(int i, int x) {
i += n - 1;
v[i] = x;
for (; i > 0;) {
i = (i - 1) / 2;
v[i] = min(v[2 * i + 1], v[2 * i + 2]);
}
}
int find(int l, int r) { return find(l, r, 0, 0, n); }
int find(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b) {
return v[k];
} else {
int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
};
int main() {
int n, q;
scanf("%d %d", &n, &q);
SegmentTree st(n, INF);
for (int i = 0; i < q; ++i) {
// for (int i = 0; i < st.n * 2 - 1; ++i) printf(" %d", st.v[i]); puts("");
int c, x, y;
scanf("%d %d %d", &c, &x, &y);
if (c == 0) {
st.set(x, y);
} else /*if (c == 1)*/ {
printf("%d\n", st.find(x, y + 1));
}
}
return 0;
}
|
replace
| 14 | 15 | 14 | 15 |
-6
|
malloc(): corrupted top size
|
p02345
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
//---------------------------------------------------------------------------------------------------
typedef int V;
// NV=3010101 -> 38MB
#define NV 6010101
#define def 2147483647
struct PersistentSegmentTree { //[L,R)
V comp(V a, V b) { return min(a, b); }
// -- template ---------------------
struct S {
int l, r;
V x;
} v[NV];
int cnt = 1, n = -1;
void init(int _n) {
n = _n;
rep(i, 0, NV) v[i].l = v[i].r = 0, v[i].x = def;
}
void add(int &root, int l, int r, int i, int val) {
v[cnt] = v[root];
root = cnt++;
if (l + 1 == r) {
v[root].x += val;
return;
}
int mi = (l + r) / 2;
if (i < mi)
add(v[root].l, l, mi, i, val);
else
add(v[root].r, mi, r, i, val);
v[root].x = comp(v[v[root].l].x, v[v[root].r].x);
}
void add(int &root, int i, int val) {
assert(0 < n);
add(root, 0, n, i, val);
}
void update(int &root, int l, int r, int i, int val) {
v[cnt] = v[root];
root = cnt++;
if (l + 1 == r) {
v[root].x = val;
return;
}
int mi = (l + r) / 2;
if (i < mi)
update(v[root].l, l, mi, i, val);
else
update(v[root].r, mi, r, i, val);
v[root].x = comp(v[v[root].l].x, v[v[root].r].x);
}
void update(int &root, int i, int val) {
assert(0 < n);
update(root, 0, n, i, val);
}
int query(int a, int b, int l, int r, int k) {
assert(0 < n);
if (v[b].x - v[a].x < k)
return -2;
if (l + 1 == r)
return l;
int mi = (l + r) / 2;
int re = query(v[a].l, v[b].l, l, mi, k); // v[0] always 0
if (re < 0)
re = query(v[a].r, v[b].r, mi, r, k);
return re;
}
int allget(int root) { return v[root].x; }
// todo
int get(int root, int l, int r, int L, int R) {
if (l >= r)
return def;
if (l == L && r == R)
return v[root].x;
int mi = (L + R) / 2;
V le = get(v[root].l, max(l, L), min(r, mi), L, mi);
V ri = get(v[root].r, max(l, mi), min(r, R), mi, R);
return comp(le, ri);
}
int get(int root, int l, int r) { return get(root, l, r, 0, n); }
};
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i
?????????????????????????????? ??? |???|
????????? /?????? /??£??£??£??£/??????|
??? ???_(__??????/??? ???/ .| .|????????????
??? ????????????/????????????/??????u??????
---------------------------------------------------------------------------------------------------*/
int N, Q;
PersistentSegmentTree pst;
int root = 0;
//---------------------------------------------------------------------------------------------------
void _main() {
pst.init(101010);
cin >> N >> Q;
rep(_, 0, Q) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0)
pst.update(root, x, y);
else
printf("%d\n", pst.get(root, x, y + 1));
}
}
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
//---------------------------------------------------------------------------------------------------
typedef int V;
// NV=3010101 -> 38MB
#define NV 3010101
#define def 2147483647
struct PersistentSegmentTree { //[L,R)
V comp(V a, V b) { return min(a, b); }
// -- template ---------------------
struct S {
int l, r;
V x;
} v[NV];
int cnt = 1, n = -1;
void init(int _n) {
n = _n;
rep(i, 0, NV) v[i].l = v[i].r = 0, v[i].x = def;
}
void add(int &root, int l, int r, int i, int val) {
v[cnt] = v[root];
root = cnt++;
if (l + 1 == r) {
v[root].x += val;
return;
}
int mi = (l + r) / 2;
if (i < mi)
add(v[root].l, l, mi, i, val);
else
add(v[root].r, mi, r, i, val);
v[root].x = comp(v[v[root].l].x, v[v[root].r].x);
}
void add(int &root, int i, int val) {
assert(0 < n);
add(root, 0, n, i, val);
}
void update(int &root, int l, int r, int i, int val) {
v[cnt] = v[root];
root = cnt++;
if (l + 1 == r) {
v[root].x = val;
return;
}
int mi = (l + r) / 2;
if (i < mi)
update(v[root].l, l, mi, i, val);
else
update(v[root].r, mi, r, i, val);
v[root].x = comp(v[v[root].l].x, v[v[root].r].x);
}
void update(int &root, int i, int val) {
assert(0 < n);
update(root, 0, n, i, val);
}
int query(int a, int b, int l, int r, int k) {
assert(0 < n);
if (v[b].x - v[a].x < k)
return -2;
if (l + 1 == r)
return l;
int mi = (l + r) / 2;
int re = query(v[a].l, v[b].l, l, mi, k); // v[0] always 0
if (re < 0)
re = query(v[a].r, v[b].r, mi, r, k);
return re;
}
int allget(int root) { return v[root].x; }
// todo
int get(int root, int l, int r, int L, int R) {
if (l >= r)
return def;
if (l == L && r == R)
return v[root].x;
int mi = (L + R) / 2;
V le = get(v[root].l, max(l, L), min(r, mi), L, mi);
V ri = get(v[root].r, max(l, mi), min(r, R), mi, R);
return comp(le, ri);
}
int get(int root, int l, int r) { return get(root, l, r, 0, n); }
};
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i
?????????????????????????????? ??? |???|
????????? /?????? /??£??£??£??£/??????|
??? ???_(__??????/??? ???/ .| .|????????????
??? ????????????/????????????/??????u??????
---------------------------------------------------------------------------------------------------*/
int N, Q;
PersistentSegmentTree pst;
int root = 0;
//---------------------------------------------------------------------------------------------------
void _main() {
pst.init(101010);
cin >> N >> Q;
rep(_, 0, Q) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0)
pst.update(root, x, y);
else
printf("%d\n", pst.get(root, x, y + 1));
}
}
|
replace
| 15 | 16 | 15 | 16 |
MLE
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
template <class T> struct treap {
#define treapInf INT_MAX
public:
struct node {
T val;
node *lch, *rch;
int pri, sz;
T sum, mini;
node(T val, int pri) : val(val), pri(pri), sz(1), sum(val), mini(val) {
lch = rch = NULL;
}
};
node *root;
treap() : root(NULL) { srand(time(NULL)); }
private:
inline int size(node *t) { return !t ? 0 : t->sz; }
inline T sum(node *t) { return !t ? 0 : t->sum; }
inline T mini(node *t) { return !t ? treapInf : t->mini; }
node *update(node *t) {
// if(!t)return;
t->sz = size(t->lch) + size(t->rch) + 1;
t->sum = sum(t->lch) + sum(t->rch) + t->val;
t->mini = min(min(mini(t->lch), mini(t->rch)), t->val);
return t;
}
node *merge(node *l, node *r) {
if (!l || !r)
return l ? l : r;
if (l->pri > r->pri) {
l->rch = merge(l->rch, r);
return update(l);
} else {
r->lch = merge(l, r->lch);
return update(r);
}
}
pair<node *, node *> split(node *t, int k) {
if (!t)
return make_pair((node *)NULL, (node *)NULL);
if (k <= size(t->lch)) {
pair<node *, node *> s = split(t->lch, k);
t->lch = s.second;
return make_pair(s.first, update(t));
} else {
pair<node *, node *> s = split(t->rch, k - size(t->lch) - 1);
t->rch = s.first;
return make_pair(update(t), s.second);
}
}
node *insert(node *t, int k, T val, int pri) {
pair<node *, node *> s = split(t, k);
t = merge(s.first, new node(val, pri));
t = merge(t, s.second);
return update(t);
}
node *erase(node *t, int k) {
pair<node *, node *> s1, s2;
s2 = split(t, k + 1);
s1 = split(s2.first, k);
return update(t = merge(s1.first, s2.second));
}
node *find(node *t, int k) {
// if(!t)return t;
int c = count(t->lch);
if (k < c)
return find(t->lch, k);
if (k == c)
return t;
return find(t->rch, k - c - 1);
}
T rangeMinimumQuery(int l, int r, node *t) {
int sz = size(t);
if (r <= 0 || sz <= l)
return treapInf;
if (l <= 0 && sz <= r)
return mini(t);
sz = size(t->lch);
T vl = rangeMinimumQuery(l, r, t->lch);
T vr = rangeMinimumQuery(l - sz - 1, r - sz - 1, t->rch);
T res = min(vl, vr);
if (l <= sz && sz < r)
res = min(res, t->val);
return res;
}
T rangeSumQuery(int l, int r, node *t) {
int sz = size(t);
if (r <= 0 || sz <= l)
return 0;
if (l <= 0 && sz <= r)
return sum(t);
sz = size(t->lch);
T vl = rangeSumQuery(l, r, t->lch);
T vr = rangeSumQuery(l - sz - 1, r - sz - 1, t->rch);
T res = vl + vr;
if (l <= sz && sz < r)
res += t->val;
return res;
}
public:
void insert(int k, T val) { root = insert(root, k, val, rand()); }
void erase(int k) { root = erase(root, k); }
node *find(int k) { return find(root, k); }
void add(int k, T v) {
node *a = find(k);
T tmp = a->val;
erase(k);
insert(k, tmp + v);
}
void update(int k, T v) {
erase(k);
insert(k, v);
}
T rangeMinimumQuery(int l, int r) { return rangeMinimumQuery(l, r, root); }
T rangeSumQuery(int l, int r) { return rangeSumQuery(l, r, root); }
};
int main() {
int n, q;
cin >> n >> q;
treap<int> t;
for (int i = 0; i < n; i++)
t.insert(i, INT_MAX);
int type, x, y;
while (q--) {
cin >> type >> x >> y;
if (type == 0) {
t.update(x, y);
} else {
cout << t.rangeMinimumQuery(x, y + 1) << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T> struct treap {
#define treapInf INT_MAX
public:
struct node {
T val;
node *lch, *rch;
int pri, sz;
T sum, mini;
node(T val, int pri) : val(val), pri(pri), sz(1), sum(val), mini(val) {
lch = rch = NULL;
}
};
node *root;
treap() : root(NULL) { srand(time(NULL)); }
private:
inline int size(node *t) { return !t ? 0 : t->sz; }
inline T sum(node *t) { return !t ? 0 : t->sum; }
inline T mini(node *t) { return !t ? treapInf : t->mini; }
node *update(node *t) {
if (!t)
return t;
t->sz = size(t->lch) + size(t->rch) + 1;
t->sum = sum(t->lch) + sum(t->rch) + t->val;
t->mini = min(min(mini(t->lch), mini(t->rch)), t->val);
return t;
}
node *merge(node *l, node *r) {
if (!l || !r)
return l ? l : r;
if (l->pri > r->pri) {
l->rch = merge(l->rch, r);
return update(l);
} else {
r->lch = merge(l, r->lch);
return update(r);
}
}
pair<node *, node *> split(node *t, int k) {
if (!t)
return make_pair((node *)NULL, (node *)NULL);
if (k <= size(t->lch)) {
pair<node *, node *> s = split(t->lch, k);
t->lch = s.second;
return make_pair(s.first, update(t));
} else {
pair<node *, node *> s = split(t->rch, k - size(t->lch) - 1);
t->rch = s.first;
return make_pair(update(t), s.second);
}
}
node *insert(node *t, int k, T val, int pri) {
pair<node *, node *> s = split(t, k);
t = merge(s.first, new node(val, pri));
t = merge(t, s.second);
return update(t);
}
node *erase(node *t, int k) {
pair<node *, node *> s1, s2;
s2 = split(t, k + 1);
s1 = split(s2.first, k);
return update(t = merge(s1.first, s2.second));
}
node *find(node *t, int k) {
// if(!t)return t;
int c = count(t->lch);
if (k < c)
return find(t->lch, k);
if (k == c)
return t;
return find(t->rch, k - c - 1);
}
T rangeMinimumQuery(int l, int r, node *t) {
int sz = size(t);
if (r <= 0 || sz <= l)
return treapInf;
if (l <= 0 && sz <= r)
return mini(t);
sz = size(t->lch);
T vl = rangeMinimumQuery(l, r, t->lch);
T vr = rangeMinimumQuery(l - sz - 1, r - sz - 1, t->rch);
T res = min(vl, vr);
if (l <= sz && sz < r)
res = min(res, t->val);
return res;
}
T rangeSumQuery(int l, int r, node *t) {
int sz = size(t);
if (r <= 0 || sz <= l)
return 0;
if (l <= 0 && sz <= r)
return sum(t);
sz = size(t->lch);
T vl = rangeSumQuery(l, r, t->lch);
T vr = rangeSumQuery(l - sz - 1, r - sz - 1, t->rch);
T res = vl + vr;
if (l <= sz && sz < r)
res += t->val;
return res;
}
public:
void insert(int k, T val) { root = insert(root, k, val, rand()); }
void erase(int k) { root = erase(root, k); }
node *find(int k) { return find(root, k); }
void add(int k, T v) {
node *a = find(k);
T tmp = a->val;
erase(k);
insert(k, tmp + v);
}
void update(int k, T v) {
erase(k);
insert(k, v);
}
T rangeMinimumQuery(int l, int r) { return rangeMinimumQuery(l, r, root); }
T rangeSumQuery(int l, int r) { return rangeSumQuery(l, r, root); }
};
int main() {
int n, q;
cin >> n >> q;
treap<int> t;
for (int i = 0; i < n; i++)
t.insert(i, INT_MAX);
int type, x, y;
while (q--) {
cin >> type >> x >> y;
if (type == 0) {
t.update(x, y);
} else {
cout << t.rangeMinimumQuery(x, y + 1) << endl;
}
}
return 0;
}
|
replace
| 27 | 28 | 27 | 29 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;
#define NUM 2147483647
int N;
int *table;
void init(int first_N) {
while (N < first_N)
N *= 2;
}
void update(int loc, int value) {
loc += N - 1;
table[loc] = value;
if (N == 1)
return;
int parent = (loc - 1) / 2;
while (true) {
table[parent] = min(table[2 * parent + 1], table[2 * parent + 2]);
if (parent == 0)
break;
else {
parent = (parent - 1) / 2;
}
}
}
int query(int search_left, int search_right, int node_id, int node_left,
int node_right) {
if (search_right < node_left || search_left > node_right)
return NUM;
if (search_left <= node_left && search_right >= node_right) {
return table[node_id];
}
int left_min = query(search_left, search_right, 2 * node_id + 1, node_left,
(node_left + node_right) / 2);
int right_min = query(search_left, search_right, 2 * node_id + 2,
(node_left + node_right) / 2 + 1, node_right);
return min(left_min, right_min);
}
int main() {
int first_N, Q, command, left, right;
table = new int[250000];
N = 1;
scanf("%d %d", &first_N, &Q);
init(first_N);
for (int i = 0; i <= 2 * N - 2; i++)
table[i] = NUM;
for (int i = 0; i < Q; i++) {
scanf("%d %d %d", &command, &left, &right);
if (command == 0) {
update(left, right);
} else {
printf("%d\n", query(left, right, 0, 0, N - 1));
}
}
return 0;
}
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;
#define NUM 2147483647
int N;
int *table;
void init(int first_N) {
while (N < first_N)
N *= 2;
}
void update(int loc, int value) {
loc += N - 1;
table[loc] = value;
if (N == 1)
return;
int parent = (loc - 1) / 2;
while (true) {
table[parent] = min(table[2 * parent + 1], table[2 * parent + 2]);
if (parent == 0)
break;
else {
parent = (parent - 1) / 2;
}
}
}
int query(int search_left, int search_right, int node_id, int node_left,
int node_right) {
if (search_right < node_left || search_left > node_right)
return NUM;
if (search_left <= node_left && search_right >= node_right) {
return table[node_id];
}
int left_min = query(search_left, search_right, 2 * node_id + 1, node_left,
(node_left + node_right) / 2);
int right_min = query(search_left, search_right, 2 * node_id + 2,
(node_left + node_right) / 2 + 1, node_right);
return min(left_min, right_min);
}
int main() {
int first_N, Q, command, left, right;
table = new int[1000000];
N = 1;
scanf("%d %d", &first_N, &Q);
init(first_N);
for (int i = 0; i <= 2 * N - 2; i++)
table[i] = NUM;
for (int i = 0; i < Q; i++) {
scanf("%d %d %d", &command, &left, &right);
if (command == 0) {
update(left, right);
} else {
printf("%d\n", query(left, right, 0, 0, N - 1));
}
}
return 0;
}
|
replace
| 65 | 66 | 65 | 66 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
#define INF 2147483647
int n, q, rmq[200000];
void update(int a, int b) {
a += n - 1;
rmq[a] = b;
while (a > 0) {
a = (a - 1) / 2;
rmq[a] = min(rmq[2 * a + 1], rmq[2 * a + 2]);
}
}
int query(int a, int b, int k, int s, int t) {
if (a <= s && t <= b)
return rmq[k];
if (t < a || b < s)
return INF;
return min(query(a, b, k * 2 + 1, s, (t + s - 1) / 2),
query(a, b, k * 2 + 2, (t + s + 1) / 2, t));
}
int main(void) {
int n1;
cin >> n1 >> q;
for (n = 1; n < n1; n *= 2)
;
for (int i = 0; i < n * 2 - 1; i++)
rmq[i] = INF;
for (int i = 0; i < q; i++) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0)
update(x, y);
else
cout << query(x, y, 0, 0, n - 1) << endl;
}
}
|
#include <iostream>
using namespace std;
#define INF 2147483647
int n, q, rmq[262144];
void update(int a, int b) {
a += n - 1;
rmq[a] = b;
while (a > 0) {
a = (a - 1) / 2;
rmq[a] = min(rmq[2 * a + 1], rmq[2 * a + 2]);
}
}
int query(int a, int b, int k, int s, int t) {
if (a <= s && t <= b)
return rmq[k];
if (t < a || b < s)
return INF;
return min(query(a, b, k * 2 + 1, s, (t + s - 1) / 2),
query(a, b, k * 2 + 2, (t + s + 1) / 2, t));
}
int main(void) {
int n1;
cin >> n1 >> q;
for (n = 1; n < n1; n *= 2)
;
for (int i = 0; i < n * 2 - 1; i++)
rmq[i] = INF;
for (int i = 0; i < q; i++) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0)
update(x, y);
else
cout << query(x, y, 0, 0, n - 1) << endl;
}
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p02345
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
long n, q;
scanf("%d %d", &n, &q);
long A[100000];
for (long i = 0; i < n; i++)
A[i] = pow(2, 31) - 1;
for (long i = 0; i < q; i++) {
long c, x, y;
scanf("%ld %ld %ld", &c, &x, &y);
if (c == 0)
A[x] = y;
else
printf("%ld\n", *min_element(A + x, A + y + 1));
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
int n, q;
scanf("%d %d", &n, &q);
long A[100000];
for (long i = 0; i < n; i++)
A[i] = pow(2, 31) - 1;
for (long i = 0; i < q; i++) {
long c, x, y;
scanf("%ld %ld %ld", &c, &x, &y);
if (c == 0)
A[x] = y;
else
printf("%ld\n", *min_element(A + x, A + y + 1));
}
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
TLE
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int N, dat[200000];
void init(int n_) {
N = 1;
while (N < n_)
N *= 2;
for (int i = 0; i < 2 * N - 1; i++)
dat[i] = INT_MAX;
}
void update(int k, int a) {
k += N - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
int n, q;
cin >> n >> q;
init(n);
rep(i, q) {
int com, x, y;
cin >> com >> x >> y;
if (com)
printf("%d\n", query(x, y + 1, 0, 0, N));
else
update(x, y);
}
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int N, dat[300000];
void init(int n_) {
N = 1;
while (N < n_)
N *= 2;
for (int i = 0; i < 2 * N - 1; i++)
dat[i] = INT_MAX;
}
void update(int k, int a) {
k += N - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
int n, q;
cin >> n >> q;
init(n);
rep(i, q) {
int com, x, y;
cin >> com >> x >> y;
if (com)
printf("%d\n", query(x, y + 1, 0, 0, N));
else
update(x, y);
}
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <climits>
#include <iostream>
using namespace std;
const int max_n = 1 << 16;
const int max_array = max_n * 2 - 1;
const int INF = 2147483647;
int dat[max_array];
void init() {
for (int i = 0; i < max_array; i++) {
dat[i] = INF;
}
}
void update(int k, int x) {
k += max_n - 1;
dat[k] = x;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int find(int a, int b, int k, int l, int m) {
if (m <= a || b <= l) {
return INF;
}
if (a <= l && m <= b) {
return dat[k];
}
int lv = find(a, b, k * 2 + 1, l, (l + m) / 2);
int mv = find(a, b, k * 2 + 2, (l + m) / 2, m);
return min(lv, mv);
}
int main() {
int n, q;
cin >> n >> q;
init();
for (int i = 0; i < q; i++) {
int x, y, com;
cin >> com >> x >> y;
if (com == 0) {
update(x, y);
} else {
cout << find(x, y + 1, 0, 0, max_n) << endl;
}
}
}
|
#include <climits>
#include <iostream>
using namespace std;
const int max_n = 1 << 17;
const int max_array = max_n * 2 - 1;
const int INF = 2147483647;
int dat[max_array];
void init() {
for (int i = 0; i < max_array; i++) {
dat[i] = INF;
}
}
void update(int k, int x) {
k += max_n - 1;
dat[k] = x;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int find(int a, int b, int k, int l, int m) {
if (m <= a || b <= l) {
return INF;
}
if (a <= l && m <= b) {
return dat[k];
}
int lv = find(a, b, k * 2 + 1, l, (l + m) / 2);
int mv = find(a, b, k * 2 + 2, (l + m) / 2, m);
return min(lv, mv);
}
int main() {
int n, q;
cin >> n >> q;
init();
for (int i = 0; i < q; i++) {
int x, y, com;
cin >> com >> x >> y;
if (com == 0) {
update(x, y);
} else {
cout << find(x, y + 1, 0, 0, max_n) << endl;
}
}
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const double inf = (1 << 31) - 1;
template <class T> struct Treap {
struct node_t {
T val;
T sum;
node_t *lch, *rch;
int pri;
int cnt;
node_t(T v, int p) : val(v), pri(p), cnt(1), sum(v) { lch = rch = NULL; }
};
node_t *root;
Treap() : root(NULL) {}
int count(node_t *t) { return t ? t->cnt : 0; }
T sum(node_t *t) { return t ? t->sum : inf; }
int size() { return count(root); }
T combine(T a, T b) { return min(a, b); }
node_t *update(node_t *t) {
t->cnt = count(t->lch) + count(t->rch) + 1;
t->sum = combine(combine(sum(t->lch), sum(t->rch)), t->val); //
return t;
}
node_t *merge(node_t *l, node_t *r) {
if (!l || !r)
return l ? l : r;
if (l->pri > r->pri) {
l->rch = merge(l->rch, r);
return update(l);
} else {
r->lch = merge(l, r->lch);
return update(r);
}
}
pair<node_t *, node_t *> split(node_t *t, int k) {
if (!t)
return mp((node_t *)NULL, (node_t *)NULL);
if (k <= count(t->lch)) {
pair<node_t *, node_t *> s = split(t->lch, k);
t->lch = s.second;
return mp(s.first, update(t));
} else {
pair<node_t *, node_t *> s = split(t->rch, k - count(t->lch) - 1);
t->rch = s.first;
return mp(update(t), s.second);
}
}
node_t *insert(node_t *t, int k, T val, int pri) {
pair<node_t *, node_t *> s = split(t, k);
t = merge(s.first, new node_t(val, pri));
t = merge(t, s.second);
return update(t);
}
node_t *erase(node_t *t, int k) {
pair<node_t *, node_t *> s1, s2;
s2 = split(t, k + 1);
s1 = split(s2.first, k);
t = merge(s1.first, s2.second);
return update(t);
}
node_t *find(node_t *t, int k) {
int c = count(t->lch);
if (k < c)
return find(t->lch, k);
if (k == c)
return t;
return find(t->rch, k - c - 1);
}
void shift(int l, int r) {
pair<node_t *, node_t *> a, b, c;
c = split(root, r);
b = split(c.first, r - 1);
a = split(b.first, l);
root = merge(a.first, b.second);
root = merge(root, a.second);
root = merge(root, c.second);
}
int query(int l, int r, node_t *t) {
int sz = count(t);
if (l >= sz || r <= 0)
return inf;
if (l <= 0 && r >= sz)
return sum(t);
int c = count(t->lch);
int lv = query(l, r, t->lch);
int rv = query(l - c - 1, r - c - 1, t->rch);
int res = combine(lv, rv); //
if (l <= c && c < r)
res = combine(res, t->val); //
return res;
}
void insert(int k, T val) { root = insert(root, k, val, rand()); }
void erase(int k) { root = erase(root, k); }
node_t *find(int k) { return find(root, k); }
int query(int l, int r) { return query(l, r, root); }
};
int main() {
srand(time(NULL));
int n, q;
cin >> n >> q;
Treap<int> t;
rep(i, n) t.insert(i, inf);
while (q--) {
int a, b, c;
cin >> a >> b >> c;
if (a == 1) {
cout << t.query(b, c + 1) << endl;
} else {
t.erase(b);
t.insert(b, c);
}
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const double inf = (1 << 31) - 1;
template <class T> struct Treap {
struct node_t {
T val;
T sum;
node_t *lch, *rch;
int pri;
int cnt;
node_t(T v, int p) : val(v), pri(p), cnt(1), sum(v) { lch = rch = NULL; }
};
node_t *root;
Treap() : root(NULL) {}
int count(node_t *t) { return t ? t->cnt : 0; }
T sum(node_t *t) { return t ? t->sum : inf; }
int size() { return count(root); }
T combine(T a, T b) { return min(a, b); }
node_t *update(node_t *t) {
t->cnt = count(t->lch) + count(t->rch) + 1;
t->sum = combine(combine(sum(t->lch), sum(t->rch)), t->val); //
return t;
}
node_t *merge(node_t *l, node_t *r) {
if (!l || !r)
return l ? l : r;
if (l->pri > r->pri) {
l->rch = merge(l->rch, r);
return update(l);
} else {
r->lch = merge(l, r->lch);
return update(r);
}
}
pair<node_t *, node_t *> split(node_t *t, int k) {
if (!t)
return mp((node_t *)NULL, (node_t *)NULL);
if (k <= count(t->lch)) {
pair<node_t *, node_t *> s = split(t->lch, k);
t->lch = s.second;
return mp(s.first, update(t));
} else {
pair<node_t *, node_t *> s = split(t->rch, k - count(t->lch) - 1);
t->rch = s.first;
return mp(update(t), s.second);
}
}
node_t *insert(node_t *t, int k, T val, int pri) {
pair<node_t *, node_t *> s = split(t, k);
t = merge(s.first, new node_t(val, pri));
t = merge(t, s.second);
return update(t);
}
node_t *erase(node_t *t, int k) {
pair<node_t *, node_t *> s1, s2;
s2 = split(t, k + 1);
s1 = split(s2.first, k);
t = merge(s1.first, s2.second);
return update(t);
}
node_t *find(node_t *t, int k) {
int c = count(t->lch);
if (k < c)
return find(t->lch, k);
if (k == c)
return t;
return find(t->rch, k - c - 1);
}
void shift(int l, int r) {
pair<node_t *, node_t *> a, b, c;
c = split(root, r);
b = split(c.first, r - 1);
a = split(b.first, l);
root = merge(a.first, b.second);
root = merge(root, a.second);
root = merge(root, c.second);
}
int query(int l, int r, node_t *t) {
int sz = count(t);
if (l >= sz || r <= 0)
return inf;
if (l <= 0 && r >= sz)
return sum(t);
int c = count(t->lch);
int lv = query(l, r, t->lch);
int rv = query(l - c - 1, r - c - 1, t->rch);
int res = combine(lv, rv); //
if (l <= c && c < r)
res = combine(res, t->val); //
return res;
}
void insert(int k, T val) { root = insert(root, k, val, rand()); }
void erase(int k) { root = erase(root, k); }
node_t *find(int k) { return find(root, k); }
int query(int l, int r) { return query(l, r, root); }
};
int main() {
srand(time(NULL));
int n, q;
cin >> n >> q;
Treap<int> t;
t.insert(inf, inf);
rep(i, n) t.insert(i, inf);
while (q--) {
int a, b, c;
cin >> a >> b >> c;
if (a == 1) {
cout << t.query(b, c + 1) << endl;
} else {
t.erase(b);
t.insert(b, c);
}
}
}
|
insert
| 135 | 135 | 135 | 136 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;
const int inf = 2147483647;
const int MAX = 1e5 + 10;
// RMQ
struct segtree {
int N, dat[2 * MAX];
segtree() {}
segtree(int n) {
N = 1;
while (N < n)
N *= 2;
for (int i = 0; i < 2 * N - 1; i++)
dat[i] = inf;
}
// update k th element
void update(int k, int a) {
k += N - 1; // leaf
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// min [a, b)
int query(int a, int b) { return query(a, b, 0, 0, N); }
int query(int a, int b, int k, int l, int r) {
if (r <= a or b <= l)
return inf;
if (a <= l and r <= b)
return dat[k];
int m = (l + r) / 2;
return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
}
};
signed main() {
int n, q;
cin >> n >> q;
segtree sg(n);
rep(i, 0, q) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0) {
sg.update(x, y);
} else {
cout << sg.query(x, y + 1) << endl;
}
}
}
|
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;
const int inf = 2147483647;
const int MAX = 2e5 + 10;
// RMQ
struct segtree {
int N, dat[2 * MAX];
segtree() {}
segtree(int n) {
N = 1;
while (N < n)
N *= 2;
for (int i = 0; i < 2 * N - 1; i++)
dat[i] = inf;
}
// update k th element
void update(int k, int a) {
k += N - 1; // leaf
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// min [a, b)
int query(int a, int b) { return query(a, b, 0, 0, N); }
int query(int a, int b, int k, int l, int r) {
if (r <= a or b <= l)
return inf;
if (a <= l and r <= b)
return dat[k];
int m = (l + r) / 2;
return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
}
};
signed main() {
int n, q;
cin >> n >> q;
segtree sg(n);
rep(i, 0, q) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0) {
sg.update(x, y);
} else {
cout << sg.query(x, y + 1) << endl;
}
}
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
typedef ll V;
const V INF_V = INT_MAX;
const int ME = 16;
const int N = 1 << ME;
class RMQ_segtree {
public:
V dat[2 * N - 1];
RMQ_segtree() { REP(i, 2 * N - 1) dat[i] = INF_V; }
void update(int k, V a) {
// k?????????????´????a????????´
k += N - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
}
}
V recursion(int a, int b, int k, int l, int r) {
//????°?????¨??????¨????????°??¢??°
if (r <= a || b <= l)
return INF_V;
if (a <= l && r <= b)
return dat[k];
else {
V vl = recursion(a, b, 2 * k + 1, l, (l + r) / 2);
V vr = recursion(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
V minimum(int a, int b) {
//??????[a, b)???????°????
return recursion(a, b, 0, 0, N);
}
};
int main() {
int n, q;
cin >> n >> q;
RMQ_segtree rmq;
REP(i, q) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
rmq.update(x, y);
} else {
cout << rmq.minimum(x, y + 1) << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
typedef ll V;
const V INF_V = INT_MAX;
const int ME = 17;
const int N = 1 << ME;
class RMQ_segtree {
public:
V dat[2 * N - 1];
RMQ_segtree() { REP(i, 2 * N - 1) dat[i] = INF_V; }
void update(int k, V a) {
// k?????????????´????a????????´
k += N - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
}
}
V recursion(int a, int b, int k, int l, int r) {
//????°?????¨??????¨????????°??¢??°
if (r <= a || b <= l)
return INF_V;
if (a <= l && r <= b)
return dat[k];
else {
V vl = recursion(a, b, 2 * k + 1, l, (l + r) / 2);
V vr = recursion(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
V minimum(int a, int b) {
//??????[a, b)???????°????
return recursion(a, b, 0, 0, N);
}
};
int main() {
int n, q;
cin >> n >> q;
RMQ_segtree rmq;
REP(i, q) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
rmq.update(x, y);
} else {
cout << rmq.minimum(x, y + 1) << endl;
}
}
return 0;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <climits>
#include <cstdio>
#include <iostream>
#define MAX 200000
#define INF INT_MAX
using namespace std;
int D[MAX];
int n = 1;
int inf;
void initRMQ(int n_) {
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++) {
D[i] = INF;
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return D[k];
int vleft, vright;
vleft = query(a, b, 2 * k + 1, l, (l + r) / 2);
vright = query(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vleft, vright);
}
int findMin(int a, int b) { return query(a, b + 1, 0, 0, n); }
void update(int k, int a) {
k += n - 1;
D[k] = a;
while (k > 0) {
k = (k - 1) / 2;
D[k] = min(D[2 * k + 1], D[2 * k + 2]);
}
}
int main() {
int q, com, x, y, n_, min;
cin >> n_ >> q;
initRMQ(n_);
for (int i = 0; i < q; i++) {
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else
cout << findMin(x, y) << endl;
}
return 0;
}
|
#include <climits>
#include <cstdio>
#include <iostream>
#define MAX 300000
#define INF INT_MAX
using namespace std;
int D[MAX];
int n = 1;
int inf;
void initRMQ(int n_) {
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++) {
D[i] = INF;
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return D[k];
int vleft, vright;
vleft = query(a, b, 2 * k + 1, l, (l + r) / 2);
vright = query(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vleft, vright);
}
int findMin(int a, int b) { return query(a, b + 1, 0, 0, n); }
void update(int k, int a) {
k += n - 1;
D[k] = a;
while (k > 0) {
k = (k - 1) / 2;
D[k] = min(D[2 * k + 1], D[2 * k + 2]);
}
}
int main() {
int q, com, x, y, n_, min;
cin >> n_ >> q;
initRMQ(n_);
for (int i = 0; i < q; i++) {
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else
cout << findMin(x, y) << endl;
}
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 100000;
const int INF = (1LL << 31LL) - 1;
int dat[2 * N - 1];
int n, q;
void init(int n_) {
n = 1;
while (n_ > n)
n *= 2;
for (int i = 0; i < 2 * n - 1; ++i)
dat[i] = INF;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (r + l) / 2);
int vr = query(a, b, k * 2 + 2, (r + l) / 2, r);
return min(vl, vr);
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> q;
init(n);
int com, x, y;
for (int i = 0; i < q; ++i) {
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else {
++y;
cout << query(x, y, 0, 0, n) << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 1 << 17;
const int INF = (1LL << 31LL) - 1;
int dat[2 * N - 1];
int n, q;
void init(int n_) {
n = 1;
while (n_ > n)
n *= 2;
for (int i = 0; i < 2 * n - 1; ++i)
dat[i] = INF;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (r + l) / 2);
int vr = query(a, b, k * 2 + 2, (r + l) / 2, r);
return min(vl, vr);
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> q;
init(n);
int com, x, y;
for (int i = 0; i < q; ++i) {
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else {
++y;
cout << query(x, y, 0, 0, n) << endl;
}
}
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
using namespace std;
const int INF = (1 << 31) - 1;
struct segtree {
int n;
int data[2620]; // 143];
segtree(int n_) {
n = 1;
while (n_ > n)
n *= 2;
for (int i = 0; i < n * 2 - 1; i++)
data[i] = INF;
}
void update(int k, int a) {
k += n - 1;
data[k] = a;
while (k > 0) {
k = (k - 1) / 2;
data[k] = min(data[2 * k + 1], data[2 * k + 2]);
}
}
int query(int a, int b) { return query(a, b, 0, 0, n); }
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return data[k];
return min(query(a, b, 2 * k + 1, l, (l + r) / 2),
query(a, b, 2 * k + 2, (l + r) / 2, r));
}
};
int main() {
int n, q;
scanf("%d %d", &n, &q);
segtree st(n);
for (int i = 0; i < q; i++) {
int cmd, x, y;
scanf("%d %d %d", &cmd, &x, &y);
if (cmd == 0)
st.update(x, y);
else if (cmd == 1)
printf("%d\n", st.query(x, y + 1));
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
using namespace std;
const int INF = (1 << 31) - 1;
struct segtree {
int n;
int data[262143];
segtree(int n_) {
n = 1;
while (n_ > n)
n *= 2;
for (int i = 0; i < n * 2 - 1; i++)
data[i] = INF;
}
void update(int k, int a) {
k += n - 1;
data[k] = a;
while (k > 0) {
k = (k - 1) / 2;
data[k] = min(data[2 * k + 1], data[2 * k + 2]);
}
}
int query(int a, int b) { return query(a, b, 0, 0, n); }
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return data[k];
return min(query(a, b, 2 * k + 1, l, (l + r) / 2),
query(a, b, 2 * k + 2, (l + r) / 2, r));
}
};
int main() {
int n, q;
scanf("%d %d", &n, &q);
segtree st(n);
for (int i = 0; i < q; i++) {
int cmd, x, y;
scanf("%d %d %d", &cmd, &x, &y);
if (cmd == 0)
st.update(x, y);
else if (cmd == 1)
printf("%d\n", st.query(x, y + 1));
}
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p02345
|
C++
|
Runtime Error
|
// #define LOCAL
#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
// #define int long long
typedef long long ll;
const ll INF = 1e18;
using namespace std;
const int MAX_N = 130100;
int n, dat[2 * MAX_N - 1];
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
signed main() {
#ifdef LOCAL
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
#endif
int N, Q;
int com, x, y;
cin >> N >> Q;
init(N + 100);
REP(i, Q) {
cin >> com >> x >> y;
if (com == 0) {
update(x, y);
} else {
cout << query(x, y + 1, 0, 0, n) << endl;
}
}
}
|
// #define LOCAL
#include <algorithm>
#include <assert.h>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <memory.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
// #define int long long
typedef long long ll;
const ll INF = 1e18;
using namespace std;
const int MAX_N = 300100;
int n, dat[2 * MAX_N - 1];
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
signed main() {
#ifdef LOCAL
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
#endif
int N, Q;
int com, x, y;
cin >> N >> Q;
init(N + 100);
REP(i, Q) {
cin >> com >> x >> y;
if (com == 0) {
update(x, y);
} else {
cout << query(x, y + 1, 0, 0, n) << endl;
}
}
}
|
replace
| 26 | 27 | 26 | 27 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int MAX_N = 100000;
int n;
vector<int> dat(2 * MAX_N - 1, INT_MAX);
void init(int N) {
n = 1;
while (n < N) {
n *= 2;
}
}
void update(int i, int y) {
int k;
k = n - 1 + i;
dat[k] = y;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
}
}
int find(int x, int y, int k, int l, int r) {
if (r <= x || l >= y) {
return INT_MAX;
}
if (r <= y && l >= x) {
return dat[k];
} else {
int vl = find(x, y, 2 * k + 1, l, (l + r) / 2);
int vr = find(x, y, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
int N, q, command, x, y;
cin >> N >> q;
init(N);
for (int i = 0; i < q; i++) {
cin >> command >> x >> y;
if (command) {
cout << find(x, y + 1, 0, 0, n) << endl;
} else {
update(x, y);
}
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int MAX_N = 100000;
int n;
vector<int> dat(4 * MAX_N, INT_MAX);
void init(int N) {
n = 1;
while (n < N) {
n *= 2;
}
}
void update(int i, int y) {
int k;
k = n - 1 + i;
dat[k] = y;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
}
}
int find(int x, int y, int k, int l, int r) {
if (r <= x || l >= y) {
return INT_MAX;
}
if (r <= y && l >= x) {
return dat[k];
} else {
int vl = find(x, y, 2 * k + 1, l, (l + r) / 2);
int vr = find(x, y, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
int N, q, command, x, y;
cin >> N >> q;
init(N);
for (int i = 0; i < q; i++) {
cin >> command >> x >> y;
if (command) {
cout << find(x, y + 1, 0, 0, n) << endl;
} else {
update(x, y);
}
}
return 0;
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
#define MAXN 100010
#define INT_MAX 2147483647
typedef long long ll;
int n, q;
int dat[MAXN * 2];
// 初期化
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
}
// k番目の値をxに変更
void update(int k, int x) {
k += n - 1;
dat[k] = x;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// [a, b)の最小値を求める
int query(int a, int b, int k, int l, int r) {
if (a >= r || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
int main(void) {
cin >> n >> q;
init(n);
for (int i = 0; i < q; i++) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
update(x, y);
} else {
cout << query(x, y + 1, 0, 0, n) << endl;
}
// for (int i = 0; i < 2*n-1; i++) {
// cout << dat[i] << endl;
// }
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
#define MAXN 100010
#define INT_MAX 2147483647
typedef long long ll;
int n, q;
int dat[MAXN * 4];
// 初期化
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
}
// k番目の値をxに変更
void update(int k, int x) {
k += n - 1;
dat[k] = x;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// [a, b)の最小値を求める
int query(int a, int b, int k, int l, int r) {
if (a >= r || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
int main(void) {
cin >> n >> q;
init(n);
for (int i = 0; i < q; i++) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
update(x, y);
} else {
cout << query(x, y + 1, 0, 0, n) << endl;
}
// for (int i = 0; i < 2*n-1; i++) {
// cout << dat[i] << endl;
// }
}
return 0;
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
const long long Mx = 0x7FFFFFFF;
long long n, q, x, y, m = 1;
long long a[200000];
void ud(long long x, long long y) {
long long k = m + x - 1;
a[k] = y;
while (k > 0) {
k = (k - 1) / 2;
a[k] = min(a[k * 2 + 1], a[k * 2 + 2]);
}
}
long long find(long long x, long long y, long long k, long long l,
long long r) {
if (x <= l && y >= r)
return a[k];
else if (x >= r || y <= l)
return Mx;
else {
long long lm = find(x, y, k * 2 + 1, l, (l + r) / 2);
long long rm = find(x, y, k * 2 + 2, (l + r) / 2, r);
return min(lm, rm);
}
}
int main() {
cin >> n >> q;
while (m < n)
m *= 2;
for (int i = 0; i < m * 2; i++)
a[i] = Mx;
for (int j = 0; j < q; j++) {
int p;
cin >> p;
if (p == 0) {
cin >> x >> y;
ud(x, y);
} else if (p == 1) {
cin >> x >> y;
cout << find(x, y + 1, 0, 0, m) << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
const long long Mx = 0x7FFFFFFF;
long long n, q, x, y, m = 1;
long long a[300000];
void ud(long long x, long long y) {
long long k = m + x - 1;
a[k] = y;
while (k > 0) {
k = (k - 1) / 2;
a[k] = min(a[k * 2 + 1], a[k * 2 + 2]);
}
}
long long find(long long x, long long y, long long k, long long l,
long long r) {
if (x <= l && y >= r)
return a[k];
else if (x >= r || y <= l)
return Mx;
else {
long long lm = find(x, y, k * 2 + 1, l, (l + r) / 2);
long long rm = find(x, y, k * 2 + 2, (l + r) / 2, r);
return min(lm, rm);
}
}
int main() {
cin >> n >> q;
while (m < n)
m *= 2;
for (int i = 0; i < m * 2; i++)
a[i] = Mx;
for (int j = 0; j < q; j++) {
int p;
cin >> p;
if (p == 0) {
cin >> x >> y;
ud(x, y);
} else if (p == 1) {
cin >> x >> y;
cout << find(x, y + 1, 0, 0, m) << endl;
}
}
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p02345
|
C++
|
Time Limit Exceeded
|
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) begin(c), end(c)
#define range(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) range(i, 0, b)
#define rangei(i, a, b) for (ll a = a; i <= ll(b); i++)
#define repi(i, b) rangei(i, 1, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template <class T> ostream &operator<<(ostream &os, vector<T> const &);
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
tuple<T...> const &t) {
os << (n == 0 ? "" : " ") << get<n>(t);
_ot<n + 1>(os, t);
}
template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) {
_ot<0>(os, t);
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
return os;
}
#ifdef DEBUG
#define dump(...) \
(cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) << " [" << __LINE__ << "]" \
<< endl)
#else
#define dump(...)
#endif
void fastios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#define endl '\n'
}
template <class T> size_t uniq(vector<T> &v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
return v.size();
}
template <class T> size_t uniq(T *l, size_t n) {
sort(l, l + n);
return unique(l, l + n) - l;
}
#define mems(arr, val) memset(arr, val, sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max();
// RMQ
template <class T> struct SegmentTree {
int n;
vector<T> dat;
SegmentTree(int n_ = 0) : n(n_) {
n = 1;
while (n < n_)
n <<= 1;
dat.resize(n * 2, inf);
}
T query(int v, int w, int l, int r) {
if (v >= (int)dat.size())
return inf;
if (r - l == w)
return dat[v];
T res = inf;
res = std::min(res, query(v * 2, w / 2, l, min(r, w / 2)));
res = std::min(res, query(v * 2 + 1, w / 2, max(0, l - w / 2), r - w / 2));
return res;
}
void update(int i, T x) {
i += n;
dat[i] = x;
while (i != 1) {
dat[i >> 1] = min(dat[i], dat[i ^ 1]);
i /= 2;
}
}
T query(int l, int r) { return query(1, n, l, r); }
size_t size() const { return n; }
};
int main() {
fastios();
int n, q;
while (cin >> n >> q) {
SegmentTree<int> st(n);
rep(i, q) {
char c;
int x, y;
cin >> c >> x >> y;
if (c == '0') {
st.update(x, y);
} else {
cout << st.query(x, y + 1) << endl;
}
}
}
}
|
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) begin(c), end(c)
#define range(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) range(i, 0, b)
#define rangei(i, a, b) for (ll a = a; i <= ll(b); i++)
#define repi(i, b) rangei(i, 1, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template <class T> ostream &operator<<(ostream &os, vector<T> const &);
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
tuple<T...> const &t) {
os << (n == 0 ? "" : " ") << get<n>(t);
_ot<n + 1>(os, t);
}
template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) {
_ot<0>(os, t);
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
return os;
}
#ifdef DEBUG
#define dump(...) \
(cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) << " [" << __LINE__ << "]" \
<< endl)
#else
#define dump(...)
#endif
void fastios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#define endl '\n'
}
template <class T> size_t uniq(vector<T> &v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
return v.size();
}
template <class T> size_t uniq(T *l, size_t n) {
sort(l, l + n);
return unique(l, l + n) - l;
}
#define mems(arr, val) memset(arr, val, sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max();
// RMQ
template <class T> struct SegmentTree {
int n;
vector<T> dat;
SegmentTree(int n_ = 0) : n(n_) {
n = 1;
while (n < n_)
n <<= 1;
dat.resize(n * 2, inf);
}
T query(int v, int w, int l, int r) {
if (v >= (int)dat.size())
return inf;
if (r - l == w)
return dat[v];
if (r <= l)
return inf;
T res = inf;
res = std::min(res, query(v * 2, w / 2, l, min(r, w / 2)));
res = std::min(res, query(v * 2 + 1, w / 2, max(0, l - w / 2), r - w / 2));
return res;
}
void update(int i, T x) {
i += n;
dat[i] = x;
while (i != 1) {
dat[i >> 1] = min(dat[i], dat[i ^ 1]);
i /= 2;
}
}
T query(int l, int r) { return query(1, n, l, r); }
size_t size() const { return n; }
};
int main() {
fastios();
int n, q;
while (cin >> n >> q) {
SegmentTree<int> st(n);
rep(i, q) {
char c;
int x, y;
cin >> c >> x >> y;
if (c == '0') {
st.update(x, y);
} else {
cout << st.query(x, y + 1) << endl;
}
}
}
}
|
insert
| 80 | 80 | 80 | 82 |
TLE
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
const int MAX_N = 100010;
const int inf = 2147483647;
int dat[MAX_N * 2];
int n;
void init(int n_) {
n = 1;
while (n < n_)
n *= 2; // 2のn乗に切り上げる
// 全て inf で初期化したいとき
for (int i = 0; i < n * 2; i++) {
dat[i] = inf;
}
// 配列 a の要素で初期化したいとき
// for(int i = n; i < n+n; i++){
// dat[i] = a[i-n];
// }
// for(int i=n-1; i>=1; i--){
// dat[i] = min(dat[i*2], dat[i*2+1]);
// }
}
void update(int i, int x) {
i += n;
dat[i] = x;
while (i > 0) {
dat[i / 2] = min(dat[i], dat[i ^ 1]);
i /= 2;
}
}
int query(int a, int b, int i, int l, int r) {
if (r <= a || b <= l)
return inf;
if (a <= l && r <= b)
return dat[i];
return min(query(a, b, i * 2, l, (l + r) / 2),
query(a, b, i * 2 + 1, (l + r) / 2, r));
}
int query(int a, int b) { return query(a, b, 1, 0, n); }
int main() {
int n, q;
while (cin >> n >> q) {
init(n);
for (int i = 0; i < q; i++) {
char c;
int x, y;
cin >> c >> x >> y;
if (c == '0') {
update(x, y);
} else {
cout << query(x, y + 1) << endl;
}
}
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
const int MAX_N = 100010;
const int inf = 2147483647;
int dat[MAX_N * 4];
int n;
void init(int n_) {
n = 1;
while (n < n_)
n *= 2; // 2のn乗に切り上げる
// 全て inf で初期化したいとき
for (int i = 0; i < n * 2; i++) {
dat[i] = inf;
}
// 配列 a の要素で初期化したいとき
// for(int i = n; i < n+n; i++){
// dat[i] = a[i-n];
// }
// for(int i=n-1; i>=1; i--){
// dat[i] = min(dat[i*2], dat[i*2+1]);
// }
}
void update(int i, int x) {
i += n;
dat[i] = x;
while (i > 0) {
dat[i / 2] = min(dat[i], dat[i ^ 1]);
i /= 2;
}
}
int query(int a, int b, int i, int l, int r) {
if (r <= a || b <= l)
return inf;
if (a <= l && r <= b)
return dat[i];
return min(query(a, b, i * 2, l, (l + r) / 2),
query(a, b, i * 2 + 1, (l + r) / 2, r));
}
int query(int a, int b) { return query(a, b, 1, 0, n); }
int main() {
int n, q;
while (cin >> n >> q) {
init(n);
for (int i = 0; i < q; i++) {
char c;
int x, y;
cin >> c >> x >> y;
if (c == '0') {
update(x, y);
} else {
cout << query(x, y + 1) << endl;
}
}
}
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define mind(a, b) (a > b ? b : a)
#define maxd(a, b) (a > b ? a : b)
#define absd(x) (x < 0 ? -(x) : x)
#define pow2(x) ((x) * (x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define repl(i, s, n) for (int i = s; i <= n; ++i)
#define replr(i, s, n) for (int i = n; i >= s; --i)
#define repf(i, s, n, j) for (int i = s; i <= n; i += j)
#define repe(e, obj) for (auto e : obj)
#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X, Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i, n, val) \
for (int i = 0; i < n; ++i) \
cout << val << " "; \
cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P>> pvqueue;
#define N 100007
class SegmentTree {
const static ll inf = (1LL << 31) - 1;
int n, n0;
ll data[N];
public:
SegmentTree(int n) {
n0 = 1;
while (n0 < n)
n0 <<= 1;
rep(i, 2 * n0) data[i] = inf;
}
void update(int k, ll x) {
k += n0 - 1;
data[k] = x;
while (k > 0) {
k = (k - 1) / 2;
data[k] = min(data[2 * k + 1], data[2 * k + 2]);
}
}
ll query(int l, int r) {
int l0 = l + n0, r0 = r + n0;
ll s = inf;
while (l0 < r0) {
if (r0 & 1) {
--r0;
s = min(s, data[r0 - 1]);
}
if (l0 & 1) {
s = min(s, data[l0 - 1]);
++l0;
}
l0 >>= 1;
r0 >>= 1;
}
return s;
}
};
int n, q;
int main() {
cin >> n >> q;
SegmentTree st(n);
rep(i, q) {
int t, x, y;
cin >> t >> x >> y;
switch (t) {
case 0:
st.update(x, y);
break;
case 1:
cout << st.query(x, y + 1) << endl;
break;
}
}
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define mind(a, b) (a > b ? b : a)
#define maxd(a, b) (a > b ? a : b)
#define absd(x) (x < 0 ? -(x) : x)
#define pow2(x) ((x) * (x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define repl(i, s, n) for (int i = s; i <= n; ++i)
#define replr(i, s, n) for (int i = n; i >= s; --i)
#define repf(i, s, n, j) for (int i = s; i <= n; i += j)
#define repe(e, obj) for (auto e : obj)
#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X, Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i, n, val) \
for (int i = 0; i < n; ++i) \
cout << val << " "; \
cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9
typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P>> pvqueue;
#define N 100007
class SegmentTree {
const static ll inf = (1LL << 31) - 1;
int n, n0;
ll data[4 * N];
public:
SegmentTree(int n) {
n0 = 1;
while (n0 < n)
n0 <<= 1;
rep(i, 2 * n0) data[i] = inf;
}
void update(int k, ll x) {
k += n0 - 1;
data[k] = x;
while (k > 0) {
k = (k - 1) / 2;
data[k] = min(data[2 * k + 1], data[2 * k + 2]);
}
}
ll query(int l, int r) {
int l0 = l + n0, r0 = r + n0;
ll s = inf;
while (l0 < r0) {
if (r0 & 1) {
--r0;
s = min(s, data[r0 - 1]);
}
if (l0 & 1) {
s = min(s, data[l0 - 1]);
++l0;
}
l0 >>= 1;
r0 >>= 1;
}
return s;
}
};
int n, q;
int main() {
cin >> n >> q;
SegmentTree st(n);
rep(i, q) {
int t, x, y;
cin >> t >> x >> y;
switch (t) {
case 0:
st.update(x, y);
break;
case 1:
cout << st.query(x, y + 1) << endl;
break;
}
}
return 0;
}
|
replace
| 60 | 61 | 60 | 61 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
struct RMQ {
static const int MAXN = 100000;
int n;
int dat[2 * MAXN - 1];
RMQ(int n_) { init(n_); }
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int query(int a, int b) { return query(a, b, 0, 0, n); }
};
int main() {
int n, q;
cin >> n >> q;
RMQ rmq(n);
for (int i = 0; i < q; i++) {
int c, x, y;
cin >> c >> x >> y;
if (c)
cout << rmq.query(x, y + 1) << endl;
else
rmq.update(x, y);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct RMQ {
static const int MAX_N = 1 << 17;
int n, dat[2 * MAX_N - 1];
// RMQ(){}
RMQ(int n_) { init(n_); }
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int query(int a, int b) { return query(a, b, 0, 0, n); }
};
int main() {
int n, q;
cin >> n >> q;
RMQ rmq(n);
for (int i = 0; i < q; i++) {
int c, x, y;
cin >> c >> x >> y;
if (c)
cout << rmq.query(x, y + 1) << endl;
else
rmq.update(x, y);
}
return 0;
}
|
replace
| 4 | 7 | 4 | 7 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(), (x).end()
#define C(x) cout << #x << " : " << x << endl
#define scanf scanf_s
using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;
using namespace std;
template <typename Monoid, typename Operand> class SegTree {
public:
Monoid *tree;
size_t size;
int32 i;
//?????????????????????
SegTree(size_t length) {
--length;
if (length & 0xffff0000) {
size = length & 0xffff0000;
}
if (size & 0xff00ff00) {
size = size & 0xff00ff00;
}
if (size & 0xf0f0f0f0) {
size = size & 0xf0f0f0f0;
}
if (size & 0xcccccccc) {
size = size & 0xcccccccc;
}
if (size & 0xaaaaaaaa) {
size = size & 0xaaaaaaaa;
}
if (length) {
size <<= 1;
} else {
size = 1;
}
tree = (Monoid *)calloc(size << 1, sizeof(Monoid));
}
//?????????
void set(bool merge) {
i = size << 1;
while (--i) {
tree[i].set();
}
if (merge) {
i = size;
while (--i) {
tree[i] = tree[i << 1] + tree[i << 1 | 1];
}
}
}
// tree[index]???data??§??´??°
void update(size_t index, Operand &data) {
index += size;
tree[index] = tree[index] * data;
while (index >>= 1)
tree[index] = tree[index << 1] + tree[index << 1 | 1];
}
//[begin,end)??????????????????
Monoid range(size_t begin, size_t end) {
Monoid retL, retR;
for (begin += size, end += size; begin < end; begin >>= 1, end >>= 1) {
if (begin & 1)
retL = retL + tree[begin++];
if (end & 1)
retR = tree[end - 1] + retR;
}
return retL + retR;
}
};
struct SUB {
int32 e;
SUB() { set(); }
SUB(int32 x) { e = x; }
void set() { e = 1000000000; }
SUB operator*(const SUB &other) { return other; }
};
struct MIN {
int32 e;
MIN() { set(); }
MIN(int32 x) { e = x; }
void set() { e = 2147483647; }
MIN operator+(const MIN &other) {
return e < other.e ? MIN(e) : MIN(other.e);
};
MIN operator*(const SUB &other) { return MIN(other.e); }
};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
size_t n, q;
cin >> n >> q;
bool c;
size_t x, y;
SUB z;
SegTree<MIN, SUB> t(n);
t.set(0);
while (q--) {
cin >> c;
if (c) {
cin >> x >> y;
printf("%d\n", t.range(x, y + 1).e);
} else {
cin >> x >> z.e;
t.update(x, z);
}
}
return 0;
}
|
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(), (x).end()
#define C(x) cout << #x << " : " << x << endl
#define scanf scanf_s
using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;
using namespace std;
template <typename Monoid, typename Operand> class SegTree {
public:
Monoid *tree;
size_t size;
int32 i;
//?????????????????????
SegTree(size_t length) {
--length;
size = length;
if (size & 0xffff0000) {
size = size & 0xffff0000;
}
if (size & 0xff00ff00) {
size = size & 0xff00ff00;
}
if (size & 0xf0f0f0f0) {
size = size & 0xf0f0f0f0;
}
if (size & 0xcccccccc) {
size = size & 0xcccccccc;
}
if (size & 0xaaaaaaaa) {
size = size & 0xaaaaaaaa;
}
if (length) {
size <<= 1;
} else {
size = 1;
}
tree = (Monoid *)calloc(size << 1, sizeof(Monoid));
}
//?????????
void set(bool merge) {
i = size << 1;
while (--i) {
tree[i].set();
}
if (merge) {
i = size;
while (--i) {
tree[i] = tree[i << 1] + tree[i << 1 | 1];
}
}
}
// tree[index]???data??§??´??°
void update(size_t index, Operand &data) {
index += size;
tree[index] = tree[index] * data;
while (index >>= 1)
tree[index] = tree[index << 1] + tree[index << 1 | 1];
}
//[begin,end)??????????????????
Monoid range(size_t begin, size_t end) {
Monoid retL, retR;
for (begin += size, end += size; begin < end; begin >>= 1, end >>= 1) {
if (begin & 1)
retL = retL + tree[begin++];
if (end & 1)
retR = tree[end - 1] + retR;
}
return retL + retR;
}
};
struct SUB {
int32 e;
SUB() { set(); }
SUB(int32 x) { e = x; }
void set() { e = 1000000000; }
SUB operator*(const SUB &other) { return other; }
};
struct MIN {
int32 e;
MIN() { set(); }
MIN(int32 x) { e = x; }
void set() { e = 2147483647; }
MIN operator+(const MIN &other) {
return e < other.e ? MIN(e) : MIN(other.e);
};
MIN operator*(const SUB &other) { return MIN(other.e); }
};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
size_t n, q;
cin >> n >> q;
bool c;
size_t x, y;
SUB z;
SegTree<MIN, SUB> t(n);
t.set(0);
while (q--) {
cin >> c;
if (c) {
cin >> x >> y;
printf("%d\n", t.range(x, y + 1).e);
} else {
cin >> x >> z.e;
t.update(x, z);
}
}
return 0;
}
|
replace
| 37 | 39 | 37 | 40 |
-11
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iostream>
#define N (1 << 18)
#define INF 2147483647
using namespace std;
void Update(int, int);
int Find(int, int, int, int, int);
int tree[N], n, N1 = N;
int main() {
int q, com, x, y;
if (N1 % 2 == 1)
N1 -= 1;
cin >> n >> q;
for (int i = 0; i < 2 * n - 1; i++)
Update(i, INF);
while (q--) {
cin >> com >> x >> y;
if (com == 0)
Update(x, y);
else {
int r = Find(x, y + 1, 0, 0, N1 / 2);
cout << r << endl;
}
}
return 0;
}
void Update(int x, int y) {
x += N1 / 2 - 1;
tree[x] = y;
while (x > 0) {
x = (x - 1) / 2;
tree[x] = min(tree[x * 2 + 1], tree[x * 2 + 2]);
}
}
int Find(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return tree[k];
else {
int vl = Find(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = Find(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#define N (1 << 19)
#define INF 2147483647
using namespace std;
void Update(int, int);
int Find(int, int, int, int, int);
int tree[N], n, N1 = N;
int main() {
int q, com, x, y;
if (N1 % 2 == 1)
N1 -= 1;
cin >> n >> q;
for (int i = 0; i < 2 * n - 1; i++)
Update(i, INF);
while (q--) {
cin >> com >> x >> y;
if (com == 0)
Update(x, y);
else {
int r = Find(x, y + 1, 0, 0, N1 / 2);
cout << r << endl;
}
}
return 0;
}
void Update(int x, int y) {
x += N1 / 2 - 1;
tree[x] = y;
while (x > 0) {
x = (x - 1) / 2;
tree[x] = min(tree[x * 2 + 1], tree[x * 2 + 2]);
}
}
int Find(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return tree[k];
else {
int vl = Find(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = Find(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p02345
|
C++
|
Time Limit Exceeded
|
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <vector>
#define DATA_MAX 100000
#define QUERY_MAX 100000
#define LEFT 0
#define RIGHT 1
using namespace std;
class SegTree {
struct Node {
int value;
int high;
int low;
};
private:
vector<vector<Node>> Tree;
const int MAX_VALUE;
int DNum, QNum;
int min(int d1, int d2) { return d1 < d2 ? d1 : d2; }
int min(vector<int> v) {
int m = v[0];
for (vector<int>::size_type i = 1; i < v.size(); i++)
if (m > v[i])
m = v[i];
return m;
}
void CreateTree(int level) {
vector<Node> new_layer;
Node tmp;
for (vector<Node>::size_type i = 0; i < Tree[level].size(); i += 2) {
tmp.value = min(Tree[level][i].value, Tree[level][i + 1].value);
tmp.low = Tree[level][i].low;
tmp.high = Tree[level][i + 1].high;
new_layer.push_back(tmp);
if (i + 2 == Tree[level].size() - 1) {
tmp = Tree[level][i + 2];
new_layer.push_back(tmp);
break;
}
}
Tree.push_back(new_layer);
if (Tree[level + 1].size() == 1)
return;
else
CreateTree(level + 1);
}
void UpDate(int x, int y) {
int target = x;
Tree[0][target].value = y;
for (vector<vector<Node>>::size_type level = 1; level < Tree.size();
level++) {
if (target == Tree[level - 1].size() - 1 && Tree[level - 1].size() & 1)
Tree[level][target / 2].value = Tree[level - 1][target].value;
else if (target & 1)
Tree[level][target / 2].value = min(Tree[level - 1][target].value,
Tree[level - 1][target - 1].value);
else
Tree[level][target / 2].value = min(Tree[level - 1][target].value,
Tree[level - 1][target + 1].value);
target /= 2;
}
PrintTree();
}
int Find(int x, int y) {
pair<int, int> section(x, y);
vector<int> element;
int iter = x;
while (iter <= y) {
iter = Find(element, 0, iter, section, Tree[0][iter]);
iter++;
}
return min(element);
}
int Find(vector<int> &element, int level, int key, pair<int, int> section,
Node before) {
if (section.first <= Tree[level][key].low &&
Tree[level][key].high <= section.second) {
if (level == Tree.size() - 1) {
element.push_back(Tree[level][0].value);
return Tree[level][0].high;
} else
return Find(element, level + 1, key / 2, section, Tree[level][key]);
}
element.push_back(before.value);
return before.high;
}
void PrintTree() {
static ofstream fout("tree.txt");
for (int i = (int)Tree.size() - 1; i >= 0; i--) {
for (vector<Node>::size_type j = 0; j < Tree[i].size(); j++) {
fout << "(";
if (Tree[i][j].value == MAX_VALUE)
fout << "∞";
else
fout << Tree[i][j].value;
fout << ", [" << Tree[i][j].low << ", " << Tree[i][j].high << "])";
}
fout << endl;
}
fout << endl;
}
public:
SegTree() : MAX_VALUE(pow(2, 31) - 1) { Tree.resize(1); }
void Init() {
cin >> DNum >> QNum;
if (!(1 <= DNum && DNum <= DATA_MAX) || !(1 <= QNum && QNum <= QUERY_MAX))
exit(1);
Tree[0].resize(DNum);
for (vector<int>::size_type i = 0; i < Tree[0].size(); i++) {
Tree[0][i].value = MAX_VALUE;
Tree[0][i].high = (int)i;
Tree[0][i].low = (int)i;
}
CreateTree(0);
}
void ReadQuery() {
int com, x, y;
for (int c = 0; c < QNum; c++) {
cin >> com >> x >> y;
if (com == 0) {
if (!(0 <= x && x < DNum) || !(0 <= y && y < MAX_VALUE))
exit(2);
UpDate(x, y);
} else if (com == 1) {
if (!(0 <= x && x < DNum) || !(0 <= y && y < DNum))
exit(3);
if (x == y)
cout << Tree[0][x].value << endl;
else if (abs(x - y) == 1)
cout << min(Tree[0][x].value, Tree[0][y].value) << endl;
else
cout << Find(x, y) << endl;
} else
exit(4);
}
}
};
int main() {
SegTree sg;
sg.Init();
sg.ReadQuery();
return 0;
}
|
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <vector>
#define DATA_MAX 100000
#define QUERY_MAX 100000
#define LEFT 0
#define RIGHT 1
using namespace std;
class SegTree {
struct Node {
int value;
int high;
int low;
};
private:
vector<vector<Node>> Tree;
const int MAX_VALUE;
int DNum, QNum;
int min(int d1, int d2) { return d1 < d2 ? d1 : d2; }
int min(vector<int> v) {
int m = v[0];
for (vector<int>::size_type i = 1; i < v.size(); i++)
if (m > v[i])
m = v[i];
return m;
}
void CreateTree(int level) {
vector<Node> new_layer;
Node tmp;
for (vector<Node>::size_type i = 0; i < Tree[level].size(); i += 2) {
tmp.value = min(Tree[level][i].value, Tree[level][i + 1].value);
tmp.low = Tree[level][i].low;
tmp.high = Tree[level][i + 1].high;
new_layer.push_back(tmp);
if (i + 2 == Tree[level].size() - 1) {
tmp = Tree[level][i + 2];
new_layer.push_back(tmp);
break;
}
}
Tree.push_back(new_layer);
if (Tree[level + 1].size() == 1)
return;
else
CreateTree(level + 1);
}
void UpDate(int x, int y) {
int target = x;
Tree[0][target].value = y;
for (vector<vector<Node>>::size_type level = 1; level < Tree.size();
level++) {
if (target == Tree[level - 1].size() - 1 && Tree[level - 1].size() & 1)
Tree[level][target / 2].value = Tree[level - 1][target].value;
else if (target & 1)
Tree[level][target / 2].value = min(Tree[level - 1][target].value,
Tree[level - 1][target - 1].value);
else
Tree[level][target / 2].value = min(Tree[level - 1][target].value,
Tree[level - 1][target + 1].value);
target /= 2;
}
// PrintTree();
}
int Find(int x, int y) {
pair<int, int> section(x, y);
vector<int> element;
int iter = x;
while (iter <= y) {
iter = Find(element, 0, iter, section, Tree[0][iter]);
iter++;
}
return min(element);
}
int Find(vector<int> &element, int level, int key, pair<int, int> section,
Node before) {
if (section.first <= Tree[level][key].low &&
Tree[level][key].high <= section.second) {
if (level == Tree.size() - 1) {
element.push_back(Tree[level][0].value);
return Tree[level][0].high;
} else
return Find(element, level + 1, key / 2, section, Tree[level][key]);
}
element.push_back(before.value);
return before.high;
}
void PrintTree() {
static ofstream fout("tree.txt");
for (int i = (int)Tree.size() - 1; i >= 0; i--) {
for (vector<Node>::size_type j = 0; j < Tree[i].size(); j++) {
fout << "(";
if (Tree[i][j].value == MAX_VALUE)
fout << "∞";
else
fout << Tree[i][j].value;
fout << ", [" << Tree[i][j].low << ", " << Tree[i][j].high << "])";
}
fout << endl;
}
fout << endl;
}
public:
SegTree() : MAX_VALUE(pow(2, 31) - 1) { Tree.resize(1); }
void Init() {
cin >> DNum >> QNum;
if (!(1 <= DNum && DNum <= DATA_MAX) || !(1 <= QNum && QNum <= QUERY_MAX))
exit(1);
Tree[0].resize(DNum);
for (vector<int>::size_type i = 0; i < Tree[0].size(); i++) {
Tree[0][i].value = MAX_VALUE;
Tree[0][i].high = (int)i;
Tree[0][i].low = (int)i;
}
CreateTree(0);
}
void ReadQuery() {
int com, x, y;
for (int c = 0; c < QNum; c++) {
cin >> com >> x >> y;
if (com == 0) {
if (!(0 <= x && x < DNum) || !(0 <= y && y < MAX_VALUE))
exit(2);
UpDate(x, y);
} else if (com == 1) {
if (!(0 <= x && x < DNum) || !(0 <= y && y < DNum))
exit(3);
if (x == y)
cout << Tree[0][x].value << endl;
else if (abs(x - y) == 1)
cout << min(Tree[0][x].value, Tree[0][y].value) << endl;
else
cout << Find(x, y) << endl;
} else
exit(4);
}
}
};
int main() {
SegTree sg;
sg.Init();
sg.ReadQuery();
return 0;
}
|
replace
| 81 | 82 | 81 | 82 |
TLE
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, N) for (int i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second
#define N_SIZE 100100
int n, q;
struct RMQ {
int N;
ll gt;
ll a[N_SIZE];
ll seg[N_SIZE * 2];
void init(int n) {
N = n;
REP(i, 30) {
if ((1 << i) >= N) {
gt = (1 << i) - 1;
break;
}
}
REP(i, N) {
// cin >> a[i];
a[i] = (1 << 31) - 1;
}
REP(i, N_SIZE * 2) seg[i] = (1 << 31) - 1;
REP(i, N) { seg[i + gt] = a[i]; }
}
void update(int k, int x) {
k += gt;
seg[k] = x;
while (k) {
k = (k - 1) / 2; //???????????????
seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]);
}
}
ll query(int a, int b, int k, int l, int r) {
if (r < a || b < l)
return (1 << 31) - 1;
else if (a <= l && r <= b)
return seg[k];
else
return min(query(a, b, k * 2 + 1, l, (l + r) / 2),
query(a, b, k * 2 + 2, (l + r) / 2 + 1, r));
}
void print() {
REP(i, 2 * (gt + 1)) { cout << i << " " << seg[i] << endl; }
}
};
RMQ rmq;
int main() {
cin >> n >> q;
rmq.init(n);
REP(i, q) {
ll x, y;
bool f;
cin >> f >> x >> y;
if (!f) {
rmq.update(x, y);
} else {
cout << rmq.query(x, y, 0, 0, rmq.gt) << endl;
}
// rmq.print();
}
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, N) for (int i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second
#define N_SIZE (1 << 20)
int n, q;
struct RMQ {
int N;
ll gt;
ll a[N_SIZE];
ll seg[N_SIZE * 2];
void init(int n) {
N = n;
REP(i, 30) {
if ((1 << i) >= N) {
gt = (1 << i) - 1;
break;
}
}
REP(i, N) {
// cin >> a[i];
a[i] = (1 << 31) - 1;
}
REP(i, N_SIZE * 2) seg[i] = (1 << 31) - 1;
REP(i, N) { seg[i + gt] = a[i]; }
}
void update(int k, int x) {
k += gt;
seg[k] = x;
while (k) {
k = (k - 1) / 2; //???????????????
seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]);
}
}
ll query(int a, int b, int k, int l, int r) {
if (r < a || b < l)
return (1 << 31) - 1;
else if (a <= l && r <= b)
return seg[k];
else
return min(query(a, b, k * 2 + 1, l, (l + r) / 2),
query(a, b, k * 2 + 2, (l + r) / 2 + 1, r));
}
void print() {
REP(i, 2 * (gt + 1)) { cout << i << " " << seg[i] << endl; }
}
};
RMQ rmq;
int main() {
cin >> n >> q;
rmq.init(n);
REP(i, q) {
ll x, y;
bool f;
cin >> f >> x >> y;
if (!f) {
rmq.update(x, y);
} else {
cout << rmq.query(x, y, 0, 0, rmq.gt) << endl;
}
// rmq.print();
}
}
|
replace
| 38 | 39 | 38 | 39 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
template <typename T> struct SegmentTree {
struct Node {
T v;
Node(T v) : v(v) {}
Node operator*(const Node &r) const { return Node(min(v, r.v)); }
};
Node e = Node((1ll << 31) - 1);
size_t n;
vector<Node> seg;
SegmentTree(size_t size)
: n(1 << (32 - __builtin_clz(size - 1))), seg(2 * n, e) {}
void update(int k, const Node &x) {
for (seg[k + n] = x, k = (k + n) / 2; k; k <<= 1) {
seg[k] = seg[2 * k] * seg[2 * k + 1];
}
}
Node query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return e;
if (a <= l && r <= b)
return seg[k];
return query(a, b, 2 * k, l, (l + r) / 2) *
query(a, b, 2 * k + 1, (l + r) / 2, r);
}
void update(int k, T x) { update(k, Node(x)); }
T query(int a, int b) { return query(a, b, 1, 0, n).v; }
};
int main() {
int n, q;
cin >> n >> q;
SegmentTree<int> seg(n);
while (q--) {
int c, x, y;
cin >> c >> x >> y;
if (c) {
cout << seg.query(x, y + 1) << endl;
} else {
seg.update(x, y);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T> struct SegmentTree {
struct Node {
T v;
Node(T v) : v(v) {}
Node operator*(const Node &r) const { return Node(min(v, r.v)); }
};
Node e = Node((1ll << 31) - 1);
size_t n;
vector<Node> seg;
SegmentTree(size_t size)
: n(1 << (32 - __builtin_clz(size - 1))), seg(2 * n, e) {}
void update(int k, const Node &x) {
for (seg[k + n] = x, k = (k + n) / 2; k; k >>= 1) {
seg[k] = seg[2 * k] * seg[2 * k + 1];
}
}
Node query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return e;
if (a <= l && r <= b)
return seg[k];
return query(a, b, 2 * k, l, (l + r) / 2) *
query(a, b, 2 * k + 1, (l + r) / 2, r);
}
void update(int k, T x) { update(k, Node(x)); }
T query(int a, int b) { return query(a, b, 1, 0, n).v; }
};
int main() {
int n, q;
cin >> n >> q;
SegmentTree<int> seg(n);
while (q--) {
int c, x, y;
cin >> c >> x >> y;
if (c) {
cout << seg.query(x, y + 1) << endl;
} else {
seg.update(x, y);
}
}
}
|
replace
| 18 | 19 | 18 | 19 |
-11
| |
p02345
|
C++
|
Runtime Error
|
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template <class T> ostream &operator<<(ostream &os, vector<T> const &);
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
tuple<T...> const &t) {
os << (n == 0 ? "" : " ") << get<n>(t);
_ot<n + 1>(os, t);
}
template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) {
_ot<0>(os, t);
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
return os;
}
#ifdef DEBUG
#define dump(...) \
(cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) << " [" << __LINE__ << "]" \
<< endl)
#else
#define dump(...)
#endif
int const inf = (1LL << 31) - 1;
int const B = 1024;
struct RMQ {
int n;
vector<int> Bmin;
vector<vector<int>> dat;
RMQ(int n_) {
n = n_;
if (n % B)
n += B - n % B;
dat.assign(n / B, vector<int>(B, inf));
Bmin.assign(n / B, inf);
}
void set(int idx, int x) {
get(idx) = x;
Bmin[idx / B] = inf;
for (int i = 0; i < B; i++)
Bmin[idx / B] = min(Bmin[idx / B], get(idx / B * B + i));
}
int &get(int idx) { return dat[idx / B][idx % B]; }
int rmq(int l, int r) {
int res = inf;
if (l / B != r / B) {
while (l % B) {
res = min(res, get(l));
l++;
}
while (r % B) {
r--;
res = min(res, get(--r));
}
while (l < r) {
res = min(res, Bmin[l / B]);
l += B;
}
} else {
while (l < r) {
res = min(res, get(l));
l++;
}
}
return res;
}
};
int main() {
int n, q;
cin >> n >> q;
RMQ rmq(n);
rep(i, q) {
int c, x, y;
cin >> c >> x >> y;
if (c)
cout << rmq.rmq(x, y + 1) << endl;
else
rmq.set(x, y);
}
}
|
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template <class T> ostream &operator<<(ostream &os, vector<T> const &);
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
tuple<T...> const &t) {
os << (n == 0 ? "" : " ") << get<n>(t);
_ot<n + 1>(os, t);
}
template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) {
_ot<0>(os, t);
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
return os;
}
#ifdef DEBUG
#define dump(...) \
(cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) << " [" << __LINE__ << "]" \
<< endl)
#else
#define dump(...)
#endif
int const inf = (1LL << 31) - 1;
int const B = 1024;
struct RMQ {
int n;
vector<int> Bmin;
vector<vector<int>> dat;
RMQ(int n_) {
n = n_;
if (n % B)
n += B - n % B;
dat.assign(n / B, vector<int>(B, inf));
Bmin.assign(n / B, inf);
}
void set(int idx, int x) {
get(idx) = x;
Bmin[idx / B] = inf;
for (int i = 0; i < B; i++)
Bmin[idx / B] = min(Bmin[idx / B], get(idx / B * B + i));
}
int &get(int idx) { return dat[idx / B][idx % B]; }
int rmq(int l, int r) {
int res = inf;
if (l / B != r / B) {
while (l % B) {
res = min(res, get(l));
l++;
}
while (r % B) {
r--;
res = min(res, get(r));
}
while (l < r) {
res = min(res, Bmin[l / B]);
l += B;
}
} else {
while (l < r) {
res = min(res, get(l));
l++;
}
}
return res;
}
};
int main() {
int n, q;
cin >> n >> q;
RMQ rmq(n);
rep(i, q) {
int c, x, y;
cin >> c >> x >> y;
if (c)
cout << rmq.rmq(x, y + 1) << endl;
else
rmq.set(x, y);
}
}
|
replace
| 74 | 75 | 74 | 75 |
0
| |
p02345
|
C++
|
Time Limit Exceeded
|
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) begin(c), end(c)
#define range(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) range(i, 0, b)
#define rangei(i, a, b) for (ll a = a; i <= ll(b); i++)
#define repi(i, b) rangei(i, 1, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template <class T> ostream &operator<<(ostream &os, vector<T> const &);
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
tuple<T...> const &t) {
os << (n == 0 ? "" : " ") << get<n>(t);
_ot<n + 1>(os, t);
}
template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) {
_ot<0>(os, t);
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
os << "{ ";
rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? " " : ", ");
return os << "}";
}
#ifdef DEBUG
#define dump(...) \
(cerr << "\x1b[32m" << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) << " [" \
<< __LINE__ << "]\x1b[0m" << endl)
#else
#define dump(...)
#endif
void fastios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// #define endl '\n'
}
template <class T> size_t uniq(vector<T> &v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
return v.size();
}
template <class T> size_t uniq(T *l, size_t n) {
sort(l, l + n);
return unique(l, l + n) - l;
}
#define mems(arr, val) memset(arr, val, sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max() / 8;
template <class T> class SqrtDecomp {
// private:
public:
const size_t B;
T const initVal;
size_t _size;
vector<T> rangeVal, elemVal;
public:
SqrtDecomp(const size_t size = 0, T const &initVal = numeric_limits<T>::max(),
const size_t rangeSize = 3)
: B(rangeSize), initVal(initVal), _size(size),
rangeVal(size / B + 1, initVal), elemVal(size, initVal) {}
size_t size() const { return _size; }
T getMin(size_t l, const size_t r) const {
T res = numeric_limits<T>::max();
while (l < r) {
if (l % B == 0 && l + B <= r) {
res = min(res, rangeVal[l / B]);
l += B;
} else {
res = min(res, elemVal[l]);
l++;
}
}
return res;
}
void setVal(const size_t p, const T &x) {
elemVal[p] = x;
rangeVal[p / B] = initVal;
size_t l = p - p % B;
size_t r = l + B;
size_t s = l / B;
for (size_t i = l; i < min(r, size()); i++) {
rangeVal[s] = min(rangeVal[s], elemVal[i]);
}
}
vector<T> to_a(int l = -1, int r = -1) {
if (l == -1)
l = 0;
if (r == -1)
r = size();
vector<T> res(r - l);
for (int i = l; i < r; i++)
res[i - l] = getMin(i, i + 1);
return res;
}
};
vector<int> naive(int n, int q, const vi &a, const vi &b, const vi &c) {
vector<int> ans;
vector<int> arr(n, (1LL << 31) - 1);
for (int i = 0; i < q; i++) {
if (a[i] == 0) {
arr[b[i]] = c[i];
} else {
int res = (1LL << 31) - 1;
for (int j = b[i]; j <= c[i]; j++) {
res = min(res, arr[j]);
}
ans.push_back(res);
}
}
return ans;
}
vector<int> solve(int n, int q, const vi &a, const vi &b, const vi &c) {
vector<int> ans;
SqrtDecomp<int32_t> rmq(n, (1LL << 31) - 1);
for (int i = 0; i < q; i++) {
if (a[i] == 0) {
rmq.setVal(b[i], c[i]);
} else {
ans.push_back(rmq.getMin(b[i], c[i] + 1));
}
}
return ans;
}
tuple<int, int, vi, vi, vi> generate() {
int n = rand() % 10 + 1;
int q = 3;
vector<int> a(q), b(q), c(q);
rep(i, q) {
a[i] = rand() % 2;
if (a[i] == 0) {
b[i] = rand() % n;
c[i] = rand() % 10;
} else {
b[i] = rand() % n;
c[i] = rand() % n;
if (b[i] > c[i])
swap(b[i], c[i]);
}
}
return make_tuple(n, q, a, b, c);
}
int main() {
int n, q;
cin >> n >> q;
vector<int> a(q), b(q), c(q);
rep(i, q) cin >> a[i] >> b[i] >> c[i];
auto ans = solve(n, q, a, b, c);
rep(i, ans.size()) cout << ans[i] << endl;
}
// int main(){
// srand(time(0));
// rep(i,1000000){
// int n,q;
// vector<int> a,b,c;
// tie(n,q,a,b,c) = generate();
// // a = { 0, 0, 1 };
// // b = { 3, 3, 3 };
// // c = { 2, 3, 6 };
// // n = 8, q = 3;
// vector<int> res = solve(n,q,a,b,c);
// vector<int> exp = naive(n,q,a,b,c);
// if(res != exp){
// dump(res);
// dump(exp);
// dump(n);
// dump(q);
// dump(a);
// dump(b);
// dump(c);
// abort();
// }
// }
// }
|
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) begin(c), end(c)
#define range(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) range(i, 0, b)
#define rangei(i, a, b) for (ll a = a; i <= ll(b); i++)
#define repi(i, b) rangei(i, 1, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template <class T> ostream &operator<<(ostream &os, vector<T> const &);
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
tuple<T...> const &t) {
os << (n == 0 ? "" : " ") << get<n>(t);
_ot<n + 1>(os, t);
}
template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) {
_ot<0>(os, t);
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
os << "{ ";
rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? " " : ", ");
return os << "}";
}
#ifdef DEBUG
#define dump(...) \
(cerr << "\x1b[32m" << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) << " [" \
<< __LINE__ << "]\x1b[0m" << endl)
#else
#define dump(...)
#endif
void fastios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// #define endl '\n'
}
template <class T> size_t uniq(vector<T> &v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
return v.size();
}
template <class T> size_t uniq(T *l, size_t n) {
sort(l, l + n);
return unique(l, l + n) - l;
}
#define mems(arr, val) memset(arr, val, sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max() / 8;
template <class T> class SqrtDecomp {
// private:
public:
const size_t B;
T const initVal;
size_t _size;
vector<T> rangeVal, elemVal;
public:
SqrtDecomp(const size_t size = 0, T const &initVal = numeric_limits<T>::max(),
const size_t rangeSize = 310)
: B(rangeSize), initVal(initVal), _size(size),
rangeVal(size / B + 1, initVal), elemVal(size, initVal) {}
size_t size() const { return _size; }
T getMin(size_t l, const size_t r) const {
T res = numeric_limits<T>::max();
while (l < r) {
if (l % B == 0 && l + B <= r) {
res = min(res, rangeVal[l / B]);
l += B;
} else {
res = min(res, elemVal[l]);
l++;
}
}
return res;
}
void setVal(const size_t p, const T &x) {
elemVal[p] = x;
rangeVal[p / B] = initVal;
size_t l = p - p % B;
size_t r = l + B;
size_t s = l / B;
for (size_t i = l; i < min(r, size()); i++) {
rangeVal[s] = min(rangeVal[s], elemVal[i]);
}
}
vector<T> to_a(int l = -1, int r = -1) {
if (l == -1)
l = 0;
if (r == -1)
r = size();
vector<T> res(r - l);
for (int i = l; i < r; i++)
res[i - l] = getMin(i, i + 1);
return res;
}
};
vector<int> naive(int n, int q, const vi &a, const vi &b, const vi &c) {
vector<int> ans;
vector<int> arr(n, (1LL << 31) - 1);
for (int i = 0; i < q; i++) {
if (a[i] == 0) {
arr[b[i]] = c[i];
} else {
int res = (1LL << 31) - 1;
for (int j = b[i]; j <= c[i]; j++) {
res = min(res, arr[j]);
}
ans.push_back(res);
}
}
return ans;
}
vector<int> solve(int n, int q, const vi &a, const vi &b, const vi &c) {
vector<int> ans;
SqrtDecomp<int32_t> rmq(n, (1LL << 31) - 1);
for (int i = 0; i < q; i++) {
if (a[i] == 0) {
rmq.setVal(b[i], c[i]);
} else {
ans.push_back(rmq.getMin(b[i], c[i] + 1));
}
}
return ans;
}
tuple<int, int, vi, vi, vi> generate() {
int n = rand() % 10 + 1;
int q = 3;
vector<int> a(q), b(q), c(q);
rep(i, q) {
a[i] = rand() % 2;
if (a[i] == 0) {
b[i] = rand() % n;
c[i] = rand() % 10;
} else {
b[i] = rand() % n;
c[i] = rand() % n;
if (b[i] > c[i])
swap(b[i], c[i]);
}
}
return make_tuple(n, q, a, b, c);
}
int main() {
int n, q;
cin >> n >> q;
vector<int> a(q), b(q), c(q);
rep(i, q) cin >> a[i] >> b[i] >> c[i];
auto ans = solve(n, q, a, b, c);
rep(i, ans.size()) cout << ans[i] << endl;
}
// int main(){
// srand(time(0));
// rep(i,1000000){
// int n,q;
// vector<int> a,b,c;
// tie(n,q,a,b,c) = generate();
// // a = { 0, 0, 1 };
// // b = { 3, 3, 3 };
// // c = { 2, 3, 6 };
// // n = 8, q = 3;
// vector<int> res = solve(n,q,a,b,c);
// vector<int> exp = naive(n,q,a,b,c);
// if(res != exp){
// dump(res);
// dump(exp);
// dump(n);
// dump(q);
// dump(a);
// dump(b);
// dump(c);
// abort();
// }
// }
// }
|
replace
| 76 | 77 | 76 | 77 |
TLE
| |
p02345
|
C++
|
Time Limit Exceeded
|
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) begin(c), end(c)
#define range(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) range(i, 0, b)
#define rangei(i, a, b) for (ll a = a; i <= ll(b); i++)
#define repi(i, b) rangei(i, 1, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template <class T> ostream &operator<<(ostream &os, vector<T> const &);
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
tuple<T...> const &t) {
os << (n == 0 ? "" : " ") << get<n>(t);
_ot<n + 1>(os, t);
}
template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) {
_ot<0>(os, t);
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
os << "{ ";
rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? " " : ", ");
return os << "}";
}
#ifdef DEBUG
#define dump(...) \
(cerr << "\x1b[32m" << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) << " [" \
<< __LINE__ << "]\x1b[0m" << endl)
#else
#define dump(...)
#endif
void fastios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// #define endl '\n'
}
template <class T> size_t uniq(vector<T> &v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
return v.size();
}
template <class T> size_t uniq(T *l, size_t n) {
sort(l, l + n);
return unique(l, l + n) - l;
}
#define mems(arr, val) memset(arr, val, sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max() / 8;
template <class T> class SqrtDecomp {
// private:
public:
const size_t B;
T const initVal;
size_t _size;
vector<T> rangeVal, elemVal;
public:
SqrtDecomp(const size_t size = 0, T const &initVal = numeric_limits<T>::max(),
const size_t rangeSize = 1)
: B(rangeSize), initVal(initVal), _size(size),
rangeVal(size / B + 1, initVal), elemVal(size, initVal) {}
size_t size() const { return _size; }
T getMin(size_t l, const size_t &r) const {
T res = numeric_limits<T>::max();
while (l < r) {
if (l % B == 0 && l + B <= r) {
res = min(res, rangeVal[l / B]);
l += B;
} else {
res = min(res, elemVal[l]);
l++;
}
}
return res;
}
void setVal(const size_t p, const T &x) {
elemVal[p] = x;
rangeVal[p / B] = initVal;
size_t l = p - p % B, r = l + B, s = l / B;
for (size_t i = l; i < min(r, size()); i++) {
rangeVal[s] = min(rangeVal[s], elemVal[i]);
}
}
vector<T> to_a(int l = -1, int r = -1) {
if (l == -1)
l = 0;
if (r == -1)
r = size();
vector<T> res(r - l);
for (int i = l; i < r; i++)
res[i - l] = getMin(i, i + 1);
return res;
}
};
vector<int> naive(int n, int q, const vi &a, const vi &b, const vi &c) {
vector<int> ans;
vector<int> arr(n, (1LL << 31) - 1);
for (int i = 0; i < q; i++) {
if (a[i] == 0) {
arr[b[i]] = c[i];
} else {
int res = (1LL << 31) - 1;
for (int j = b[i]; j <= c[i]; j++) {
res = min(res, arr[j]);
}
ans.push_back(res);
}
}
return ans;
}
vector<int> solve(int n, int q, const vi &a, const vi &b, const vi &c) {
vector<int> ans;
SqrtDecomp<int32_t> rmq(n, (1LL << 31) - 1);
for (int i = 0; i < q; i++) {
if (a[i] == 0) {
rmq.setVal(b[i], c[i]);
} else {
ans.push_back(rmq.getMin(b[i], c[i] + 1));
}
}
return ans;
}
tuple<int, int, vi, vi, vi> generate() {
int n = rand() % 10 + 1;
int q = 3;
vector<int> a(q), b(q), c(q);
rep(i, q) {
a[i] = rand() % 2;
if (a[i] == 0) {
b[i] = rand() % n;
c[i] = rand() % 10;
} else {
b[i] = rand() % n;
c[i] = rand() % n;
if (b[i] > c[i])
swap(b[i], c[i]);
}
}
return make_tuple(n, q, a, b, c);
}
int main() {
fastios();
int n, q;
cin >> n >> q;
vector<int> a(q), b(q), c(q);
rep(i, q) cin >> a[i] >> b[i] >> c[i];
auto ans = solve(n, q, a, b, c);
rep(i, ans.size()) cout << ans[i] << '\n';
}
// int main(){
// srand(time(0));
// rep(i,1000000){
// int n,q;
// vector<int> a,b,c;
// tie(n,q,a,b,c) = generate();
// // a = { 0, 0, 1 };
// // b = { 3, 3, 3 };
// // c = { 2, 3, 6 };
// // n = 8, q = 3;
// vector<int> res = solve(n,q,a,b,c);
// vector<int> exp = naive(n,q,a,b,c);
// if(res != exp){
// dump(res);
// dump(exp);
// dump(n);
// dump(q);
// dump(a);
// dump(b);
// dump(c);
// abort();
// }
// }
// }
|
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) begin(c), end(c)
#define range(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) range(i, 0, b)
#define rangei(i, a, b) for (ll a = a; i <= ll(b); i++)
#define repi(i, b) rangei(i, 1, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template <class T> ostream &operator<<(ostream &os, vector<T> const &);
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
tuple<T...> const &t) {
os << (n == 0 ? "" : " ") << get<n>(t);
_ot<n + 1>(os, t);
}
template <class... T> ostream &operator<<(ostream &os, tuple<T...> const &t) {
_ot<0>(os, t);
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
return os << "(" << p.first << ", " << p.second << ") ";
}
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
os << "{ ";
rep(i, v.size()) os << v[i] << (i + 1 == (int)v.size() ? " " : ", ");
return os << "}";
}
#ifdef DEBUG
#define dump(...) \
(cerr << "\x1b[32m" << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) << " [" \
<< __LINE__ << "]\x1b[0m" << endl)
#else
#define dump(...)
#endif
void fastios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// #define endl '\n'
}
template <class T> size_t uniq(vector<T> &v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
return v.size();
}
template <class T> size_t uniq(T *l, size_t n) {
sort(l, l + n);
return unique(l, l + n) - l;
}
#define mems(arr, val) memset(arr, val, sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max() / 8;
template <class T> class SqrtDecomp {
// private:
public:
const size_t B;
T const initVal;
size_t _size;
vector<T> rangeVal, elemVal;
public:
SqrtDecomp(const size_t size = 0, T const &initVal = numeric_limits<T>::max(),
const size_t rangeSize = 500)
: B(rangeSize), initVal(initVal), _size(size),
rangeVal(size / B + 1, initVal), elemVal(size, initVal) {}
size_t size() const { return _size; }
T getMin(size_t l, const size_t &r) const {
T res = numeric_limits<T>::max();
while (l < r) {
if (l % B == 0 && l + B <= r) {
res = min(res, rangeVal[l / B]);
l += B;
} else {
res = min(res, elemVal[l]);
l++;
}
}
return res;
}
void setVal(const size_t p, const T &x) {
elemVal[p] = x;
rangeVal[p / B] = initVal;
size_t l = p - p % B, r = l + B, s = l / B;
for (size_t i = l; i < min(r, size()); i++) {
rangeVal[s] = min(rangeVal[s], elemVal[i]);
}
}
vector<T> to_a(int l = -1, int r = -1) {
if (l == -1)
l = 0;
if (r == -1)
r = size();
vector<T> res(r - l);
for (int i = l; i < r; i++)
res[i - l] = getMin(i, i + 1);
return res;
}
};
vector<int> naive(int n, int q, const vi &a, const vi &b, const vi &c) {
vector<int> ans;
vector<int> arr(n, (1LL << 31) - 1);
for (int i = 0; i < q; i++) {
if (a[i] == 0) {
arr[b[i]] = c[i];
} else {
int res = (1LL << 31) - 1;
for (int j = b[i]; j <= c[i]; j++) {
res = min(res, arr[j]);
}
ans.push_back(res);
}
}
return ans;
}
vector<int> solve(int n, int q, const vi &a, const vi &b, const vi &c) {
vector<int> ans;
SqrtDecomp<int32_t> rmq(n, (1LL << 31) - 1);
for (int i = 0; i < q; i++) {
if (a[i] == 0) {
rmq.setVal(b[i], c[i]);
} else {
ans.push_back(rmq.getMin(b[i], c[i] + 1));
}
}
return ans;
}
tuple<int, int, vi, vi, vi> generate() {
int n = rand() % 10 + 1;
int q = 3;
vector<int> a(q), b(q), c(q);
rep(i, q) {
a[i] = rand() % 2;
if (a[i] == 0) {
b[i] = rand() % n;
c[i] = rand() % 10;
} else {
b[i] = rand() % n;
c[i] = rand() % n;
if (b[i] > c[i])
swap(b[i], c[i]);
}
}
return make_tuple(n, q, a, b, c);
}
int main() {
fastios();
int n, q;
cin >> n >> q;
vector<int> a(q), b(q), c(q);
rep(i, q) cin >> a[i] >> b[i] >> c[i];
auto ans = solve(n, q, a, b, c);
rep(i, ans.size()) cout << ans[i] << '\n';
}
// int main(){
// srand(time(0));
// rep(i,1000000){
// int n,q;
// vector<int> a,b,c;
// tie(n,q,a,b,c) = generate();
// // a = { 0, 0, 1 };
// // b = { 3, 3, 3 };
// // c = { 2, 3, 6 };
// // n = 8, q = 3;
// vector<int> res = solve(n,q,a,b,c);
// vector<int> exp = naive(n,q,a,b,c);
// if(res != exp){
// dump(res);
// dump(exp);
// dump(n);
// dump(q);
// dump(a);
// dump(b);
// dump(c);
// abort();
// }
// }
// }
|
replace
| 76 | 77 | 76 | 77 |
TLE
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
int n, q;
const int N = 100010;
const int INF = (1LL << 31LL) - 1;
int dat[2 * N - 1];
void init(int n_) {
n = 1;
while (n_ > n)
n *= 2;
for (int i = 0; i < n * 2 - 1; ++i)
dat[i] = INF;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return dat[k];
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> q;
init(n);
int c, x, y;
for (int i = 0; i < q; ++i) {
cin >> c >> x >> y;
if (c == 0)
update(x, y);
else {
y++;
cout << query(x, y, 0, 0, n) << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int n, q;
const int N = 1 << 17;
const int INF = (1LL << 31LL) - 1;
int dat[2 * N - 1];
void init(int n_) {
n = 1;
while (n_ > n)
n *= 2;
for (int i = 0; i < n * 2 - 1; ++i)
dat[i] = INF;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return dat[k];
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> q;
init(n);
int c, x, y;
for (int i = 0; i < q; ++i) {
cin >> c >> x >> y;
if (c == 0)
update(x, y);
else {
y++;
cout << query(x, y, 0, 0, n) << endl;
}
}
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <stdio.h>
using namespace std;
int n, q;
int a[400005], b[400005], com[400005], c[400005], d[400005];
int N = 2147483648 - 1;
int sa;
void update(int x, int y) {
x += sa;
a[x] = y;
while (x > 0) {
x = (x - 1) / 2;
a[x] = min(a[x * 2 + 1], a[x * 2 + 2]);
}
}
int find(int x, int z, int k, int l, int r) {
if (x <= l && r <= z) {
return a[k];
}
if (r <= x || z <= l)
return N;
else {
int vl = find(x, z, k * 2 + 1, l, (l + r) / 2);
int vr = find(x, z, k * 2 + 2, (l + r) / 2, r);
// printf("%d %d %d\n",k,vl,vr);
return min(vl, vr);
}
}
int pow(int x) {
int i = 1;
while (true) {
if (i <= x && x < (i * 2))
return (i * 2);
else
i *= 2;
}
}
int main() {
scanf("%d%d", &n, &q);
for (int i = 0; i < q; i++) {
scanf("%d%d%d", &com[i], &c[i], &d[i]);
}
sa = pow(n) - 1;
int ni = 4 * sa;
for (int i = 0; i < ni; i++) {
a[i] = N;
}
for (int i = 0; i < q; i++) {
if (com[i] == 0) {
update(c[i], d[i]);
} else {
printf("%d\n", (find(c[i], d[i] + 1, 0, 0, sa + 1)));
}
}
return 0;
}
|
#include <algorithm>
#include <stdio.h>
using namespace std;
int n, q;
int a[4000005], com[4000005], c[4000005], d[4000005];
int N = 2147483648 - 1;
int sa;
void update(int x, int y) {
x += sa;
a[x] = y;
while (x > 0) {
x = (x - 1) / 2;
a[x] = min(a[x * 2 + 1], a[x * 2 + 2]);
}
}
int find(int x, int z, int k, int l, int r) {
if (x <= l && r <= z) {
return a[k];
}
if (r <= x || z <= l)
return N;
else {
int vl = find(x, z, k * 2 + 1, l, (l + r) / 2);
int vr = find(x, z, k * 2 + 2, (l + r) / 2, r);
// printf("%d %d %d\n",k,vl,vr);
return min(vl, vr);
}
}
int pow(int x) {
int i = 1;
while (true) {
if (i <= x && x < (i * 2))
return (i * 2);
else
i *= 2;
}
}
int main() {
scanf("%d%d", &n, &q);
for (int i = 0; i < q; i++) {
scanf("%d%d%d", &com[i], &c[i], &d[i]);
}
sa = pow(n) - 1;
int ni = 4 * sa;
for (int i = 0; i < ni; i++) {
a[i] = N;
}
for (int i = 0; i < q; i++) {
if (com[i] == 0) {
update(c[i], d[i]);
} else {
printf("%d\n", (find(c[i], d[i] + 1, 0, 0, sa + 1)));
}
}
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
int st[1 << 17];
void init(int n) {
int nn = 1;
while (nn < n)
nn *= 2;
fill(st, st + 2 * nn - 1, INF);
}
void update(int i, int a, int k, int l, int r) {
if (i < l || r <= i)
return;
if (r - l == 1)
st[k] = a;
else {
int chl = 2 * k + 1;
int chr = 2 * k + 2;
update(i, a, chl, l, (l + r) / 2);
update(i, a, chr, (l + r) / 2, r);
st[k] = min(st[chl], st[chr]);
}
}
int find(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return st[k];
int res_l = find(a, b, 2 * k + 1, l, (l + r) / 2);
int res_r = find(a, b, 2 * k + 2, (l + r) / 2, r);
return min(res_l, res_r);
}
int main() {
int n, q;
scanf("%d%d", &n, &q);
init(n);
for (int i = 0; i < q; i++) {
int c, x, y;
scanf("%d%d%d", &c, &x, &y);
if (c == 0) {
update(x, y, 0, 0, n);
} else {
int ret = find(x, y + 1, 0, 0, n);
printf("%d\n", ret);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
int st[1 << 18];
void init(int n) {
int nn = 1;
while (nn < n)
nn *= 2;
fill(st, st + 2 * nn - 1, INF);
}
void update(int i, int a, int k, int l, int r) {
if (i < l || r <= i)
return;
if (r - l == 1)
st[k] = a;
else {
int chl = 2 * k + 1;
int chr = 2 * k + 2;
update(i, a, chl, l, (l + r) / 2);
update(i, a, chr, (l + r) / 2, r);
st[k] = min(st[chl], st[chr]);
}
}
int find(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return st[k];
int res_l = find(a, b, 2 * k + 1, l, (l + r) / 2);
int res_r = find(a, b, 2 * k + 2, (l + r) / 2, r);
return min(res_l, res_r);
}
int main() {
int n, q;
scanf("%d%d", &n, &q);
init(n);
for (int i = 0; i < q; i++) {
int c, x, y;
scanf("%d%d%d", &c, &x, &y);
if (c == 0) {
update(x, y, 0, 0, n);
} else {
int ret = find(x, y + 1, 0, 0, n);
printf("%d\n", ret);
}
}
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, int M> struct RMQ {
T arr[M];
T INF;
int N;
RMQ(int N_, T INF_) {
INF = INF_;
for (int j = 0; j < 2 * M; ++j) {
arr[j] = INF;
}
N = 1;
while (N < N_)
N *= 2;
}
void update(int x, int a) {
int ind = N - 1 + x;
arr[ind] = a;
while (ind > 0) {
ind = (ind - 1) / 2;
arr[ind] = min(arr[ind * 2 + 1], arr[ind * 2 + 2]);
}
}
T query(int x, int y) { return query_(x, y, 0, 0, N); }
T query_(int x, int y, int v, int l, int r) {
if (y <= l || r <= x)
return INF;
if (x <= l && r <= y)
return arr[v];
T vl = query_(x, y, 2 * v + 1, l, (l + r) / 2);
T vr = query_(x, y, 2 * v + 2, (l + r) / 2, r);
return vl < vr ? vl : vr;
}
};
int main() {
int n, q;
cin >> n >> q;
RMQ<int, 300000> rmq(n, ((1 << 30) - 1) * 2 + 1);
for (int j = 0; j < q; ++j) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
rmq.update(x, y);
}
if (com == 1) {
int res = rmq.query(x, y + 1);
cout << res << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, int M> struct RMQ {
T arr[M];
T INF;
int N;
RMQ(int N_, T INF_) {
INF = INF_;
for (int j = 0; j < M; ++j) {
arr[j] = INF;
}
N = 1;
while (N < N_)
N *= 2;
}
void update(int x, int a) {
int ind = N - 1 + x;
arr[ind] = a;
while (ind > 0) {
ind = (ind - 1) / 2;
arr[ind] = min(arr[ind * 2 + 1], arr[ind * 2 + 2]);
}
}
T query(int x, int y) { return query_(x, y, 0, 0, N); }
T query_(int x, int y, int v, int l, int r) {
if (y <= l || r <= x)
return INF;
if (x <= l && r <= y)
return arr[v];
T vl = query_(x, y, 2 * v + 1, l, (l + r) / 2);
T vr = query_(x, y, 2 * v + 2, (l + r) / 2, r);
return vl < vr ? vl : vr;
}
};
int main() {
int n, q;
cin >> n >> q;
RMQ<int, 300000> rmq(n, ((1 << 30) - 1) * 2 + 1);
for (int j = 0; j < q; ++j) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
rmq.update(x, y);
}
if (com == 1) {
int res = rmq.query(x, y + 1);
cout << res << endl;
}
}
return 0;
}
|
replace
| 10 | 11 | 10 | 11 |
-11
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 2147483647;
int n, dat[2 * MAX];
void init(int m) {
n = 1;
while (n < m)
n *= 2;
for (int i = 0; i < 2 * n; i++)
dat[i] = inf;
}
void change(int x, int y) {
x += n - 1;
dat[x] = y;
while (x > 0) {
x = (x - 1) / 2;
dat[x] = min(dat[x * 2 + 1], dat[x * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (b <= l || r <= a)
return inf;
if (a <= l && r <= b)
return dat[k];
int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
int main() {
int m, q, c, x, y, ans;
scanf("%d%d", &m, &q);
init(m);
while (q--) {
scanf("%d%d%d", &c, &x, &y);
if (!c)
change(x, y);
else
printf("%d\n", query(x, y + 1, 0, 0, n));
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define INF 100000005
#define MAX 100001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int, int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 2147483647;
int n, dat[10 * MAX];
void init(int m) {
n = 1;
while (n < m)
n *= 2;
for (int i = 0; i < 2 * n; i++)
dat[i] = inf;
}
void change(int x, int y) {
x += n - 1;
dat[x] = y;
while (x > 0) {
x = (x - 1) / 2;
dat[x] = min(dat[x * 2 + 1], dat[x * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (b <= l || r <= a)
return inf;
if (a <= l && r <= b)
return dat[k];
int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
int main() {
int m, q, c, x, y, ans;
scanf("%d%d", &m, &q);
init(m);
while (q--) {
scanf("%d%d%d", &c, &x, &y);
if (!c)
change(x, y);
else
printf("%d\n", query(x, y + 1, 0, 0, n));
}
return 0;
}
|
replace
| 16 | 17 | 16 | 17 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
#define MAX_N 100001
int N, dat[2 * MAX_N - 1];
static const int maxi = pow(2, 31) - 1;
void init(int n) {
N = 1;
while (N < n)
N *= 2;
fill_n(dat, 2 * N - 1, maxi);
}
void update(int k, int a) {
k += N - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return maxi;
if (a <= l && r <= b)
return dat[k];
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
void printv(int v[], int len) {
for (int i = 0; i < len; i++)
cout << " " << v[i];
cout << endl;
}
int main() {
int n, q, com, x, y;
cin >> n >> q;
init(n);
while (q-- > 0) {
// printv(dat, N);
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else
cout << query(x, y + 1, 0, 0, N) << endl;
;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
#define MAX_N 200000
int N, dat[2 * MAX_N - 1];
static const int maxi = pow(2, 31) - 1;
void init(int n) {
N = 1;
while (N < n)
N *= 2;
fill_n(dat, 2 * N - 1, maxi);
}
void update(int k, int a) {
k += N - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return maxi;
if (a <= l && r <= b)
return dat[k];
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
void printv(int v[], int len) {
for (int i = 0; i < len; i++)
cout << " " << v[i];
cout << endl;
}
int main() {
int n, q, com, x, y;
cin >> n >> q;
init(n);
while (q-- > 0) {
// printv(dat, N);
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else
cout << query(x, y + 1, 0, 0, N) << endl;
;
}
return 0;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <iostream>
#include <limits.h>
using namespace std;
int inf = INT_MAX;
int dat[200001];
int n, q;
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = inf;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
// cout << a<< b<< k<<l<<r <<endl;
if (r <= a || b <= l)
return inf;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
// cout << vl << ":" <<vr << endl;
return min(vl, vr);
}
}
int find(int x, int y) { return query(x, y, 0, 0, n); }
int main() {
int n_;
cin >> n_ >> q;
init(n_);
// cout << n <<endl;
int i, j;
for (i = 0; i < q; i++) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else if (x == y)
cout << dat[x + n - 1] << endl;
else
cout << find(x, y + 1) << endl;
/*
for(j=0;j<n*2-1;j++) cout << dat[j] << ":";
cout << endl;
*/
}
return 0;
}
|
#include <iostream>
#include <limits.h>
using namespace std;
int inf = INT_MAX;
int dat[400004];
int n, q;
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = inf;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
// cout << a<< b<< k<<l<<r <<endl;
if (r <= a || b <= l)
return inf;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
// cout << vl << ":" <<vr << endl;
return min(vl, vr);
}
}
int find(int x, int y) { return query(x, y, 0, 0, n); }
int main() {
int n_;
cin >> n_ >> q;
init(n_);
// cout << n <<endl;
int i, j;
for (i = 0; i < q; i++) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else if (x == y)
cout << dat[x + n - 1] << endl;
else
cout << find(x, y + 1) << endl;
/*
for(j=0;j<n*2-1;j++) cout << dat[j] << ":";
cout << endl;
*/
}
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
#define rev(i, n) for (int i = (n); i > 0; --i)
#define INF (1e9 + 1e9)
/* SegTree
http://codeforces.com/blog/entry/18051
*/
class SegTree {
public:
vector<int> t;
int n;
SegTree(int n) : n(n) {
t.resize(1e5);
fill(t.begin(), t.end(), INT_MAX);
build();
}
void build() { rev(i, n - 1) t[i] = min(t[i << 1], t[i << 1 | 1]); }
void modify(int p, int value) {
for (t[p += n] = value; p > 1; p >>= 1)
t[p >> 1] = min(t[p], t[p ^ 1]);
}
int query(int l, int r) { // [l,r)
int res = INT_MAX;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
res = min(res, t[l++]);
if (r & 1)
res = min(res, t[--r]);
}
return res;
}
};
int main() {
int N, Q;
cin >> N >> Q;
SegTree st(N);
vector<int> C, X, Y;
rep(i, Q) {
int c, x, y;
cin >> c >> x >> y;
C.pb(c);
X.pb(x);
Y.pb(y);
}
rep(i, Q) if (C[i] == 0) st.modify(X[i], Y[i]);
else cout << st.query(X[i], Y[i] + 1) << endl;
}
|
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
#define rev(i, n) for (int i = (n); i > 0; --i)
#define INF (1e9 + 1e9)
/* SegTree
http://codeforces.com/blog/entry/18051
*/
class SegTree {
public:
vector<int> t;
int n;
SegTree(int n) : n(n) {
t.resize(n << 1);
fill(t.begin(), t.end(), INT_MAX);
build();
}
void build() { rev(i, n - 1) t[i] = min(t[i << 1], t[i << 1 | 1]); }
void modify(int p, int value) {
for (t[p += n] = value; p > 1; p >>= 1)
t[p >> 1] = min(t[p], t[p ^ 1]);
}
int query(int l, int r) { // [l,r)
int res = INT_MAX;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
res = min(res, t[l++]);
if (r & 1)
res = min(res, t[--r]);
}
return res;
}
};
int main() {
int N, Q;
cin >> N >> Q;
SegTree st(N);
vector<int> C, X, Y;
rep(i, Q) {
int c, x, y;
cin >> c >> x >> y;
C.pb(c);
X.pb(x);
Y.pb(y);
}
rep(i, Q) if (C[i] == 0) st.modify(X[i], Y[i]);
else cout << st.query(X[i], Y[i] + 1) << endl;
}
|
replace
| 27 | 28 | 27 | 28 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll LINF = 1e18;
struct edge {
int to, cost;
};
const int MAX_N = 1 << 17;
// const int F = 2147483647;//(int)(((ll)(2)<<31) -1);
const int F = (1LL << 31) - 1;
int n;
unsigned int dat[100000]; // セグメント木
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = F;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]); // RMQ以外はここを変える?
}
}
//[a,b)の最小値を求める
// kは接点の番号,l,rはその接点が[l,r)に対応していることを示す
// 呼ぶときはquery(a,b,0,0,n)
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return F;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int m, q;
cin >> m >> q;
init(m);
int com, x, y;
for (int i = 0; i < q; i++) {
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else
cout << query(x, y + 1, 0, 0, n) << "\n";
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll LINF = 1e18;
struct edge {
int to, cost;
};
const int MAX_N = 1 << 17;
// const int F = 2147483647;//(int)(((ll)(2)<<31) -1);
const int F = (1LL << 31) - 1;
int n;
unsigned int dat[1000000]; // セグメント木
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = F;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]); // RMQ以外はここを変える?
}
}
//[a,b)の最小値を求める
// kは接点の番号,l,rはその接点が[l,r)に対応していることを示す
// 呼ぶときはquery(a,b,0,0,n)
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return F;
if (a <= l && r <= b)
return dat[k];
else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int m, q;
cin >> m >> q;
init(m);
int com, x, y;
for (int i = 0; i < q; i++) {
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else
cout << query(x, y + 1, 0, 0, n) << "\n";
}
return 0;
}
|
replace
| 35 | 36 | 35 | 36 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
struct node {
int num, l, r, ls, rs;
node(int _l, int _r) {
num = INT_MAX;
l = _l;
r = _r;
}
};
vector<node> T;
int make(int l, int r) {
int id = T.size();
T.push_back(node(l, r));
T[id].ls = (l + 1 == r ? -1 : make(l, (l + r) / 2));
T[id].rs = (l + 1 == r ? -1 : make((l + r) / 2, r));
return id;
}
void update(int id, int x, int t) {
if (T[id].l + 1 == T[id].r) {
if (T[id].l == x)
T[id].num = t;
return;
}
int mid = (T[id].l + T[id].r) >> 1;
if (x < mid)
update(T[id].ls, x, t);
else
update(T[id].rs, x, t);
T[id].num = min(T[T[id].ls].num, T[T[id].rs].num);
}
int getmin(int id, int l, int r) {
if (l == r || T[id].l >= r || T[id].r <= l)
return INT_MAX;
if (T[id].l >= l && T[id].r <= r)
return T[id].num;
int mid = (T[id].l + T[id].r) >> 1, mi = INT_MAX;
if (l < mid)
mi = min(mi, getmin(T[id].ls, l, r));
if (r > mid)
mi = min(mi, getmin(T[id].rs, l, r));
return mi;
}
int main() {
freopen("in.txt", "r", stdin);
T.reserve(200100);
int n, q;
scanf("%d%d", &n, &q);
// printf("|\n");
make(0, n);
// printf("||\n");
for (int i = 0; i < q; i++) {
int com, x, y;
scanf("%d%d%d", &com, &x, &y);
if (com == 0)
update(0, x, y);
else
printf("%d\n", getmin(0, x, y + 1));
}
}
|
#include <bits/stdc++.h>
using namespace std;
struct node {
int num, l, r, ls, rs;
node(int _l, int _r) {
num = INT_MAX;
l = _l;
r = _r;
}
};
vector<node> T;
int make(int l, int r) {
int id = T.size();
T.push_back(node(l, r));
T[id].ls = (l + 1 == r ? -1 : make(l, (l + r) / 2));
T[id].rs = (l + 1 == r ? -1 : make((l + r) / 2, r));
return id;
}
void update(int id, int x, int t) {
if (T[id].l + 1 == T[id].r) {
if (T[id].l == x)
T[id].num = t;
return;
}
int mid = (T[id].l + T[id].r) >> 1;
if (x < mid)
update(T[id].ls, x, t);
else
update(T[id].rs, x, t);
T[id].num = min(T[T[id].ls].num, T[T[id].rs].num);
}
int getmin(int id, int l, int r) {
if (l == r || T[id].l >= r || T[id].r <= l)
return INT_MAX;
if (T[id].l >= l && T[id].r <= r)
return T[id].num;
int mid = (T[id].l + T[id].r) >> 1, mi = INT_MAX;
if (l < mid)
mi = min(mi, getmin(T[id].ls, l, r));
if (r > mid)
mi = min(mi, getmin(T[id].rs, l, r));
return mi;
}
int main() {
// freopen("in.txt","r",stdin);
T.reserve(200100);
int n, q;
scanf("%d%d", &n, &q);
// printf("|\n");
make(0, n);
// printf("||\n");
for (int i = 0; i < q; i++) {
int com, x, y;
scanf("%d%d%d", &com, &x, &y);
if (com == 0)
update(0, x, y);
else
printf("%d\n", getmin(0, x, y + 1));
}
}
|
replace
| 51 | 52 | 51 | 52 |
-11
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unordered_map>
#include <vector>
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MAX_N = 101000;
class SegTree {
public:
// セグメント木を持つグローバル変数
int n;
ll dat[2 * MAX_N - 1];
void init(int n_, ll init_num) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = init_num;
}
}
// k番目の値(0-indexed)をaに変更
void update(int k, ll a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// [a, b)の最小値を求める。
// kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。
// query(a, b, 0, 0, n)で外からは呼び出す。
ll query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) {
return (1LL << 31) - 1;
}
if (a <= l && r <= b) {
return dat[k];
} else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
};
int main() {
int n, q;
cin >> n >> q;
SegTree s;
s.init(n, (1LL << 31) - 1);
for (int i = 0; i < q; i++) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
s.update(x, y);
} else {
cout << s.query(x, y + 1, 0, 0, s.n) << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unordered_map>
#include <vector>
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MAX_N = 201000;
class SegTree {
public:
// セグメント木を持つグローバル変数
int n;
ll dat[2 * MAX_N - 1];
void init(int n_, ll init_num) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = init_num;
}
}
// k番目の値(0-indexed)をaに変更
void update(int k, ll a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// [a, b)の最小値を求める。
// kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。
// query(a, b, 0, 0, n)で外からは呼び出す。
ll query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) {
return (1LL << 31) - 1;
}
if (a <= l && r <= b) {
return dat[k];
} else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
};
int main() {
int n, q;
cin >> n >> q;
SegTree s;
s.init(n, (1LL << 31) - 1);
for (int i = 0; i < q; i++) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
s.update(x, y);
} else {
cout << s.query(x, y + 1, 0, 0, s.n) << endl;
}
}
return 0;
}
|
replace
| 24 | 25 | 24 | 25 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#define INF 2147483647
using namespace std;
int n, q;
int com;
int tree[211111];
void init();
void update(int i, int x);
int segtree_find(int x, int y, int now, int left, int right);
int main() {
scanf(" %d %d", &n, &q);
init();
for (int i = 0; i < q; i++) {
scanf(" %d", &com);
if (com) {
int x, y;
scanf(" %d %d", &x, &y);
printf("%d\n", segtree_find(x, y, 0, 0, n - 1));
} else {
int x, y;
scanf(" %d %d", &x, &y);
update(x, y);
}
}
return 0;
}
void init() {
int m = n;
n = 1;
while (n < m)
n = (n << 1);
fill(tree, tree + n * 2, INF);
return;
}
void update(int i, int x) {
i = i + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) / 2;
tree[i] = min(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
int segtree_find(int x, int y, int now, int left, int right) {
if (right < x || y < left)
return INF;
if (x <= left && right <= y)
return tree[now];
if (now > n * 2)
return -1;
int find_left = segtree_find(x, y, (now * 2 + 1), left, ((right + left) / 2));
int find_right =
segtree_find(x, y, (now * 2 + 2), ((right + left) / 2 + 1), right);
return min(find_left, find_right);
}
|
#include <algorithm>
#include <cstdio>
#define INF 2147483647
using namespace std;
int n, q;
int com;
int tree[2111111];
void init();
void update(int i, int x);
int segtree_find(int x, int y, int now, int left, int right);
int main() {
scanf(" %d %d", &n, &q);
init();
for (int i = 0; i < q; i++) {
scanf(" %d", &com);
if (com) {
int x, y;
scanf(" %d %d", &x, &y);
printf("%d\n", segtree_find(x, y, 0, 0, n - 1));
} else {
int x, y;
scanf(" %d %d", &x, &y);
update(x, y);
}
}
return 0;
}
void init() {
int m = n;
n = 1;
while (n < m)
n = (n << 1);
fill(tree, tree + n * 2, INF);
return;
}
void update(int i, int x) {
i = i + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) / 2;
tree[i] = min(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
int segtree_find(int x, int y, int now, int left, int right) {
if (right < x || y < left)
return INF;
if (x <= left && right <= y)
return tree[now];
if (now > n * 2)
return -1;
int find_left = segtree_find(x, y, (now * 2 + 1), left, ((right + left) / 2));
int find_right =
segtree_find(x, y, (now * 2 + 2), ((right + left) / 2 + 1), right);
return min(find_left, find_right);
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#define INF 2147483647
using namespace std;
int n, q;
int com;
int tree[251111];
void init();
void update(int i, int x);
int segtree_find(int x, int y, int now, int left, int right);
int main() {
scanf(" %d %d", &n, &q);
init();
for (int i = 0; i < q; i++) {
scanf(" %d", &com);
if (com) {
int x, y;
scanf(" %d %d", &x, &y);
printf("%d\n", segtree_find(x, y, 0, 0, n - 1));
} else {
int x, y;
scanf(" %d %d", &x, &y);
update(x, y);
}
}
return 0;
}
void init() {
int m = n;
n = 1;
while (n < m)
n = (n << 1);
fill(tree, tree + n * 2, INF);
return;
}
void update(int i, int x) {
i = i + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) / 2;
tree[i] = min(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
int segtree_find(int x, int y, int now, int left, int right) {
if (right < x || y < left)
return INF;
if (x <= left && right <= y)
return tree[now];
if (now > n * 2)
return -1;
int find_left = segtree_find(x, y, (now * 2 + 1), left, ((right + left) / 2));
int find_right =
segtree_find(x, y, (now * 2 + 2), ((right + left) / 2 + 1), right);
return min(find_left, find_right);
}
|
#include <algorithm>
#include <cstdio>
#define INF 2147483647
using namespace std;
int n, q;
int com;
int tree[411111];
void init();
void update(int i, int x);
int segtree_find(int x, int y, int now, int left, int right);
int main() {
scanf(" %d %d", &n, &q);
init();
for (int i = 0; i < q; i++) {
scanf(" %d", &com);
if (com) {
int x, y;
scanf(" %d %d", &x, &y);
printf("%d\n", segtree_find(x, y, 0, 0, n - 1));
} else {
int x, y;
scanf(" %d %d", &x, &y);
update(x, y);
}
}
return 0;
}
void init() {
int m = n;
n = 1;
while (n < m)
n = (n << 1);
fill(tree, tree + n * 2, INF);
return;
}
void update(int i, int x) {
i = i + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) / 2;
tree[i] = min(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
int segtree_find(int x, int y, int now, int left, int right) {
if (right < x || y < left)
return INF;
if (x <= left && right <= y)
return tree[now];
if (now > n * 2)
return -1;
int find_left = segtree_find(x, y, (now * 2 + 1), left, ((right + left) / 2));
int find_right =
segtree_find(x, y, (now * 2 + 2), ((right + left) / 2 + 1), right);
return min(find_left, find_right);
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <limits.h>
using namespace std;
#define INF (2147483647)
int n, q;
int com;
int pos, num;
int b, e;
int tree[211111];
void init();
int find(int x, int y, int now, int left, int right);
void update(int i, int x);
int main() {
scanf(" %d %d", &n, &q);
init();
for (int i = 0; i < q; i++) {
scanf(" %d", &com);
if (com) {
scanf(" %d %d", &b, &e);
printf("%d\n", find(b, e, 0, 0, n - 1));
} else {
scanf(" %d %d", &pos, &num);
update(pos, num);
}
}
}
void init() {
int m = n;
n = 1;
while (m > n)
n = (n << 1);
fill(tree, tree + n * 2, INF);
return;
}
void update(int i, int x) {
i = i + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) / 2;
tree[i] = min(tree[i * 2 + 1], tree[i * 2 + 2]);
}
}
int find(int x, int y, int now, int left, int right) {
if (right < x || y < left)
return INF;
if (x <= left && right <= y)
return tree[now];
int find_left = find(x, y, now * 2 + 1, left, (left + right) / 2);
int find_right = find(x, y, now * 2 + 2, (left + right) / 2 + 1, right);
return min(find_left, find_right);
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <limits.h>
using namespace std;
#define INF (2147483647)
int n, q;
int com;
int pos, num;
int b, e;
int tree[555555];
void init();
int find(int x, int y, int now, int left, int right);
void update(int i, int x);
int main() {
scanf(" %d %d", &n, &q);
init();
for (int i = 0; i < q; i++) {
scanf(" %d", &com);
if (com) {
scanf(" %d %d", &b, &e);
printf("%d\n", find(b, e, 0, 0, n - 1));
} else {
scanf(" %d %d", &pos, &num);
update(pos, num);
}
}
}
void init() {
int m = n;
n = 1;
while (m > n)
n = (n << 1);
fill(tree, tree + n * 2, INF);
return;
}
void update(int i, int x) {
i = i + n - 1;
tree[i] = x;
while (i > 0) {
i = (i - 1) / 2;
tree[i] = min(tree[i * 2 + 1], tree[i * 2 + 2]);
}
}
int find(int x, int y, int now, int left, int right) {
if (right < x || y < left)
return INF;
if (x <= left && right <= y)
return tree[now];
int find_left = find(x, y, now * 2 + 1, left, (left + right) / 2);
int find_right = find(x, y, now * 2 + 2, (left + right) / 2 + 1, right);
return min(find_left, find_right);
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
struct sqrt_decomposition {
using F = function<int(int, int)>;
int n, sz, len;
vector<int> v;
vector<int> w;
F f;
int e;
sqrt_decomposition(vector<int> _v, F _f, int _e) : v(_v), f(_f), e(_e) {
n = v.size();
sz = 1;
while ((sz + 1) * (sz + 1) < n)
++sz;
len = n / sz;
w.resize(len, e);
for (int i = 0; i < sz; ++i)
for (int j = 0; j < sz; ++j)
if (i * sz + j < n)
w[i] = f(w[i], v[i * sz + j]);
}
void point_set(int a, int x) {
v[a] = x;
int b = a / sz;
w[b] = e;
for (int i = 0; i < sz; ++i)
w[b] = f(w[b], v[b * sz + i]);
}
/* void range_set(int a, int b, int x){
while(a < b && a % sqrt_n != 0){
v[a] = x;
++a;
}
while(a + sqrt_n <= b){
w[a / sqrt_n] = x;
a += sqrt_n;
}
while(a < b){
v[a] = x;
++a;
}
}
*/
int point_get(int a) {
int b = a / sz;
return f(w[b], v[a]);
}
int range_get(int a, int b) {
int res = e;
while (a < b && a % sz != 0) {
res = f(res, v[a]);
++a;
}
while (a + sz <= b) {
res = f(res, w[a / sz]);
a += sz;
}
while (a < b) {
res = f(res, v[a]);
++a;
}
return res;
}
};
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
int n, q, inf = INT_MAX;
cin >> n >> q;
sqrt_decomposition sd(
vector<int>(n, inf), [](int x, int y) { return min(x, y); }, inf);
while (q--) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0) {
sd.point_set(x, y);
} else {
cout << sd.range_get(x, y + 1) << "\n";
}
}
// for(int i=0; i<n; ++i)
// cout << i << " " << sd.v[i] << "\n";
// for(int i=0; i<n/sd.sz; ++i)
// cout << i << " " << sd.w[i] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
struct sqrt_decomposition {
using F = function<int(int, int)>;
int n, sz, len;
vector<int> v;
vector<int> w;
F f;
int e;
sqrt_decomposition(vector<int> _v, F _f, int _e) : v(_v), f(_f), e(_e) {
n = v.size();
sz = 1;
while ((sz + 1) * (sz + 1) < n)
++sz;
len = n / sz;
w.resize(len, e);
for (int i = 0; i < sz; ++i)
for (int j = 0; j < sz; ++j)
if (i * sz + j < n)
w[i] = f(w[i], v[i * sz + j]);
}
void point_set(int a, int x) {
v[a] = x;
int b = a / sz;
w[b] = e;
for (int i = 0; i < sz && b * sz + i < n; ++i)
w[b] = f(w[b], v[b * sz + i]);
}
/* void range_set(int a, int b, int x){
while(a < b && a % sqrt_n != 0){
v[a] = x;
++a;
}
while(a + sqrt_n <= b){
w[a / sqrt_n] = x;
a += sqrt_n;
}
while(a < b){
v[a] = x;
++a;
}
}
*/
int point_get(int a) {
int b = a / sz;
return f(w[b], v[a]);
}
int range_get(int a, int b) {
int res = e;
while (a < b && a % sz != 0) {
res = f(res, v[a]);
++a;
}
while (a + sz <= b) {
res = f(res, w[a / sz]);
a += sz;
}
while (a < b) {
res = f(res, v[a]);
++a;
}
return res;
}
};
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
int n, q, inf = INT_MAX;
cin >> n >> q;
sqrt_decomposition sd(
vector<int>(n, inf), [](int x, int y) { return min(x, y); }, inf);
while (q--) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0) {
sd.point_set(x, y);
} else {
cout << sd.range_get(x, y + 1) << "\n";
}
}
// for(int i=0; i<n; ++i)
// cout << i << " " << sd.v[i] << "\n";
// for(int i=0; i<n/sd.sz; ++i)
// cout << i << " " << sd.w[i] << "\n";
}
|
replace
| 26 | 27 | 26 | 27 |
0
| |
p02345
|
C++
|
Runtime Error
|
// Segment Tree
// RMQ
#include <climits>
#include <cstdio>
#include <iostream>
using namespace std;
// const int MAX_N = 1 << 17;
const int MAX_N = 100022;
int n, dat[2 * MAX_N - 1];
int init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
return n;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
// cout<<a<<" ----- "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
if (r <= a || b <= l) {
// cout<<a<<" DD "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
return INT_MAX;
}
if (a <= l && r <= b) {
// cout<<a<<" c "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
// cout<<dat[k]<<endl;
return dat[k];
} else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
// cout<<a<<" b "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
// cout<<vl<<" b "<<vr<<endl;
return min(vl, vr);
}
}
int main() {
int n, q, com, x, y;
cin >> n >> q;
n = init(n);
for (int i = 0; i < q; i++) {
scanf("%d %d %d", &com, &x, &y);
if (com) {
printf("%d\n", query(x, y + 1, 0, 0, n));
} else {
update(x, y);
}
// for(int i = 0; i < n*2; i++)
// cout<<i<<" "<<dat[i]<<endl;
}
return 0;
}
|
// Segment Tree
// RMQ
#include <climits>
#include <cstdio>
#include <iostream>
using namespace std;
// const int MAX_N = 1 << 17;
const int MAX_N = 200022;
int n, dat[2 * MAX_N - 1];
int init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INT_MAX;
return n;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
// cout<<a<<" ----- "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
if (r <= a || b <= l) {
// cout<<a<<" DD "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
return INT_MAX;
}
if (a <= l && r <= b) {
// cout<<a<<" c "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
// cout<<dat[k]<<endl;
return dat[k];
} else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
// cout<<a<<" b "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
// cout<<vl<<" b "<<vr<<endl;
return min(vl, vr);
}
}
int main() {
int n, q, com, x, y;
cin >> n >> q;
n = init(n);
for (int i = 0; i < q; i++) {
scanf("%d %d %d", &com, &x, &y);
if (com) {
printf("%d\n", query(x, y + 1, 0, 0, n));
} else {
update(x, y);
}
// for(int i = 0; i < n*2; i++)
// cout<<i<<" "<<dat[i]<<endl;
}
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
int dp[200010], n, q, r, x, y, i;
int m(int l, int r, int k) {
if (x <= l && r <= y)
return dp[k];
if (y <= l || r <= x)
return 2147483647;
return min(m(l, (l + r) / 2, k * 2 + 1), m((l + r) / 2, r, k * 2 + 2));
}
int main() {
cin >> n >> q;
r = 2;
while (r < n)
r *= 2;
n = r, r *= 2;
while (r--)
dp[r] = 2147483647;
while (q--) {
cin >> r >> x >> y;
if (r) {
y++;
cout << m(0, n, 0) << endl;
} else {
i = x + n - 1, dp[i] = y;
while (i)
i = (i - 1) / 2, dp[i] = min(dp[i * 2 + 1], dp[i * 2 + 2]);
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int dp[270000], n, q, r, x, y, i;
int m(int l, int r, int k) {
if (x <= l && r <= y)
return dp[k];
if (y <= l || r <= x)
return 2147483647;
return min(m(l, (l + r) / 2, k * 2 + 1), m((l + r) / 2, r, k * 2 + 2));
}
int main() {
cin >> n >> q;
r = 2;
while (r < n)
r *= 2;
n = r, r *= 2;
while (r--)
dp[r] = 2147483647;
while (q--) {
cin >> r >> x >> y;
if (r) {
y++;
cout << m(0, n, 0) << endl;
} else {
i = x + n - 1, dp[i] = y;
while (i)
i = (i - 1) / 2, dp[i] = min(dp[i * 2 + 1], dp[i * 2 + 2]);
}
}
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
class Backet {
int n, sqrtN, B;
vector<int> val, backet;
public:
Backet(vector<int> a) : val(a) {
n = a.size();
sqrtN = ceil(sqrt(n));
B = (n + sqrtN - 1) / sqrtN;
backet.resize(B, INF);
for (int i = 0; i < B; i++) {
for (int j = sqrtN * i; j < sqrtN * (i + 1); j++) {
if (j >= n)
break;
backet[i] = min(backet[i], val[j]);
}
}
}
int RMQ(int l, int r) {
int L = (l + sqrtN - 1) / sqrtN + 1, R = r / sqrtN;
int res = INF;
if (L <= R) {
for (int i = l; i < sqrtN * L; i++)
res = min(res, val[i]);
for (int i = L; i < R; i++)
res = min(res, backet[i]);
for (int i = sqrtN * R; i < r; i++)
res = min(res, val[i]);
} else {
for (int i = l; i < r; i++)
res = min(res, val[i]);
}
return res;
}
void update(int k, int v) {
val[k] = v;
int x = k / sqrtN;
backet[x] = INF;
for (int i = sqrtN * x; i < sqrtN * (x + 1); i++) {
backet[x] = min(backet[x], val[i]);
}
}
};
int main() {
int n, q;
cin >> n >> q;
vector<int> a(n, INF);
Backet b(a);
for (int i = 0; i < q; i++) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0)
b.update(x, y);
else
cout << b.RMQ(x, y + 1) << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
class Backet {
int n, sqrtN, B;
vector<int> val, backet;
public:
Backet(vector<int> a) : val(a) {
n = a.size();
sqrtN = ceil(sqrt(n));
B = (n + sqrtN - 1) / sqrtN;
backet.resize(B, INF);
for (int i = 0; i < B; i++) {
for (int j = sqrtN * i; j < sqrtN * (i + 1); j++) {
if (j >= n)
break;
backet[i] = min(backet[i], val[j]);
}
}
}
int RMQ(int l, int r) {
int L = (l + sqrtN - 1) / sqrtN + 1, R = r / sqrtN;
int res = INF;
if (L <= R) {
for (int i = l; i < sqrtN * L; i++)
res = min(res, val[i]);
for (int i = L; i < R; i++)
res = min(res, backet[i]);
for (int i = sqrtN * R; i < r; i++)
res = min(res, val[i]);
} else {
for (int i = l; i < r; i++)
res = min(res, val[i]);
}
return res;
}
void update(int k, int v) {
val[k] = v;
int x = k / sqrtN;
backet[x] = INF;
for (int i = sqrtN * x; i < sqrtN * (x + 1); i++) {
if (i >= n)
break;
backet[x] = min(backet[x], val[i]);
}
}
};
int main() {
int n, q;
cin >> n >> q;
vector<int> a(n, INF);
Backet b(a);
for (int i = 0; i < q; i++) {
int c, x, y;
cin >> c >> x >> y;
if (c == 0)
b.update(x, y);
else
cout << b.RMQ(x, y + 1) << endl;
}
}
|
insert
| 49 | 49 | 49 | 51 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
// http://hos.ac/slides/20140319_bit.pdf
template <class T, int MAX_N> struct FenwickTree { // 0-indexed
int N;
T data[MAX_N];
void init(int n) {
N = n;
memset(data, 0, sizeof(data));
}
T sum(int j) { //[0, j)
T ret = 0;
for (int x = j - 1; x >= 0; x = (x & (x + 1)) - 1)
ret += data[x];
return ret;
}
void add(int j, T w) { // 0 <= j < N
for (int x = j; x < N; x |= x + 1)
data[x] += w;
}
};
// Range Minimum Query
template <class T, int MAX_N> struct SegmentTree {
int n;
T data[MAX_N * 2 - 1];
const T INF = (1LL << 31) - 1LL; // rewrite
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
fill_n(data, 2 * n - 1, INF);
}
void update(int k, T a) { // 0-indexed
k += n - 1;
data[k] = a;
while (k > 0) {
k = (k - 1) >> 1;
data[k] = min(data[k * 2 + 1], data[k * 2 + 2]);
}
}
T __query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return data[k];
else {
T val_l = __query(a, b, k * 2 + 1, l, (l + r) >> 1);
T val_r = __query(a, b, k * 2 + 2, (l + r) >> 1, r);
return min(val_l, val_r);
}
}
T query(int a, int b) { //[a, b)
return __query(a, b, 0, 0, n);
}
};
SegmentTree<long long, 100000> segt;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, Q;
cin >> N >> Q;
segt.init(N);
for (int i = 0; i < Q; ++i) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
segt.update(x, static_cast<long long>(y));
} else
cout << segt.query(x, y + 1) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
// http://hos.ac/slides/20140319_bit.pdf
template <class T, int MAX_N> struct FenwickTree { // 0-indexed
int N;
T data[MAX_N];
void init(int n) {
N = n;
memset(data, 0, sizeof(data));
}
T sum(int j) { //[0, j)
T ret = 0;
for (int x = j - 1; x >= 0; x = (x & (x + 1)) - 1)
ret += data[x];
return ret;
}
void add(int j, T w) { // 0 <= j < N
for (int x = j; x < N; x |= x + 1)
data[x] += w;
}
};
// Range Minimum Query
template <class T, int MAX_N> struct SegmentTree {
int n;
T data[MAX_N * 2 - 1];
const T INF = (1LL << 31) - 1LL; // rewrite
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
fill_n(data, 2 * n - 1, INF);
}
void update(int k, T a) { // 0-indexed
k += n - 1;
data[k] = a;
while (k > 0) {
k = (k - 1) >> 1;
data[k] = min(data[k * 2 + 1], data[k * 2 + 2]);
}
}
T __query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return data[k];
else {
T val_l = __query(a, b, k * 2 + 1, l, (l + r) >> 1);
T val_r = __query(a, b, k * 2 + 2, (l + r) >> 1, r);
return min(val_l, val_r);
}
}
T query(int a, int b) { //[a, b)
return __query(a, b, 0, 0, n);
}
};
SegmentTree<long long, 1 << 17> segt;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, Q;
cin >> N >> Q;
segt.init(N);
for (int i = 0; i < Q; ++i) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
segt.update(x, static_cast<long long>(y));
} else
cout << segt.query(x, y + 1) << '\n';
}
return 0;
}
|
replace
| 58 | 59 | 58 | 59 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
#define max_n (1 << 17)
using namespace std;
int dat[max_n], n;
int get(int k) { return dat[k + n]; }
void update(int k, int a) {
for (k += n, dat[k] = a; k > 1; k >>= 1)
dat[k >> 1] = min(dat[k], dat[k ^ 1]);
}
int rmq(int a, int b) {
int res = INT_MAX;
for (a += n, b += n; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
if (a & 1)
res = min(res, dat[a]);
if ((b & 1) == 0)
res = min(res, dat[b]);
}
return res;
}
int main(void) {
fill(dat, dat + max_n, INT_MAX);
int q;
cin >> n >> q;
while (q--) {
int com, x, y;
cin >> com >> x >> y;
if (com)
cout << rmq(x, y) << endl;
else
update(x, y);
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
#define max_n (1 << 18)
using namespace std;
int dat[max_n], n;
int get(int k) { return dat[k + n]; }
void update(int k, int a) {
for (k += n, dat[k] = a; k > 1; k >>= 1)
dat[k >> 1] = min(dat[k], dat[k ^ 1]);
}
int rmq(int a, int b) {
int res = INT_MAX;
for (a += n, b += n; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
if (a & 1)
res = min(res, dat[a]);
if ((b & 1) == 0)
res = min(res, dat[b]);
}
return res;
}
int main(void) {
fill(dat, dat + max_n, INT_MAX);
int q;
cin >> n >> q;
while (q--) {
int com, x, y;
cin >> com >> x >> y;
if (com)
cout << rmq(x, y) << endl;
else
update(x, y);
}
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
#define MAX_V 100002
#define INF INT_MAX
using namespace std;
int dat[MAX_V * 2], sz;
void update(int k, int x) {
k += sz - 1;
dat[k] = x;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return dat[k];
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
int main(void) {
fill(dat, dat + MAX_V * 2, INF);
int n, q;
cin >> n >> q;
sz = 1;
while (sz < n)
sz *= 2;
while (q--) {
int com, x, y;
cin >> com >> x >> y;
if (com)
cout << query(x, y + 1, 0, 0, sz) << endl;
else
update(x, y);
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
#define MAX_V (1 << 17)
#define INF INT_MAX
using namespace std;
int dat[MAX_V * 2], sz;
void update(int k, int x) {
k += sz - 1;
dat[k] = x;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return dat[k];
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
int main(void) {
fill(dat, dat + MAX_V * 2, INF);
int n, q;
cin >> n >> q;
sz = 1;
while (sz < n)
sz *= 2;
while (q--) {
int com, x, y;
cin >> com >> x >> y;
if (com)
cout << query(x, y + 1, 0, 0, sz) << endl;
else
update(x, y);
}
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int A[(1 << 17)];
int n, Q;
int N;
void init() {
N = 1;
while (N < n)
N *= 2;
for (int i = 0; i < 2 * N - 1; i++)
A[i] = 2147483647;
}
int find(int a, int b, int k, int l, int r) {
if (a <= l && r <= b)
return A[k];
if (r <= a || b <= l)
return 2147483647;
int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
// printf("find %d %d %d %d\n", l, r, vl,vr);
return min(vl, vr);
}
void update(int i, int x) {
i += N - 1;
A[i] = x;
// printf("update %d %d\n", i, A[i]);
while (i > 0) {
i = (i - 1) / 2;
A[i] = min(A[2 * i + 1], A[2 * i + 2]);
// printf("update %d %d\n", i, A[i]);
}
}
int main() {
cin >> n >> Q;
init();
for (int i = 0; i < Q; i++) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else
printf("%d\n", find(x, y + 1, 0, 0, N));
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int A[(1 << 20)];
int n, Q;
int N;
void init() {
N = 1;
while (N < n)
N *= 2;
for (int i = 0; i < 2 * N - 1; i++)
A[i] = 2147483647;
}
int find(int a, int b, int k, int l, int r) {
if (a <= l && r <= b)
return A[k];
if (r <= a || b <= l)
return 2147483647;
int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
// printf("find %d %d %d %d\n", l, r, vl,vr);
return min(vl, vr);
}
void update(int i, int x) {
i += N - 1;
A[i] = x;
// printf("update %d %d\n", i, A[i]);
while (i > 0) {
i = (i - 1) / 2;
A[i] = min(A[2 * i + 1], A[2 * i + 2]);
// printf("update %d %d\n", i, A[i]);
}
}
int main() {
cin >> n >> Q;
init();
for (int i = 0; i < Q; i++) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0)
update(x, y);
else
printf("%d\n", find(x, y + 1, 0, 0, N));
}
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
int n, q, data[200010];
int INF = (1LL << 31) - 1;
void init(int &n_) {
int n = 1;
while (n < n_)
n *= 2;
n_ = n;
for (int i = 0; i < 2 * n - 1; i++)
data[i] = INF;
}
void update(int k, int x) {
k += n - 1;
data[k] = x;
while (k > 0) {
k = (k - 1) / 2;
data[k] = std::min(data[k * 2 + 1], data[k * 2 + 2]);
}
}
int find(int a, int b, int k, int l, int r) {
if (r <= a)
return INF;
if (b <= l)
return INF;
if (a <= l && r <= b)
return data[k];
int val1 = find(a, b, k * 2 + 1, l, (r + l) / 2);
int val2 = find(a, b, k * 2 + 2, (r + l) / 2, r);
return std::min(val1, val2);
}
int main() {
std::cin >> n >> q;
init(n);
for (int i = 0; i < q; i++) {
int a, b, c;
std::cin >> a >> b >> c;
if (a == 0)
update(b, c);
else
std::cout << find(b, c + 1, 0, 0, n) << std::endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
int n, q, data[300010];
int INF = (1LL << 31) - 1;
void init(int &n_) {
int n = 1;
while (n < n_)
n *= 2;
n_ = n;
for (int i = 0; i < 2 * n - 1; i++)
data[i] = INF;
}
void update(int k, int x) {
k += n - 1;
data[k] = x;
while (k > 0) {
k = (k - 1) / 2;
data[k] = std::min(data[k * 2 + 1], data[k * 2 + 2]);
}
}
int find(int a, int b, int k, int l, int r) {
if (r <= a)
return INF;
if (b <= l)
return INF;
if (a <= l && r <= b)
return data[k];
int val1 = find(a, b, k * 2 + 1, l, (r + l) / 2);
int val2 = find(a, b, k * 2 + 2, (r + l) / 2, r);
return std::min(val1, val2);
}
int main() {
std::cin >> n >> q;
init(n);
for (int i = 0; i < q; i++) {
int a, b, c;
std::cin >> a >> b >> c;
if (a == 0)
update(b, c);
else
std::cout << find(b, c + 1, 0, 0, n) << std::endl;
}
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p02345
|
C++
|
Runtime Error
|
#include <climits>
#include <iostream>
using namespace std;
#define DEBUG 0
void update(int x, int y);
int find(int index, int x, int y, int l, int r);
void initRMQ();
void printTree();
const int infinit = INT_MAX;
int n, q;
const int SIZE = 100000;
int segmenttree[SIZE * 2 + 10];
int main() {
cin >> n >> q;
initRMQ();
/*
for (int i = 0; i < n * 2 - 1; ++i)
segmenttree[i] = infinit;
*/
#if DEBUG == 1
printTree();
#endif
for (int i = 0; i < q; ++i) {
int com, x, y;
cin >> com >> x >> y;
switch (com) {
case 0:
update(x, y);
break;
case 1:
cout << find(0, x, y + 1, 0, n) << endl;
break;
}
#if DEBUG == 1
cout << com << " " << x << " " << y << endl;
printTree();
#endif // DEBUG == 1
}
return 0;
}
void initRMQ() {
int n_ = 2 * n - 1;
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; ++i)
segmenttree[i] = infinit;
}
void update(int x, int y) {
int i = x + n - 1;
segmenttree[i] = y;
while (i > 0) {
i = (i - 1) / 2;
segmenttree[i] = min(segmenttree[i * 2 + 1], segmenttree[i * 2 + 2]);
}
}
int find(int index, int x, int y, int l, int r) {
if (r <= x || y <= l) {
return infinit;
} else if (x <= l && r <= y) {
return segmenttree[index];
} else {
int left = find(index * 2 + 1, x, y, l, (r + l) / 2);
int right = find(index * 2 + 2, x, y, (r + l) / 2, r);
#if DEBUG == 1
cout << "(r + l) / 2 = " << (r + l) / 2 << endl;
cout << "r = " << r << endl;
cout << "l = " << l << endl;
cout << "index * 2 + 2 = " << index * 2 + 2 << endl;
cout << "l = " << left << ", r = " << right << endl;
#endif
return min(left, right);
}
}
void printTree() {
for (int i = 0; i < n * 2 - 1; ++i)
cout << segmenttree[i] << " ";
cout << endl << endl;
}
|
#include <climits>
#include <iostream>
using namespace std;
#define DEBUG 0
void update(int x, int y);
int find(int index, int x, int y, int l, int r);
void initRMQ();
void printTree();
const int infinit = INT_MAX;
int n, q;
const int SIZE = 1000000;
int segmenttree[SIZE * 2 + 10];
int main() {
cin >> n >> q;
initRMQ();
/*
for (int i = 0; i < n * 2 - 1; ++i)
segmenttree[i] = infinit;
*/
#if DEBUG == 1
printTree();
#endif
for (int i = 0; i < q; ++i) {
int com, x, y;
cin >> com >> x >> y;
switch (com) {
case 0:
update(x, y);
break;
case 1:
cout << find(0, x, y + 1, 0, n) << endl;
break;
}
#if DEBUG == 1
cout << com << " " << x << " " << y << endl;
printTree();
#endif // DEBUG == 1
}
return 0;
}
void initRMQ() {
int n_ = 2 * n - 1;
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; ++i)
segmenttree[i] = infinit;
}
void update(int x, int y) {
int i = x + n - 1;
segmenttree[i] = y;
while (i > 0) {
i = (i - 1) / 2;
segmenttree[i] = min(segmenttree[i * 2 + 1], segmenttree[i * 2 + 2]);
}
}
int find(int index, int x, int y, int l, int r) {
if (r <= x || y <= l) {
return infinit;
} else if (x <= l && r <= y) {
return segmenttree[index];
} else {
int left = find(index * 2 + 1, x, y, l, (r + l) / 2);
int right = find(index * 2 + 2, x, y, (r + l) / 2, r);
#if DEBUG == 1
cout << "(r + l) / 2 = " << (r + l) / 2 << endl;
cout << "r = " << r << endl;
cout << "l = " << l << endl;
cout << "index * 2 + 2 = " << index * 2 + 2 << endl;
cout << "l = " << left << ", r = " << right << endl;
#endif
return min(left, right);
}
}
void printTree() {
for (int i = 0; i < n * 2 - 1; ++i)
cout << segmenttree[i] << " ";
cout << endl << endl;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p02345
|
C++
|
Runtime Error
|
// ???????????????
#include <cassert>
#include <climits>
#include <vector>
// ?????°
const int INF = INT_MAX;
// ?????????
class RangeMinimumQuery {
public:
explicit RangeMinimumQuery(int s);
void update(int i, int v);
int index(int left, int right) const;
int value(int left, int right) const;
private:
int parent(int node) const;
int left_child(int node) const;
int right_child(int node) const;
int power_of_two(int n) const;
int query(int left, int right, int node, int node_left, int node_right) const;
int size_, nil_, inf_;
std::vector<int> index_, value_;
};
// ????????????
RangeMinimumQuery::RangeMinimumQuery(int s)
: size_(power_of_two(s)), nil_(size_), inf_(INF),
index_(2 * size_ - 1, nil_), value_(size_ + 1, inf_) {}
void RangeMinimumQuery::update(int i, int v) {
int node = i + size_ - 1;
index_.at(node) = i;
value_.at(i) = v;
while ((node = parent(node)) != nil_) {
int l = value_.at(index_.at(left_child(node)));
int r = value_.at(index_.at(right_child(node)));
index_.at(node) = index_.at(l <= r ? left_child(node) : right_child(node));
}
}
int RangeMinimumQuery::index(int left, int right) const {
return query(left, right, 0, 0, size_ - 1);
}
int RangeMinimumQuery::value(int left, int right) const {
return value_.at(query(left, right, 0, 0, size_ - 1));
}
int RangeMinimumQuery::parent(int node) const {
return node ? (node - 1) / 2 : nil_;
}
int RangeMinimumQuery::left_child(int node) const { return 2 * node + 1; }
int RangeMinimumQuery::right_child(int node) const { return 2 * node + 2; }
int RangeMinimumQuery::power_of_two(int n) const {
while (n & (n - 1))
n += n & -n;
return n;
}
int RangeMinimumQuery::query(int left, int right, int node, int node_left,
int node_right) const {
assert(left <= right);
assert(0 <= left);
assert(size_ < right);
if (node_right < left || right < node_left)
return nil_;
if (left <= node_left && node_right <= right)
return index_.at(node);
int middle = (node_left + node_right) / 2;
int l = query(left, right, left_child(node), node_left, middle);
int r = query(left, right, right_child(node), middle + 1, node_right);
return value_.at(l) <= value_.at(r) ? l : r;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
RangeMinimumQuery rmq(n);
for (int i = 0; i < q; ++i) {
int com, x, y;
cin >> com >> x >> y;
if (com)
cout << rmq.value(x, y) << endl;
else
rmq.update(x, y);
}
}
|
// ???????????????
#include <cassert>
#include <climits>
#include <vector>
// ?????°
const int INF = INT_MAX;
// ?????????
class RangeMinimumQuery {
public:
explicit RangeMinimumQuery(int s);
void update(int i, int v);
int index(int left, int right) const;
int value(int left, int right) const;
private:
int parent(int node) const;
int left_child(int node) const;
int right_child(int node) const;
int power_of_two(int n) const;
int query(int left, int right, int node, int node_left, int node_right) const;
int size_, nil_, inf_;
std::vector<int> index_, value_;
};
// ????????????
RangeMinimumQuery::RangeMinimumQuery(int s)
: size_(power_of_two(s)), nil_(size_), inf_(INF),
index_(2 * size_ - 1, nil_), value_(size_ + 1, inf_) {}
void RangeMinimumQuery::update(int i, int v) {
int node = i + size_ - 1;
index_.at(node) = i;
value_.at(i) = v;
while ((node = parent(node)) != nil_) {
int l = value_.at(index_.at(left_child(node)));
int r = value_.at(index_.at(right_child(node)));
index_.at(node) = index_.at(l <= r ? left_child(node) : right_child(node));
}
}
int RangeMinimumQuery::index(int left, int right) const {
return query(left, right, 0, 0, size_ - 1);
}
int RangeMinimumQuery::value(int left, int right) const {
return value_.at(query(left, right, 0, 0, size_ - 1));
}
int RangeMinimumQuery::parent(int node) const {
return node ? (node - 1) / 2 : nil_;
}
int RangeMinimumQuery::left_child(int node) const { return 2 * node + 1; }
int RangeMinimumQuery::right_child(int node) const { return 2 * node + 2; }
int RangeMinimumQuery::power_of_two(int n) const {
while (n & (n - 1))
n += n & -n;
return n;
}
int RangeMinimumQuery::query(int left, int right, int node, int node_left,
int node_right) const {
assert(left <= right);
assert(0 <= left);
assert(right < size_);
if (node_right < left || right < node_left)
return nil_;
if (left <= node_left && node_right <= right)
return index_.at(node);
int middle = (node_left + node_right) / 2;
int l = query(left, right, left_child(node), node_left, middle);
int r = query(left, right, right_child(node), middle + 1, node_right);
return value_.at(l) <= value_.at(r) ? l : r;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
RangeMinimumQuery rmq(n);
for (int i = 0; i < q; ++i) {
int com, x, y;
cin >> com >> x >> y;
if (com)
cout << rmq.value(x, y) << endl;
else
rmq.update(x, y);
}
}
|
replace
| 57 | 58 | 57 | 58 |
-6
|
4f4839fd-dd81-4185-97b9-1774c359f366.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02345/C++/s906043922.cpp:51: int RangeMinimumQuery::query(int, int, int, int, int) const: Assertion `size_ < right' failed.
|
p02345
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)
#define INT_MAX (2147483647)
using namespace std;
struct SegmentTree {
int n;
vector<int> dat;
SegmentTree(int _n) {
n = 2;
while (n < _n)
n *= 2;
dat.resize(n);
for (int i = 0; i < 2 * n - 1; ++i)
dat[i] = INT_MAX;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int find(int a, int b) { return query(a, b, 0, 0, n); }
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b) {
return dat[k];
} else {
int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
};
int N, Q;
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N >> Q;
SegmentTree seg(N);
while (Q--) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
seg.update(x, y);
} else {
cout << seg.find(x, y + 1) << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)
#define INT_MAX (2147483647)
using namespace std;
struct SegmentTree {
int n;
vector<int> dat;
SegmentTree(int _n) {
n = 2;
while (n < _n)
n *= 2;
dat.resize(n * 2);
for (int i = 0; i < 2 * n - 1; ++i)
dat[i] = INT_MAX;
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int find(int a, int b) { return query(a, b, 0, 0, n); }
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return INT_MAX;
if (a <= l && r <= b) {
return dat[k];
} else {
int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
};
int N, Q;
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N >> Q;
SegmentTree seg(N);
while (Q--) {
int com, x, y;
cin >> com >> x >> y;
if (com == 0) {
seg.update(x, y);
} else {
cout << seg.find(x, y + 1) << endl;
}
}
return 0;
}
|
replace
| 43 | 44 | 43 | 44 |
0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.