제출 #1224931

#제출 시각아이디문제언어결과실행 시간메모리
1224931AmirAli_H1Arranging Shoes (IOI19_shoes)C++17
100 / 100
66 ms57532 KiB
// In the name of Allah #include <bits/stdc++.h> #include "shoes.h" using namespace std; typedef long long int ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef complex<ld> cld; #define all(x) (x).begin(),(x).end() #define len(x) ((ll) (x).size()) #define F first #define S second #define pb push_back #define sep ' ' #define endl '\n' #define Mp make_pair #define kill(x) cout << x << '\n', exit(0) #define set_dec(x) cout << fixed << setprecision(x); #define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 1e6 + 4; int n; vector<pii> lsx; vector<int> ls0[maxn], ls1[maxn]; ll t[maxn]; void addx(int i, ll x) { for (++i; i < maxn; i += (i & -i)) t[i] += x; } ll getx(int i) { ll res = 0; for (++i; i > 0; i -= (i & -i)) res += t[i]; return res; } ll count_swaps(vector<int> s) { n = len(s) / 2; for (int i = 0; i < (2 * n); i++) { int j = abs(s[i]) - 1; if (s[i] < 0) ls0[j].pb(i); else ls1[j].pb(i); } ll ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < len(ls0[i]); j++) { int lx = ls0[i][j], rx = ls1[i][j]; if (lx > rx) { swap(lx, rx); ans++; } lsx.pb(Mp(lx, rx)); } } sort(all(lsx)); reverse(all(lsx)); for (auto f : lsx) { int lx = f.F, rx = f.S; ans += getx(rx - 1) - getx(lx); addx(lx, 1); addx(rx, 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...