Submission #311829

#TimeUsernameProblemLanguageResultExecution timeMemory
311829MarcoMeijerBubble Sort 2 (JOI18_bubblesort2)C++14
100 / 100
5143 ms166368 KiB
#include "bubblesort2.h" #include <bits/stdc++.h> using namespace std; // macros typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define FOR(a,b) for(auto& a : b) #define all(a) a.begin(), a.end() #define INF 1e9 #define EPS 1e-9 #define pb push_back #define popb pop_back #define fi first #define se second #define sz size() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const int H=20; const int N=(1<<H); vi A, X, V; vi dif; int seg[N*2], laz[N]; void apply(int p, int v) { seg[p] += v; if(p < N) laz[p] += v; } void build(int p) { while(p>1) p/=2, seg[p]=max(seg[p*2],seg[p*2+1])+laz[p]; } void push(int p) { REV(s,1,H+1) { int i=p>>s; apply(i*2 ,laz[i]); apply(i*2+1,laz[i]); laz[i] = 0; } } void add(int l, int r, int v) { int l0=l+=N, r0=r+=N; for(; l<r; l/=2, r/=2) { if(l&1) apply(l++,v); if(r&1) apply(--r,v); } build(l0); build(r0-1); } int get(int l, int r) { l+=N; r+=N; push(l); push(r-1); int res=0; for(; l<r; l/=2, r/=2) { if(l&1) res += seg[l++]; if(r&1) res += seg[--r]; } return res; } map<int,set<int>> mp; void update(int i, int v) { add(A[i],N,-v); if(v == 1) { if(!mp[A[i]].empty()) add(A[i],A[i]+1,-*prev(mp[A[i]].end())); mp[A[i]].insert(i); add(A[i],A[i]+1, *prev(mp[A[i]].end())); } else { add(A[i],A[i]+1,-*prev(mp[A[i]].end())); mp[A[i]].erase(i); if(!mp[A[i]].empty()) add(A[i],A[i]+1, *prev(mp[A[i]].end())); } } vi countScans(vi _A, vi _X, vi _V){ A=_A; X=_X; V=_V; int n=A.size(); int q=X.size(); vi ans(q); RE(i,n) dif.pb(A[i]); RE(i,q) dif.pb(V[i]); sort(all(dif)); dif.erase(unique(all(dif)), dif.end()); RE(i,n) A[i] = lower_bound(all(dif), A[i])-dif.begin(); RE(i,q) V[i] = lower_bound(all(dif), V[i])-dif.begin(); add(0,N,1); RE(i,n) update(i,1); RE(j,q) { update(X[j],-1); A[X[j]] = V[j]; update(X[j], 1); ans[j] = get(0,N); } 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...