Submission #381829

#TimeUsernameProblemLanguageResultExecution timeMemory
381829JerryLiu06Bubble Sort 2 (JOI18_bubblesort2)C++11
0 / 100
222 ms5856 KiB
#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[2000010]; vector<pii> allX; const int INF = 1000000000; int cntLess[1000010]; void updBIT(int ind, int val) { while (ind <= MX) { cntLess[ind] += val; ind += (ind & -ind); } } int queryBIT(int ind) { int sum = 0; while (ind > 0) { sum += cntLess[ind]; ind -= (ind & -ind); } return sum; } 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 update(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 ; } update(2 * x, l, mid, tl, tr, C); update(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); } int query(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2; pushdown(x, l, r); if (l > tr || r < tl) return 0; if (tl <= l && r <= tr) return tree[x].f; return max(query(2 * x, l, mid, tl, tr), query(2 * x + 1, mid + 1, r, tl, tr)); } 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(); for (int i = 0; i < N; i++) { int POS = getX(pii {A[i], i}); int LESS = queryBIT(POS); updBIT(POS, 1); update(1, 1, MX, POS, POS, i - LESS); } vector<int> res; for (int i = 0; i < Q; i++) { int POS1 = getX(pii {A[X[i]], X[i]}); int POS2 = getX(pii {V[i], X[i]}); updBIT(POS1, -1); int LESS = queryBIT(POS2); updBIT(POS2, 1); if (POS1 < POS2) update(1, 1, MX, POS1 + 1, POS2 - 1, 1); if (POS2 < POS1) update(1, 1, MX, POS2 + 1, POS1 - 1, -1); int VAL = query(1, 1, MX, POS2, POS2); update(1, 1, MX, POS1, POS1, -INF); update(1, 1, MX, POS2, POS2, -VAL + X[i] - LESS); A[X[i]] = V[i]; res.pb(tree[1].f); } return res; } // int main() { // ios_base::sync_with_stdio(false); cin.tie(0); // cin >> N >> Q; vector<int> A, X, V; // for (int i = 0; i < N; i++) { int a; cin >> a; A.pb(a); } // for (int i = 0; i < Q; i++) { int x, v; cin >> x >> v; X.pb(x); V.pb(v); } // vector<int> res = countScans(A, X, V); // for (int i : res) cout << i << endl; // }

Compilation message (stderr)

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:39:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   39 |     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:39:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   39 |     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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...