Submission #211128

#TimeUsernameProblemLanguageResultExecution timeMemory
211128vincent97198Arranging Shoes (IOI19_shoes)C++14
0 / 100
1098 ms408 KiB
#include <bits/stdc++.h> #define N 100005 using namespace std; int BIT[2*N]; inline int lowbit(int x) { return x&(-x); } void add(int pos,int val) { for(;pos<N;pos+=lowbit(pos)) BIT[pos]+=val; } int sum(int pos) { int ret=0; for(;pos>0;pos-=lowbit(pos)) ret+=BIT[pos]; return ret; } long long count_swaps(vector<int> S) { map<long long,queue<int>> mp; long long ans=0; for(int i=0;i<S.size();++i){ mp[S[i]].push(i); add(i+1,1); } for(int i=0;i<S.size();++i){ mp[S[i]].pop(); int t=mp[-S[i]].front(); mp[-S[i]].pop(); ans+=(sum(i+1)-sum(t-1)); add(t,-1); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:32:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<S.size();++i){
              ~^~~~~~~~~
shoes.cpp:36:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  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...