Submission #1042662

#TimeUsernameProblemLanguageResultExecution timeMemory
1042662BF001Bubble Sort 2 (JOI18_bubblesort2)C++17
100 / 100
1436 ms55460 KiB
#include<bits/stdc++.h> using namespace std; #define N 1000005 #define fi first #define se second typedef pair<int, int> ii; int bit[4 * N], lazy[4 * N]; vector<ii> vec; void add(int id, int val){ bit[id] += val; lazy[id] += val; } void down(int id, int l, int r){ if (l == r) return; add(id * 2, lazy[id]); add(id * 2 + 1, lazy[id]); lazy[id] = 0; } void ud(int id, int l, int r, int u, int v, int val){ if (l > v || r < u) return; if (l >= u && r <= v){ add(id, val); return; } down(id, l, r); int mid = (l + r) >> 1; ud(id * 2, l, mid, u, v, val); ud(id * 2 + 1, mid + 1, r, u, v, val); bit[id] = max(bit[id * 2], bit[id * 2 + 1]); } vector<int> a; void qr(int x, int sign){ ii tmp1 = {a[x], x}; ii tmp2 = {a[x], -1}; int pos = lower_bound(vec.begin(), vec.end(), tmp1) - vec.begin() + 1; int pos2 = lower_bound(vec.begin(), vec.end(), tmp2) - vec.begin() + 1; int n = (int) vec.size(); ud(1, 1, n, pos, pos, x * sign); ud(1, 1, n, pos2, n, -sign); //cout << pos << " " << pos2 << " ; \n"; } vector<int> countScans(vector<int> A, vector<int> x, vector<int> y){ int n, q; n = (int) A.size(); q = (int) x.size(); a.push_back(1); for (auto xx : A) a.push_back(xx); vector<int> ans; for (int i = 0; i < n; i++) {vec.push_back({A[i], i + 1});} for (int i = 0; i < q; i++){ x[i]++; vec.push_back({y[i], x[i]}); } sort(vec.begin(), vec.end()); vec.resize(unique(vec.begin(), vec.end()) - vec.begin()); for (int i = 1; i <= n; i++){ qr(i, 1); } for (int i = 0; i < q; i++){ qr(x[i], -1); a[x[i]] = y[i]; qr(x[i], 1); ans.push_back(bit[1]); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...