Submission #268130

#TimeUsernameProblemLanguageResultExecution timeMemory
268130shinjanArranging Shoes (IOI19_shoes)C++14
100 / 100
204 ms138744 KiB
#include <iostream> #include <bits/stdc++.h> #include "shoes.h" #define maxN 200005 using namespace std; int fen[maxN]; void add(int ind,int n) { for(int i=ind;i<=n;i+=(i&(-i))) { fen[i]++; } } void brisi(int ind,int n) { for(int i=ind;i<=n;i+=(i&(-i))) { fen[i]--; } } long long sum(int ind) { long long ans=0; for(int i=ind;i>=1;i-=(i&(-i))) { ans+=fen[i]; } return ans; } long long count_swaps(vector <int> s) { int n=s.size(); long long ans=0; queue<int> neg[n/2+1]; queue<int> poz[n/2+1]; for(int i=0;i<s.size();i++) { if(s[i]>0) { if(neg[s[i]].size()!=0) { int pos=neg[s[i]].front(); ans-=(sum(i)-sum(pos+1)); brisi(pos+1,n); ans+=(i-pos-1); neg[s[i]].pop(); } else{ poz[s[i]].push(i); add(i+1,n); } } if(s[i]<0) { int x=abs(s[i]); if(poz[x].size()!=0) { int pos=poz[x].front(); ans-=(sum(i)-sum(pos+1)); brisi(pos+1,n); ans+=(i-pos); poz[x].pop(); } else{ neg[x].push(i); add(i+1,n); } } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     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...