Submission #341757

#TimeUsernameProblemLanguageResultExecution timeMemory
341757ogibogi2004Arranging Shoes (IOI19_shoes)C++14
100 / 100
101 ms19820 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long const int MAXN=2e5+6; int fen[MAXN]; void update(int idx,int val) { idx++; for(;idx<MAXN;idx+=idx&(-idx)) { fen[idx]+=val; } } int query(int idx) { idx++; int ret=0; for(;idx>0;idx-=idx&(-idx)) { ret+=fen[idx]; } return ret; } vector<int>shoes[MAXN][2]; bool vis[MAXN]; long long count_swaps(vector<int> s) { for(int i=0;i<s.size();++i) { if(s[i]>0)shoes[s[i]][0].push_back(i); else shoes[-s[i]][1].push_back(i); } for(int i=0;i<MAXN;i++) { reverse(shoes[i][0].begin(),shoes[i][0].end()); reverse(shoes[i][1].begin(),shoes[i][1].end()); } for(int i=0;i<s.size();++i) { update(i,+1); } ll ans=0; for(int i=0;i<s.size();++i) { if(vis[i])continue; if(s[i]<0) { int k=shoes[-s[i]][0].back(); ans+=(ll)query(k)-query(i)-1; update(i,+1); vis[k]=1; update(k+1,-1); shoes[-s[i]][0].pop_back(); shoes[-s[i]][1].pop_back(); } else { int k=shoes[s[i]][1].back(); ans+=(ll)query(k)-query(i); update(i,+1); update(k+1,-1); vis[k]=1; shoes[s[i]][1].pop_back(); shoes[s[i]][0].pop_back(); } } return ans; }

Compilation message (stderr)

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