Submission #161689

#TimeUsernameProblemLanguageResultExecution timeMemory
161689InkretBearArranging Shoes (IOI19_shoes)C++14
0 / 100
2 ms504 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; const int MAXN=200000+100; int fen[MAXN]; int querry(int j){ if (j==0){ return 0; } return fen[j]+querry(j-(j&-j)); } long long count_swaps(vector<int> a){ return 0; int n=a.size(); int f=0; long long rez=0; vector<int> v1[MAXN],v2[MAXN]; for (int i=0;i<n;++i){ int curr=a[i]; if (curr>0){ v1[curr].push_back(i); if (!v2[curr].empty()){ int x=*--v2[curr].end(); v2[curr].pop_back(); v1[curr].pop_back(); rez+=i+x-2*f-querry(i+1)-querry(x+1)+2*querry(1+2*f); for (int j=i+1;j<=MAXN;j+=j&-j){ ++fen[j]; } for (int j=x+1;j<=MAXN;j+=j&-j){ ++fen[j]; } ++f; } } else { curr*=-1; v2[curr].push_back(i); if (!v1[curr].empty()){ int x=*--v1[curr].end(); v2[curr].pop_back(); v1[curr].pop_back(); rez+=i+x-2*f-querry(i+1)-querry(x+1)+2*querry(1+2*f)-1; for (int j=i+1;j<=MAXN;j+=j&-j){ ++fen[j]; } for (int j=x+1;j<=MAXN;j+=j&-j){ ++fen[j]; } ++f; } } } return rez; }
#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...