제출 #259408

#제출 시각아이디문제언어결과실행 시간메모리
259408astoriaArranging Shoes (IOI19_shoes)C++14
10 / 100
1092 ms1152 KiB
#include "shoes.h" #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]; int have[3][n+5]; memset(have,-1,sizeof(have)); memset(clo,-1,sizeof(clo)); for(int i=0; i<2*n; i++){ int x = s[i], y=abs(s[i]); if(x<0){ if(have[2][y]!=-1){ clo[have[2][y]] = i; have[2][y]=-1; } else have[1][y]=i; } if(x>0){ if(have[1][y]!=-1){ clo[have[1][y]] = i; have[1][y]=-1; } else have[2][y]=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; }
#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...