Submission #1028173

#TimeUsernameProblemLanguageResultExecution timeMemory
1028173modwweBubble Sort 2 (JOI18_bubblesort2)C++17
100 / 100
1270 ms66696 KiB
//https://www.instagram.com/_modwwe/ //#include "bubblesort2.h" #pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2") #include<bits/stdc++.h> //#define int long long //#define ll long long #define down cout<<'\n'; #define debug cout<<" cucuucucuuu",down #define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); #define modwwe int t;cin>>t; while(t--) #define bit(i,j) (i>>j&1) #define sobit(a) __builtin_popcountll(a) #define task "test" #define fin(x) freopen(x".inp","r",stdin) #define fou(x) freopen(x".ans ","w",stdout) #define pb push_back #define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms"; using namespace std; void phongbeo(); const int inf=1e9; const int mod2=1e9+7; const int mod1=998244353; struct icd { int a,b; }; struct ib { int a; int b; }; struct ic { int a,b,c; }; struct id { int a,b,c,d; }; struct ie { int a,b,c,d,e,f; }; int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l; int i,s10,s12; int kk; int el=29; ib t[4000001]; void ff(int x) { for(int i=x*2;i<=x*2+1;i++) t[i].a+=t[x].b, t[i].b+=t[x].b; t[x].b=0; } void upd(int node,int l,int r,int l1,int r1,int x) { if(l>r1||r<l1) return; if(l>=l1&&r<=r1) {t[node].b+=x;t[node].a+=x; return;} if(t[node].b!=0) ff(node); int mid=l+r>>1; upd(node<<1,l,mid,l1,r1,x); upd(node<<1|1,mid+1,r,l1,r1,x); t[node].a=max(t[node<<1].a,t[node<<1|1].a); } void upd2(int node,int l,int r,int l1,int x) { if(l==r) { t[node].a+=x; return; } if(t[node].b!=0) ff(node); int mid=l+r>>1; if(l1<=mid) upd2(node<<1,l,mid,l1,x); else upd2(node<<1|1,mid+1,r,l1,x); t[node].a=max(t[node<<1].a,t[node<<1|1].a); } vector<int> countScans(vector<int> a, vector<int> x, vector<int> y) { n=a.size(); m=x.size(); vector<int> c(m); vector<pair<int,int>> v; for(int i=0;i<n;i++) v.pb({a[i],i}); for(int i=0;i<m;i++)v.pb({y[i],x[i]}); sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); l=v.size()-1; for(int i=1;i<=l*4;i++) t[i].a=-inf; for(int i=0;i<n;i++) { s2=lower_bound(v.begin(),v.end(),make_pair(a[i],i))-v.begin(); upd2(1,0,l,s2,i+inf); if(s2!=l) upd(1,0,l,s2+1,l,-1); } for(int i=0;i<m;i++) { s2=lower_bound(v.begin(),v.end(),make_pair(a[x[i]],x[i]))-v.begin(); upd2(1,0,l,s2,-x[i]-inf); if(s2!=l) upd(1,0,l,s2+1,l,1); a[x[i]]=y[i]; s2=lower_bound(v.begin(),v.end(),make_pair(a[x[i]],x[i]))-v.begin(); upd2(1,0,l,s2,x[i]+inf); if(s2!=l) upd(1,0,l,s2+1,l,-1); c[i]=t[1].a; } return c; } /*main() { vector<int>a,b,c; a.resize(4); a={1,2,3,4}; b.resize(2); c.resize(2); b={0,2}; c={3,1}; vector<int> z=countScans(a,b,c); for(auto x:z) cout<<x,down }*/

Compilation message (stderr)

bubblesort2.cpp: In function 'void upd(int, int, int, int, int, int)':
bubblesort2.cpp:64:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |   int mid=l+r>>1;
      |           ~^~
bubblesort2.cpp: In function 'void upd2(int, int, int, int, int)':
bubblesort2.cpp:78:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   78 |         int mid=l+r>>1;
      |                 ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...