Submission #412415

#TimeUsernameProblemLanguageResultExecution timeMemory
412415nichkeBubble Sort 2 (JOI18_bubblesort2)C++14
100 / 100
6153 ms215664 KiB
#include<bits/stdc++.h> #define pb push_back #define left 2*i+1 #define righ 2*i+2 #define mid (l+r)/2 using namespace std; const int maxn=1e6+100; vector<int>a,pos,val,ans; int cnt=0; map<int,int>ha; set<int>id[maxn]; int st[4*maxn],lazy[4*maxn]; void upd(int i,int l,int r,int ql,int qr,int del){ if(lazy[i]){ st[i]+=lazy[i]; if(l!=r){ lazy[left]+=lazy[i]; lazy[righ]+=lazy[i]; } lazy[i]=0; } if(r<ql||l>qr)return; if(l>=ql&&r<=qr){ st[i]+=del; if(l!=r){ lazy[left]+=del; lazy[righ]+=del; } return; } upd(left,l,mid,ql,qr,del); upd(righ,mid+1,r,ql,qr,del); st[i]=max(st[left],st[righ]); } void rem(int i,int x){ upd(0,0,cnt-1,x,cnt-1,1); if(i==*id[x].rbegin()){ auto it=id[x].end(); it--; int del=-*it; it--; del+=*it; upd(0,0,cnt-1,x,x,del); } id[x].erase(i); } void add(int i,int x){ upd(0,0,cnt-1,x,cnt-1,-1); if(i>*id[x].rbegin()){ upd(0,0,cnt-1,x,x,i-*id[x].rbegin()); } id[x].insert(i); a[i]=x; } void solve(){ for(auto x:a)ha[x]=1; for(auto x:val)ha[x]=1; for(auto &x:ha){ x.second=cnt++; } for(int i=0;i<cnt;i++){ id[i].insert(-maxn); } for(int i=0;i<a.size();i++){ a[i]=ha[a[i]]; id[a[i]].insert(i); upd(0,0,cnt-1,a[i],cnt-1,-1); } for(int i=0;i<cnt;i++){ upd(0,0,cnt-1,i,i,*id[i].rbegin()); } for(int q=0;q<pos.size();q++){ rem(pos[q],a[pos[q]]); add(pos[q],ha[val[q]]); ans.pb(st[0]+1); } } vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) { a = A; pos = X; val = V; solve(); return ans; }

Compilation message (stderr)

bubblesort2.cpp: In function 'void solve()':
bubblesort2.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
bubblesort2.cpp:76:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int q=0;q<pos.size();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...