Submission #157517

#TimeUsernameProblemLanguageResultExecution timeMemory
157517tevdoreArranging Shoes (IOI19_shoes)C++14
0 / 100
275 ms269640 KiB
#include<bits/stdc++.h> #define mid (L+R)/2 using namespace std; int n,i,ans,k; int x[200001],sg[200001]; queue<int>q1[200001]; queue<int>q2[200001]; void upd(int u,int L,int R,int pos,int y){ if(R < pos || L > pos)return; if(R == L){sg[u]=y;return;} else{ upd(u*2,L,mid,pos,y); upd(u*2+1,mid+1,R,pos,y); sg[u]=sg[u*2]+sg[u*2+1]; } } int get(int u,int L,int R,int a,int b){ if(b < L || a > R)return 0; if(a <= L && b >= R)return sg[u]; return(get(u*2,L,mid,a,b)+get(u*2+1,mid+1,R,a,b)); } int count_swaps(std:: vector<int>s){ for(i=0;i<s.size();i++){ upd(1,1,s.size(),i+1,1); } for(i=0;i<s.size();i++){ if(s[i] < 0){ k=-(s[i]); if(q2[k].size() == 0){ q1[k].push(i+1); continue; } ans+=get(1,1,s.size(),q2[k].front()+1,i+1)-1; upd(1,1,s.size(),q2[k].front()+1,2); upd(1,1,s.size(),i+1,0); q2[k].pop(); } if(s[i] > 0){ k=s[i]; if(q1[k].size() == 0){ q2[k].push(i+1); continue; } ans+=get(1,1,s.size(),q1[k].front()+1,i+1)-2; upd(1,1,s.size(),q1[k].front()+1,2); upd(1,1,s.size(),i+1,0); q1[k].pop(); } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'int count_swaps(std::vector<int>)':
shoes.cpp:23:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<s.size();i++){
             ~^~~~~~~~~
shoes.cpp:26:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<s.size();i++){
             ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...