This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define pb push_back
#define f first
#define s second
int N, Q, MX; pii tree[4000010]; vector<pii> allX; const int INF = 1000000000;
int getX(pii P) { return lower_bound(allX.begin(), allX.end(), P) - allX.begin() + 1; }
void pushdown(int x, int l, int r) {
tree[x].f += tree[x].s; if (l < r) { tree[2 * x].s += tree[x].s; tree[2 * x + 1].s += tree[x].s; } tree[x].s = 0;
}
void updRange(int x, int l, int r, int tl, int tr, int C) { int mid = (l + r) / 2;
pushdown(x, l, r); if (l > tr || r < tl) return ; if (tl <= l && r <= tr) { tree[x].s += C; return ; }
updRange(2 * x, l, mid, tl, tr, C); updRange(2 * x + 1, mid + 1, r, tl, tr, C);
pushdown(2 * x, l, mid); pushdown(2 * x + 1, mid + 1, r); tree[x].f = max(tree[2 * x].f, tree[2 * x + 1].f);
}
void INSERT(pii P) { int X = getX(P); updRange(1, 1, MX, X, X, INF + P.s); updRange(1, 1, MX, X + 1, MX, -1); }
void REMOVE(pii P) { int X = getX(P); updRange(1, 1, MX, X, X, -INF - P.s); updRange(1, 1, MX, X + 1, MX, 1); }
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) { int N = A.size(); int Q = X.size();
for (int i = 0; i < N; i++) allX.pb(pii {A[i], i}); for (int i = 0; i < Q; i++) allX.pb(pii {V[i], X[i]});
sort(allX.begin(), allX.end()); allX.resize(distance(allX.begin(), unique(allX.begin(), allX.end())));
MX = allX.size(); updRange(1, 1, MX, 1, MX, -INF);
for (int i = 0; i < N; i++) INSERT(pii {A[i], i});
vector<int> res; for (int i = 0; i < Q; i++) {
REMOVE(pii {A[X[i]], X[i]}); INSERT(pii {V[i], X[i]});
A[X[i]] = V[i]; res.pb(tree[1].f);
}
return res;
}
Compilation message (stderr)
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:30:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
30 | for (int i = 0; i < N; i++) allX.pb(pii {A[i], i}); for (int i = 0; i < Q; i++) allX.pb(pii {V[i], X[i]});
| ^~~
bubblesort2.cpp:30:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
30 | for (int i = 0; i < N; i++) allX.pb(pii {A[i], i}); for (int i = 0; i < Q; i++) allX.pb(pii {V[i], X[i]});
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |