Submission #569358

#TimeUsernameProblemLanguageResultExecution timeMemory
569358ngpin04Seats (IOI18_seats)C++17
33 / 100
1258 ms69432 KiB
#include "seats.h" #include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define TASK "" #define bit(x) (1LL << (x)) #define getbit(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() using namespace std; template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count()); int rand(int l, int r) { return l + rd() % (r - l + 1); } const int N = 1e6 + 5; const int oo = 1e9; const long long ooo = 1e18; const int mod = 1e9 + 7; // 998244353; const long double pi = acos(-1); typedef tuple <int, int, int, int> pir; pair <int, int> st[N << 2]; int lz[N << 2]; int x[N]; int y[N]; int a[N]; int n,m,sz,ans; void dolazy(int id) { for (int i = (id << 1); i <= (id << 1 | 1); i++) { lz[i] += lz[id]; st[i].fi += lz[id]; } lz[id] = 0; } void build(int id, int l, int r) { if (l == r) { st[id].se = 1; return; } int mid = (l + r) >> 1; build(id << 1, l, mid); build(id << 1 | 1, mid + 1, r); } void update(int id, int l, int r, int u, int v, int val) { if (l > v || r < u) return; if (l >= u && r <= v) { lz[id] += val; st[id].fi += val; return; } int mid = (l + r) >> 1; dolazy(id); update(id << 1, l, mid, u, v, val); update(id << 1 | 1, mid + 1, r, u, v, val); st[id] = st[id << 1]; if (st[id].fi > st[id << 1 | 1].fi) st[id] = st[id << 1 | 1]; else if (st[id].fi == st[id << 1 | 1].fi) st[id].se += st[id << 1 | 1].se; } void update(int l, int r, int val) { // cerr << l << " " << r << " " << val << "\n"; update(1, 0, sz - 1, l, r, val); } int getmin() { return st[1].se; } void give_initial_chart(int H, int W, vector<int> R, vector<int> C) { n = H; m = W; sz = n * m; build(1, 0, sz - 1); for (int i = 0; i < n * m; i++) { x[i] = R[i], y[i] = C[i]; a[y[i]] = i; } for (int i = 0; i < sz; i++) update(i, i, i); for (int i = 0; i + 1 < n * m; i++) update(max(a[i], a[i + 1]), sz - 1, -1); } void add(int i, int val) { int pos = y[i]; if (pos > 0) update(max(a[pos - 1], a[pos]), m - 1, val); if (pos + 1 < m) update(max(a[pos], a[pos + 1]), m - 1, val); } int sub4() { return getmin(); } int swap_seats(int l, int r) { add(l, 1); add(r, 1); swap(y[l], y[r]); swap(a[y[l]], a[y[r]]); add(l, -1); add(r, -1); if (n == 1) return sub4(); return -1; } //#include "grader.cpp"
#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...