Submission #570164

#TimeUsernameProblemLanguageResultExecution timeMemory
570164MohammadAghilBubble Sort 2 (JOI18_bubblesort2)C++14
100 / 100
4547 ms106252 KiB
#include <bits/stdc++.h> #include "bubblesort2.h" // #pragma GCC optimize ("Ofast,unroll-loops") // #pragma GCC target ("avx2") using namespace std; typedef long long ll; typedef pair<int, int> pp; #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl #define per(i,r,l) for(int i = (r); i >= (l); i--) #define rep(i,l,r) for(int i = (l); i < (r); i++) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define pb push_back #define ss second #define ff first void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll mod = 998244353, maxn = 1e6 + 5, lg = 22, inf = ll(1e9) + 5; ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;} int seg[maxn<<2], laz[maxn<<2]; map<pp, int> mp; int id; void updNode(int x, int k){ seg[x] += k, laz[x] += k; } void shift(int x){ if(laz[x]){ updNode(x<<1, laz[x]), updNode(x<<1|1, laz[x]); laz[x] = 0; } } void upd(int l, int r, int k, int x = 1, int lx = 0, int rx = id){ if(l <= lx && r >= rx){ updNode(x, k); return; } if(l >= rx || r <= lx) return; shift(x); int mid = (lx + rx)>>1; upd(l, r, k, x<<1, lx, mid), upd(l, r, k, x<<1|1, mid, rx); seg[x] = max(seg[x<<1], seg[x<<1|1]); } void add(int p, int v, int k){ int ps = mp[{v, p}]; upd(ps, ps + 1, k*(inf+p)); if(ps+1-id) upd(ps+1, id, -k); } vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){ int n = sz(A), q = sz(X); rep(i,0,n) mp[{A[i], i}] = 0; rep(i,0,q) mp[{V[i], X[i]}] = 0; for(auto&c:mp) c.ss = id++; upd(0, id, -inf); rep(i,0,n) add(i, A[i], 1); vector<int> res(q); rep(i,0,q){ add(X[i], A[X[i]], -1), add(X[i], A[X[i]] = V[i], 1); res[i] = seg[1]; } return res; } // int main(){ // cin.tie(0) -> sync_with_stdio(0); // int n, q; cin >> n >> q; // vector<int> a(n); // rep(i,0,n) cin >> a[i], mp[{a[i], i}] = 0; // vector<pp> query(q); // rep(i,0,q) cin >> query[i].ff >> query[i].ss, mp[{query[i].ss, query[i].ff}] = 0; // for(auto&c:mp) c.ss = id++; // upd(0, id, -inf); // rep(i,0,n) add(i, a[i], 1); // for(auto[p, v]: query){ // add(p, a[p], -1), add(p, a[p] = v, 1); // cout << seg[1] << '\n'; // } // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...