Submission #758868

#TimeUsernameProblemLanguageResultExecution timeMemory
758868FidiskArranging Shoes (IOI19_shoes)C++14
100 / 100
184 ms274516 KiB
#include <bits/stdc++.h> using namespace std; #define edge(xxxx,yyyy) ((xxxx)*(m+5)+(yyyy)) #define oo 1e18 #define fi first #define se second #define sp(iiii) setprecision(iiii) #define IO ios_base::sync_with_stdio(false); cin.tie(0) #define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa)) #define cntbit(xxxx) __builtin_popcount(xxxx) #define getbit(xxxx,aaaa) (((xxxx)>>((aaaa)-1))&1) #define totbit(xxxx) (32-__builtin_clz(xxxx)) #define totbitll(xxxx) (64-__builtin_clzll(ll(xxxx))) typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<pair<int,int>,int> piii; typedef pair<long long,long long> pll; typedef pair<pair<long long,long long>,long long> plll; typedef pair<pair<long long,long long>,pair<long long,long long>> pllll; typedef pair<pair<long long,long long>,bool> pllb; const ll base=333333349; const ll mod=1e9+7; const ld eps=1e-5; const ll maxn=50009; vector<int> a,b; int n,cnt,bit[200009]; queue<int> g[200009],h[200009]; ll get(ll x) { ll kq=0; for (;x>0;x-=x&(-x)) { kq+=bit[x]; } return kq; } void add(ll x) { for (;x<=n;x+=x&(-x)) { bit[x]++; } } long long count_swaps(vector<int> a) { n=a.size(); cnt=0; b.resize(n); for (int i=0;i<n;i++) { if (a[i]>0) { if (g[a[i]].empty()) { h[a[i]].push(i); } else { cnt++; b[g[a[i]].front()]=cnt; g[a[i]].pop(); cnt++; b[i]=cnt; } } else { a[i]=-a[i]; if (h[a[i]].empty()) { g[a[i]].push(i); } else { cnt++; b[i]=cnt; cnt++; b[h[a[i]].front()]=cnt; h[a[i]].pop(); } } } long long kq=0; for (int i=0;i<n;i++) { kq+=get(n)-get(b[i]); add(b[i]); } return kq; }
#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...