Submission #871801

#TimeUsernameProblemLanguageResultExecution timeMemory
871801serifefedartarBubble Sort 2 (JOI18_bubblesort2)C++17
100 / 100
1766 ms68656 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<pair<int,int>> cc; int index(pair<int,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]; } lazy[k] = 0; return ; } } 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)); } int N; void add(pair<int,int> p) { int plc = index(p); update(1, 1, N, plc, plc, 1e7 + p.s); update(1, 1, N, plc + 1, N, -1); } void omit(pair<int,int> p) { int plc = index(p); update(1, 1, N, plc, plc, -1e7 - p.s); update(1, 1, N, plc + 1, N, 1); } vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) { memset(lazy, 0, sizeof(lazy)); memset(sg, 0, sizeof(sg)); int n = A.size(), q = V.size(); for (int i = 0; i < n; i++) cc.push_back({A[i], i}); for (int i = 0; i < q; i++) cc.push_back({V[i], X[i]}); sort(cc.begin(), cc.end()); cc.erase(unique(cc.begin(), cc.end()), cc.end()); N = cc.size(); update(1, 1, N, 1, N, -1e7); push(1, 1, N); for (int i = 0; i < n; i++) add({A[i], i}); push(1, 1, N); vector<int> res; for (int i = 0; i < q; i++) { omit({A[X[i]], X[i]}); add({V[i], X[i]}); A[X[i]] = V[i]; 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...