Submission #673495

#TimeUsernameProblemLanguageResultExecution timeMemory
673495406Bubble Sort 2 (JOI18_bubblesort2)C++17
100 / 100
1721 ms38860 KiB
#include "bubblesort2.h" #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 50; int mx[4 * N], delta[4 * N]; vector<pair<int, int>> D; void add(int v, int l, int r, int L, int R, int d) { if (R <= L || R <= l || r <= L) return; if (l >= L && r <= R) { mx[v] += d, delta[v] += d; return; } int m = l + r >> 1; add(v<<1, l, m, L, R, d); add(v<<1|1, m, r, L, R, d); mx[v] = max(mx[v<<1], mx[v<<1|1]) + delta[v]; } int loc(pair<int, int> p) {return lower_bound(D.begin(), D.end(), p) - D.begin();} vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){ int Q = X.size(); int n = A.size(); D.reserve(Q + n); for (int i = 0; i < n; i++) D.emplace_back(A[i], i); for (int i = 0; i < Q; i++) D.emplace_back(V[i], X[i]); sort(D.begin(), D.end()), D.resize(unique(D.begin(), D.end()) - D.begin()); for (int i = 0; i < n; i++) { int ind = loc({A[i], i}); add(1, 0, D.size(), ind, ind + 1, +i); add(1, 0, D.size(), ind + 1, D.size(), -1); } vector<int> answer(Q); for (int i = 0; i < Q; i++) { int ind = loc({A[X[i]], X[i]}); add(1, 0, D.size(), ind, ind + 1, -X[i]); add(1, 0, D.size(), ind + 1, D.size(), +1); ind = loc({V[i], X[i]}); add(1, 0, D.size(), ind, ind + 1, +X[i]); add(1, 0, D.size(), ind + 1, D.size(), -1); A[X[i]] = V[i]; answer[i] = max(mx[1], 0); } return answer; }

Compilation message (stderr)

bubblesort2.cpp: In function 'void add(int, int, int, int, int, int)':
bubblesort2.cpp:13:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |  int m = l + r >> 1;
      |          ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...