(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #555900

#TimeUsernameProblemLanguageResultExecution timeMemory
555900cheissmartSeats (IOI18_seats)C++14
100 / 100
2664 ms119224 KiB
#include "seats.h" #include <bits/stdc++.h> #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(v) int((v).size()) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7, N = 1e6 + 7; int H, W; namespace DS { pi t[N * 4]; int lz[N * 4]; void apply(int v, int x) { lz[v] += x; t[v].F += x; } void push(int v) { apply(v * 2, lz[v]); apply(v * 2 + 1, lz[v]); lz[v] = 0; } pi add(pi a, pi b) { if(a.F != b.F) return min(a, b); a.S += b.S; return a; } void build(int v = 1, int tl = 0, int tr = H * W) { if(tr - tl == 1) { t[v] = {0, 1}; return; } int tm = (tl + tr) / 2; build(v * 2, tl, tm); build(v * 2 + 1, tm, tr); t[v] = add(t[v * 2], t[v * 2 + 1]); } void upd(int l, int r, int x, int v = 1, int tl = 0, int tr = H * W) { if(l <= tl && tr <= r) { apply(v, x); return; } push(v); int tm = (tl + tr) / 2; if(l < tm) upd(l, r, x, v * 2, tl, tm); if(r > tm) upd(l, r, x, v * 2 + 1, tm, tr); t[v] = add(t[v * 2], t[v * 2 + 1]); } } V<vi> a; vi R, C; void upd(int i, int j, int op) { int aux[] = {a[i][j], a[i + 1][j], a[i][j + 1], a[i + 1][j + 1]}; sort(aux, aux + 4); if(aux[0] < aux[1]) DS::upd(aux[0], aux[1], op);//, cerr << aux[0] << " " << aux[1] << " " << op << endl; if(aux[2] < aux[3]) DS::upd(aux[2], aux[3], op);//, cerr << aux[2] << " " << aux[3] << " " << op << endl; } void set_val(int i, int j, int x) { upd(i - 1, j - 1, -1); upd(i, j - 1, -1); upd(i - 1, j, -1); upd(i, j, -1); a[i][j] = x; upd(i - 1, j - 1, 1); upd(i, j - 1, 1); upd(i - 1, j, 1); upd(i, j, 1); } void give_initial_chart(int _H, int _W, vi _R, vi _C) { H = _H, W = _W, R = _R, C = _C; a = V<vi> (H + 2, vi(W + 2, H * W)); for(int i = 0; i < SZ(R); i++) { ++R[i], ++C[i]; a[R[i]][C[i]] = i; } DS::build(); for(int i = 0; i <= H; i++) for(int j = 0; j <= W; j++) upd(i, j, 1); } int swap_seats(int x, int y) { int val_x = a[R[x]][C[x]]; int val_y = a[R[y]][C[y]]; set_val(R[x], C[x], val_y); set_val(R[y], C[y], val_x); swap(R[x], R[y]), swap(C[x], C[y]); return DS::t[1].S; }
#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...