Submission #871776

#TimeUsernameProblemLanguageResultExecution timeMemory
871776serifefedartarBubble Sort 2 (JOI18_bubblesort2)C++17
0 / 100
15 ms2908 KiB
#include <bits/stdc++.h> #include "bubblesort2.h" using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); #define s second #define f first typedef long long ll; const ll MOD = 1e9+9; const ll LOGN = 20; const ll MAXN = 1e6 + 100; vector<int> cc; int index(int k) { return upper_bound(cc.begin(), cc.end(), k) - cc.begin(); } int sg[4*MAXN], lazy[4*MAXN]; void push(int k, int a, int b) { if (lazy[k]) { sg[k] += lazy[k]; if (a != b) { lazy[2*k] += lazy[k]; lazy[2*k+1] += lazy[k]; } return ; } } void init(int k, int a, int b) { if (a == b) { sg[k] = -1e7; return ; } init(2*k, a, (a+b)/2); init(2*k+1, (a+b)/2+1, b); sg[k] = max(sg[2*k], sg[2*k+1]); } void update(int k, int a, int b, int q_l, int q_r, int val) { push(k, a, b); if (b < q_l || a > q_r) return ; if (q_l <= a && b <= q_r) { lazy[k] += val; push(k, a, b); return ; } update(2*k, a, (a+b)/2, q_l, q_r, val); update(2*k+1, (a+b)/2+1, b, q_l, q_r, val); sg[k] = max(sg[2*k], sg[2*k+1]); } int query(int k, int a, int b, int q_l, int q_r) { push(k, a, b); if (b < q_l || a > q_r) return 0; if (q_l <= a && b <= q_r) return sg[k]; return max(query(2*k, a, (a+b)/2, q_l, q_r), query(2*k+1, (a+b)/2+1, b, q_l, q_r)); } vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) { int n = A.size(); int q = X.size(); for (auto u : A) cc.push_back(u); for (auto u : V) cc.push_back(u); sort(cc.begin(), cc.end()); cc.erase(unique(cc.begin(), cc.end()), cc.end()); for (int i = 0; i < n; i++) A[i] = index(A[i]); for (int i = 0; i < q; i++) V[i] = index(V[i]); int N = cc.size(); init(1, 1, N); for (int i = 0; i < n; i++) { int Q = query(1, 1, N, A[i], A[i]); update(1, 1, N, A[i], A[i], -Q); update(1, 1, N, A[i], A[i], i); update(1, 1, N, A[i] + 1, N, -1); } vector<int> res; for (int i = 0; i < q; i++) { int plc = X[i]; int Q = query(1, 1, N, A[plc], A[plc]); update(1, 1, N, A[plc], A[plc], - (Q + 1e7)); update(1, 1, N, A[plc] + 1, N, 1); A[plc] = V[i]; Q = query(1, 1, N, A[plc], A[plc]); update(1, 1, N, A[plc], A[plc], -Q); update(1, 1, N, A[plc], A[plc], plc); update(1, 1, N, A[plc] + 1, N, -1); push(1, 1, N); res.push_back(sg[1]); } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...