Submission #259413

#TimeUsernameProblemLanguageResultExecution timeMemory
259413astoriaArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "bits/stdc++.h" using namespace std; #define ll long long #define MAXN 200005 int ft[MAXN]; int sum(int r){ int an=0; for(int i=r; i>=0; i=(i&(i+1))-1){ an += ft[i]; } return an; } int sum(int l, int r){ if(l!=0) return sum(r)-sum(l-1); else return sum(r); } void add(int r, int x){ for(int i=r; i<MAXN; i|=(i+1)){ ft[i] += x; } } long long count_swaps(std::vector<int> s) { int n=s.size()/2; int clo[2*n]; queue<int> have[3][n+5]; for(int i=0; i<2*n; i++){ int x = s[i], y=abs(s[i]); if(x<0){ if(!have[2][y].empty()){ clo[have[2][y].front()] = i; have[2][y].pop(); } else have[1][y].push(i); } if(x>0){ if(!have[1][y].empty()){ clo[have[1][y].front()] = i; have[1][y].pop(); } else have[2][y].push(i); } } memset(ft,0,sizeof(ft)); bool taken[2*n]; memset(taken,0,sizeof(taken)); ll an=0; for(int i=0; i<2*n; i++){ if(taken[i]) continue; int b = sum(i,clo[i]); b += (clo[i]-i-1); if(s[i]>0) b++; an+=b; add(clo[i],-1); taken[clo[i]]=1; } return an; } int main() { int n; assert(1 == scanf("%d", &n)); vector<int> S(2 * n); for (int i = 0; i < 2 * n; i++) assert(1 == scanf("%d", &S[i])); //fclose(stdin); long long result = count_swaps(S); printf("%lld\n", result); //fclose(stdout); return 0; }

Compilation message (stderr)

/tmp/ccf48eHQ.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccfBJJYL.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status