(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 #768480

#TimeUsernameProblemLanguageResultExecution timeMemory
768480SanguineChameleonSeats (IOI18_seats)C++17
100 / 100
2033 ms103252 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; const int maxN = 1e6 + 20; pair<int, int> tree[maxN * 4]; int lazy[maxN * 4]; int R[maxN]; int C[maxN]; vector<vector<int>> seats; int N; void build_tree(int id, int lt, int rt) { if (lt == rt) { tree[id] = make_pair(0, 1); return; } int mt = (lt + rt) >> 1; build_tree(id << 1, lt, mt); build_tree(id << 1 | 1, mt + 1, rt); tree[id] = make_pair(0, rt - lt + 1); } void update_tree(int id, int lt, int rt, int ql, int qr, int add) { if (lt == ql && rt == qr) { tree[id].first += add; lazy[id] += add; return; } tree[id << 1].first += lazy[id]; lazy[id << 1] += lazy[id]; tree[id << 1 | 1].first += lazy[id]; lazy[id << 1 | 1] += lazy[id]; lazy[id] = 0; int mt = (lt + rt) >> 1; if (qr <= mt) { update_tree(id << 1, lt, mt, ql, qr, add); } else if (ql >= mt + 1) { update_tree(id << 1 | 1, mt + 1, rt, ql, qr, add); } else { update_tree(id << 1, lt, mt, ql, mt, add); update_tree(id << 1 | 1, mt + 1, rt, mt + 1, qr, add); } tree[id].first = min(tree[id << 1].first, tree[id << 1 | 1].first); tree[id].second = (tree[id << 1].first == tree[id].first ? tree[id << 1].second : 0) + (tree[id << 1 | 1].first == tree[id].first ? tree[id << 1 | 1].second : 0); } void update_square(int i, int j, int add) { int val1 = seats[i][j]; int val2 = seats[i][j + 1]; int val3 = seats[i + 1][j]; int val4 = seats[i + 1][j + 1]; if (val1 > val2) { swap(val1, val2); } if (val1 > val3) { swap(val1, val3); } if (val1 > val4) { swap(val1, val4); } if (val2 > val3) { swap(val2, val3); } if (val2 > val4) { swap(val2, val4); } if (val3 > val4) { swap(val3, val4); } if (val1 < val2) { update_tree(1, 1, N, val1, val2 - 1, add); } if (val3 < val4) { update_tree(1, 1, N, val3, val4 - 1, add); } } void update_pos(int i, int j, int val) { update_square(i - 1, j - 1, -1); update_square(i - 1, j, -1); update_square(i, j - 1, -1); update_square(i, j, -1); seats[i][j] = val; update_square(i - 1, j - 1, 1); update_square(i - 1, j, 1); update_square(i, j - 1, 1); update_square(i, j, 1); } void give_initial_chart(int H, int W, vector<int> _R, vector<int> _C) { H = H; W = W; N = H * W; seats.resize(H + 2, vector<int>(W + 2, N + 1)); build_tree(1, 1, N); for (int i = 1; i <= N; i++) { R[i] = _R[i - 1] + 1; C[i] = _C[i - 1] + 1; seats[R[i]][C[i]] = i; } for (int i = 0; i <= H; i++) { for (int j = 0; j <= W; j++) { update_square(i, j, 1); } } } int swap_seats(int a, int b) { a++; b++; update_pos(R[a], C[a], b); update_pos(R[b], C[b], a); swap(R[a], R[b]); swap(C[a], C[b]); return tree[1].second; }
#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...