제출 #173000

#제출 시각아이디문제언어결과실행 시간메모리
173000FieryPhoenixArranging Shoes (IOI19_shoes)C++17
0 / 100
2 ms504 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <cstdio> #include <map> #include <queue> #include <set> #include <iomanip> #include <deque> #include <cassert> #include <ctime> #include <cstring> #include <cstdlib> #include <chrono> #include <ctime> #include <random> #include <stack> #include <unordered_set> #include <unordered_map> #include <iterator> #include <climits> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; typedef long double ld; #define INF 2001001001 #define MOD 1000000007 int N; map<int,int>mp; int tree[200001]; bool dead[200001]; void update(int pos, int val){ while (pos<=N*2){ tree[pos]+=val; pos+=(pos&(-pos)); } } int query(int pos){ int ans=0; while (pos>=1){ ans+=tree[pos]; pos-=(pos&(-pos)); } return ans; } ll count_swaps(vector<int>S){ int N=(int)S.size()/2; for (int i=1;i<=N*2;i++){ mp[S[i-1]]=i; update(i,1); } ll ans=0; for (int i=1;i<=N*2;i++){ if (dead[i]) continue; int target=mp[S[i-1]*(-1)]; ans+=query(target)-query(i-1)-2; if (S[i]>0) ans++; dead[i]=true; update(i,-1); dead[target]=true; update(target,-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...