Submission #776720

#TimeUsernameProblemLanguageResultExecution timeMemory
776720WarinchaiArranging Shoes (IOI19_shoes)C++14
50 / 100
209 ms277892 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; queue<int>q[100005]; queue<int>nq[100005]; int check[100005]; struct fenwick{ int info[100005]; void upd(int idx,int val){ for(int i=idx;i<=100000;i+=i&-i){ info[i]+=val; } } int fsum(int idx){ int sum=0; for(int i=idx;i>0;i-=i&-i){ sum+=info[i]; } return sum; } }fw; long long count_swaps(vector<int>s) { //cout<<"work"<<endl; for(int i=0;i<s.size();i++){ if(s[i]>=0){ q[s[i]].push(i+1); }else{ nq[s[i]*-1].push(i+1); } } long long ans=0; for(int i=0;i<s.size();i++){ if(check[i]==0){ int x=s[i]; int nx=s[i]*-1; if(x>=0){ int id=nq[nx*-1].front(); nq[nx*-1].pop(); q[x].pop(); int sz=id-1-i; int st=i+1; //cout<<"id,i:"<<id<<" "<<i+1<<endl; //cout<<sz<<" "; sz-=fw.fsum(id)-fw.fsum(st); //cout<<sz<<endl; ans+=sz; check[i]=1; check[id-1]=1; fw.upd(id,1); }else{ int id=q[nx].front(); q[nx].pop(); nq[nx].pop(); //cout<<"id,i:"<<id<<" "<<i+1<<endl; int sz=id-2-i; int st=i+1; //cout<<sz<<" "; sz-=fw.fsum(id)-fw.fsum(st); ans+=sz; //cout<<sz<<endl; check[i]=1; check[id-1]=1; fw.upd(id,1); } } } //cout<<ans<<endl; return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:24:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for(int i=0;i<s.size();i++){
      |              ~^~~~~~~~~
shoes.cpp:32:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int 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...