제출 #210353

#제출 시각아이디문제언어결과실행 시간메모리
2103532qbingxuanBubble Sort 2 (JOI18_bubblesort2)C++14
0 / 100
41 ms13688 KiB
#include <bits/stdc++.h> #define pb emplace_back #define get_pos(u,x) (lower_bound(begin(u),end(u),x) - begin(u)) using namespace std; const int N = 1000025, inf = 1e9; struct Segtree { int mx[N<<1], lz[N]; void init() { for(int i = 0; i < N*2; i++) mx[i] = -inf; for(int i = 0; i < N; i++) lz[i] = 0; } void upd(int p, int d) { mx[p] += d; if(p < N) lz[p] += d; } void pull(int p) { for(; p>1; p>>=1) mx[p>>1] = max(mx[p],mx[p^1]) + lz[p>>1]; } void push(int p) { for(int h = __lg(N); h >= 0; h--) { int i = p>>h; if(!lz[i>>1]) continue; upd(i,lz[i>>1]); upd(i^1,lz[i>>1]); lz[i>>1] = 0; } } void add(int l, int r, int d) { int L = l, R = r; for(l+=N,r+=N; l<r; l>>=1,r>>=1) { if(l&1) upd(l++, d); if(r&1) upd(--r, d); } pull(L+N), pull(R-1+N); } int query(int l, int r) { int res = -inf; push(l+N), push(r-1+N); for(l+=N,r+=N; l<r; l>>=1,r>>=1) { if(l&1) res = max(res, mx[l++]); if(r&1) res = max(res, mx[--r]); } return res; } } sgt; vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) { int n = A.size(), q = X.size(); /*for(int i = 0; i < n; i++) evt.pb(i, i, A[i]); for(int i = 0; i < q; i++) evt.pb(i+n, X[i]-1, V[i]); CDQ(evt);*/ vector<int> u; for(int i = 0; i < n; i++) u.pb(A[i]); for(int i = 0; i < q; i++) u.pb(V[i]); sort(u.begin(), u.end()); u.erase(unique(u.begin(), u.end()), u.end()); for(int i = 0; i < n; i++) A[i] = get_pos(u, A[i]) + 1; for(int i = 0; i < q; i++) V[i] = get_pos(u, V[i]) + 1; vector<set<int>> idx(u.size()+1); vector<int> Q; sgt.init(); auto del = [&](int p, int x) { sgt.add(x,x+1,-sgt.query(x,x+1)); idx[x].erase(p); sgt.add(x,x+1, idx[x].empty() ? -inf : (*idx[x].rbegin())); sgt.add(x+1,N,1); }; auto add = [&](int p, int x) { sgt.add(x,x+1,-sgt.query(x,x+1)); idx[x].insert(p); sgt.add(x,x+1,(*idx[x].rbegin())); sgt.add(x+1,N,-1); }; for(int i = 0; i < n; i++) add(i, A[i]); for(int i = 0; i < q; i++) { // i - #j : v_j < v_i del(X[i], A[X[i]]); A[X[i]] = V[i]; add(X[i], A[X[i]]); //for(int i = 0; i <= u.size(); i++) sgt.push(i+N), cout << sgt.mx[i+N] << ' ';cout<<'\n'; Q.pb(sgt.query(0,N)); } return Q; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...