제출 #169780

#제출 시각아이디문제언어결과실행 시간메모리
169780arthur_nascimentoArranging Shoes (IOI19_shoes)C++14
10 / 100
74 ms67832 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; #define pb push_back #define debug printf #define ll long long #define maxn 100100 stack<int> st[maxn]; int par[maxn]; int foi[maxn]; int T[maxn]; void upd(int idx,int val){ idx++; while(idx < maxn){ T[idx] += val; idx += (idx&-idx); } } int get(int idx){ //debug("get %d\n",idx); idx++;; int r = 0; while(idx){ r += T[idx]; idx -= (idx&-idx); } //debug("-> %d\n",r); return r; } long long count_swaps(std::vector<int> S){ int n = S.size(); ll ans = 0; for(int i=0;i<n;i++){ //debug("i %d %d\n",i,S[i]); int sz = abs(S[i]); if(st[sz].size() > 0 && S[st[sz].top()] == - S[i]){ if(S[i] < 0) ans++; par[st[sz].top()] = i; // debug("%d - %d\n",st[sz].top(),i); st[sz].pop(); } else { st[sz].push(i); //debug("add\n"); } } for(int i=0;i<n;i++) upd(i,1); for(int i=0;i<n;i++) if(!foi[i]){ int u = par[i]; ans += get(u-1) - get(i); upd(u,-1); foi[u] = 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...