제출 #797945

#제출 시각아이디문제언어결과실행 시간메모리
797945MularstyleArranging Shoes (IOI19_shoes)C++14
0 / 100
1 ms256 KiB
#include<bits/stdc++.h> using namespace std; #include "shoes.h" #define ll long long int n; ll ar[200005]; bool vis[200005]; void up(int idx,int x) { while(idx<=n)ar[idx]+=x,idx+=(idx&-idx); } int re(int idx) { ll sum=0; while(idx>0)sum+=ar[idx],idx-=(idx&-idx); return sum; } long long count_swaps(std::vector<int> os) { ll ans=0; n=os.size(); int s[n+5]; for(int i=1;i<=n;i++) s[i]=os[i-1]; vector<int> S[n]; int pidx[n+5]; for(int i=1;i<=n;i++) { up(i,1); if(S[abs(s[i])].empty()) S[abs(s[i])].push_back(i); else { int tmp=S[abs(s[i])].back(); if(s[i]!=s[tmp]) { pidx[i]=tmp; pidx[tmp]=i; S[abs(s[i])].pop_back(); } else { S[abs(s[i])].push_back(i); } } } for(int i=1;i<=n;i++) { if(vis[pidx[i]])continue; vis[i]=true; ans+=((re(pidx[i])-re(i-1))-2); if(ar[i]>0)//rightonleft ans++; up(i,-1); up(pidx[i],-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...