제출 #1047444

#제출 시각아이디문제언어결과실행 시간메모리
1047444NotLinuxArranging Shoes (IOI19_shoes)C++17
100 / 100
321 ms148332 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; #define sz(x) (int)x.size() #define all(x) x.begin(),x.end() const long long inf = 1e18 + 7; struct SEGT{ vector < int > t; int tree_size; const int identity_element = 0; int merge(int x , int y){ return x + y; } void init(int x){ tree_size = x+3; t.assign(2*tree_size , identity_element); } void modify(int p, int value) { // set value at position p for (t[p += tree_size] = value; p > 1; p >>= 1){ t[p>>1] = merge(t[p] , t[p^1]); } } int query(int l, int r) { // sum on interval [l, r] int res = identity_element; for (r+=1 , l += tree_size, r += tree_size; l < r; l >>= 1, r >>= 1) { if (l&1) res = merge(res , t[l++]); if (r&1) res = merge(res , t[--r]); } return res; } }; long long count_swaps(vector<int> s) { int n = sz(s) / 2; long long ans = 0; SEGT segt; segt.init(2*n+5); map < int , queue < int > > mpa; int vis[2*n]; memset(vis , 0 , sizeof(vis)); for(int i = 0;i<2*n;i++){ mpa[s[i]].push(i); segt.modify(i , 1); } for(int i = 0;i<2*n;i++){ if(vis[i])continue; int nxt = mpa[-s[i]].front(); // cout << i << " : " << nxt << endl; mpa[s[i]].pop(); mpa[-s[i]].pop(); vis[i] = vis[nxt] = 1; segt.modify(i , 0); segt.modify(nxt , 0); ans += segt.query(0 , nxt); if(s[i] > 0)ans++; } 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...