제출 #642948

#제출 시각아이디문제언어결과실행 시간메모리
642948tigarArranging Shoes (IOI19_shoes)C++14
0 / 100
0 ms212 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll fenvick[200020]; void fenvick_add(int x, int n) { int x1=x; while(x1<=n) { fenvick[x1]++; x1+=((-x1)&x1); } } ll fenvick_sum(int x) { int x1=x, rz=0; while(x1>0) { rz+=fenvick[x1]; x1-=((-x1)&x1); } return rz; } ll count_swaps(vector<int>S) { int n=S.size()/2; stack<pair<int, int> >patike[n+1]; ll reez=0; int poooz[n*2+1]={0}; for(int i=0; i<2*n; i++) { if(patike[abs(S[i])].empty()) { if(S[i]<0)patike[abs(S[i])].push({i+1, -1}); else patike[abs(S[i])].push({i+1, 1}); } else { if(patike[abs(S[i])].top().second>0 and S[i]>0) patike[abs(S[i])].push({i+1, 1}); else if(patike[abs(S[i])].top().second<0 and S[i]<0) patike[abs(S[i])].push({i+1, -1}); else if(patike[abs(S[i])].top().second<0 and S[i]>0) { poooz[i+1]=patike[abs(S[i])].top().first; poooz[patike[abs(S[i])].top().first]=i+1; patike[abs(S[i])].pop(); } else if(patike[abs(S[i])].top().second>0 and S[i]<0) { poooz[i+1]=patike[abs(S[i])].top().first; poooz[patike[abs(S[i])].top().first]=i+1; patike[abs(S[i])].pop(); reez++; } } } for(int i=1; i<=2*n; i++) { if(fenvick[i]==0) { fenvick_add(i, 2*n); fenvick_add(poooz[i], 2*n); } if(fenvick[i]==1) { reez+=fenvick_sum(i)-fenvick_sum(poooz[i]); } } return reez; }
#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...