제출 #808834

#제출 시각아이디문제언어결과실행 시간메모리
808834OrazBArranging Shoes (IOI19_shoes)C++14
100 / 100
290 ms275864 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define all(x) (x).begin(), (x).end() #define ll long long int #define pii pair <int, int> #define pb push_back #define ff first #define ss second const int N = 2e5+5; deque<int> lft[N], rgt[N]; ll count_swaps(vector<int> S){ int n = S.size(); S.insert(S.begin(), -1); for (int i = 1; i <= n; i++){ if (S[i] > 0) rgt[S[i]].pb(i); else lft[-S[i]].pb(i); } ll ans = 0; ordered_set s; for (int i = 1; i <= n; i++){ if (s.find(i) != s.end()) continue; int j = 0; while(s.size() and (*s.begin()) <= i) s.erase(s.begin()); if (S[i] > 0) j = lft[S[i]].front(); else j = rgt[-S[i]].front(); lft[abs(S[i])].pop_front(); rgt[abs(S[i])].pop_front(); ans += (j-i-s.order_of_key(j)-(S[i] < 0)); s.insert(j); } 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...