Submission #259302

#TimeUsernameProblemLanguageResultExecution timeMemory
259302LifeHappen__Arranging Shoes (IOI19_shoes)C++14
100 / 100
194 ms139384 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; #define forinc(a, b, c) for(int a = b, _c = c; a <= _c; ++a) #define fordec(a, b, c) for(int a = b, _c = c; a >= _c; --a) #define forv(a, b) for(auto &a : b) #define rep(i, n) forinc(i, 1, n) #define repv(i, n) forinc(i, 0, n - 1) #define eb emplace_back #define pb push_back #define mp make_pair #define fi first #define se second #define all(a) a.begin(), a.end() #define reset(f, x) memset(f, x, sizeof(f)) #define gcd __gcd #define __builtin_popcount __builtin_popcountll #define fasty ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define bit(x, i) (x >> (i - 1) & 1ll) #define on(x, i) (x | (1ll << (i - 1))) #define off(x, i) (x & ~(1ll << (i - 1))) typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<pair<int,int>> vii; typedef long long ll; typedef unsigned long long ull; typedef double db; const int N = 1e5 + 10; long long it[N * 2]; queue<int> s[N * 2]; void upd(int i, int val) { for(; i < 2*N; i += i & -i) it[i] += val; } int get(int i) { int ans = 0; for(; i; i -= i & -i) ans += it[i]; return ans; } long long count_swaps(vector<int> S) { long long ans = 0; forinc(i, 1, S.size()) { int u = S[i - 1]; if(s[N - u].size()) { int j = s[N - u].front(); s[N - u].pop(); ans += i - j - (u > 0); ans -= get(i) - get(j); upd(j, -1); } else { s[N + u].push(i); upd(i, 1); } } return ans; } /* int32_t main() { cin >> n; vector <int> T; forinc(i, 1, 2 * n) { int x; cin >> x; T.pb(x); } cout << count_swaps(T); } */
#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...