Submission #571566

#TimeUsernameProblemLanguageResultExecution timeMemory
571566elazarkorenSeats (IOI18_seats)C++17
33 / 100
1746 ms91700 KiB
#include <bits/stdc++.h> #define x first #define y second #define all(v) v.begin(), v.end() #define chkmin(a, b) a = min(a, b) #define chkmax(a, b) a = max(a, b) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vii; const int MAX_N = 1e6 + 5; struct Seg { int n; vi seg, cnt, add; Seg() {} Seg(int m) { n = m; // for (n = 1; n < m; n <<= 1); seg.resize(4 * n); cnt.resize(4 * n); add.resize(4 * n); Init(1, 0, n); } void Init(int i, int l, int r) { cnt[i] = r - l; if (l + 1 == r) return; Init(i << 1, l, (l + r) >> 1), Init(i << 1 | 1, (l + r) >> 1, r); } inline int Val(int i) { return seg[i] + add[i]; } inline void push(int i) { add[i << 1] += add[i]; add[i << 1 | 1] += add[i]; seg[i] += add[i]; add[i] = 0; } inline void pull(int i) { int x1 = Val(i << 1), x2 = Val(i << 1 | 1); seg[i] = min(x1, x2); if (x1 == x2) { cnt[i] = cnt[i << 1] + cnt[i << 1 | 1]; } else if (x1 < x2) { cnt[i] = cnt[i << 1]; } else cnt[i] = cnt[i << 1 | 1]; } void update(int a, int b, int x, int i, int l, int r) { if (a <= l && r <= b) { add[i] += x; return; } if (r <= a || b <= l) return; push(i); update(a, b, x, i << 1, l, (l + r) >> 1); update(a, b, x, i << 1 | 1, (l + r) >> 1, r); pull(i); } inline void update(int a, int b, int x) { update(a, b, x, 1, 0, n); } }; int r[MAX_N], c[MAX_N]; int ind[MAX_N]; Seg seg; int n; int h, w; inline void update(int i, int j, int x) { int y1 = i >= 0 ? ind[i] : n + 1; int y2 = ind[j]; if (y1 > y2) swap(y1, y2); seg.update(y1, y2, x); } bitset<MAX_N> color; void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { h = H, w = W; n = h * w; seg = Seg(n); for (int i = 0; i < n; i++) r[i] = R[i], c[i] = C[i]; for (int i = 0; i < n; i++) ind[c[i]] = i; ind[n] = n; for (int i = 0; i <= n; i++) { update(i - 1, i, 1); // update(i, i + 1, 1), update(i - 1, i, 1); } } int swap_seats(int a, int b) { // if (a > b) swap(a, b); int x1 = c[a], x2 = c[b]; update(x1 - 1, x1, -1), update(x1, x1 + 1, -1); update(x2 - 1, x2, -1), update(x2, x2 + 1, -1); swap(c[a], c[b]); ind[c[a]] = a, ind[c[b]] = b; update(x1 - 1, x1, 1), update(x1, x1 + 1, 1); update(x2 - 1, x2, 1), update(x2, x2 + 1, 1); return seg.cnt[1]; } //1 5 3 //0 2 //0 0 //0 3 //0 1 //0 4 //0 1 //2 4 //3 0
#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...