Submission #200092

#TimeUsernameProblemLanguageResultExecution timeMemory
200092anonymousArranging Shoes (IOI19_shoes)C++14
100 / 100
140 ms17528 KiB
#include "shoes.h" #include<queue> #define LL long long #define MAXN 200005 using namespace std; LL N, BIT[MAXN], ans; priority_queue<int> PQ[MAXN>>1][2]; //only BIT is 1 indexed bool del[MAXN]; int abs(int i) {return(i > 0 ? i : -i);} void upd(int p, int v) { for (; p<=N+5; p+=p&(-p)) {BIT[p]+=v;} } LL ask(int p) { LL res=0; for (; p>0; p-=p&(-p)) {res+=BIT[p];} return(res); } long long count_swaps(std::vector<int> s) { N=s.size(); for (int i=1; i<=N; i++) { upd(i,1); PQ[abs(s[i-1])][s[i-1]<0].push(1-i); } for (int i=0; i<N; i++) { if (del[i]) {continue;} LL v; while (true) { v=-PQ[abs(s[i])][s[i]>0].top(); PQ[abs(s[i])][s[i]>0].pop(); if (del[v]) {continue;} else {break;} } ans+=ask(v)-ask(i+1); if (s[i] > 0) {ans++;} del[i]=del[v]=true; upd(v+1, -1); upd(i+1, -1); } return(ans); }
#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...