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

#TimeUsernameProblemLanguageResultExecution timeMemory
218849IgorISeats (IOI18_seats)C++17
100 / 100
3546 ms226420 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3e6 + 55; typedef pair<long long, int> T; int n, m, k; vector<vector<int> > p; int x[N], y[N]; T tree[1 << 23]; long long push[1 << 23]; void Push(int V, int L, int R, int M) { tree[2 * V + 1].first += push[V]; push[2 * V + 1] += push[V]; tree[2 * V + 2].first += push[V]; push[2 * V + 2] += push[V]; push[V] = 0; } void add(int l, int r, long long val, int L = 0, int R = (n - 2) * (m - 2), int V = 0) { if (r <= L || R <= l) return; if (l <= L && R <= r) { tree[V].first += val; push[V] += val; return; } int M = (L + R) / 2; Push(V, L, R, M); add(l, r, val, L, M, 2 * V + 1); add(l, r, val, M, R, 2 * V + 2); tree[V].first = min(tree[2 * V + 1].first, tree[2 * V + 2].first); tree[V].second = 0; if (tree[2 * V + 1].first == tree[V].first) tree[V].second += tree[2 * V + 1].second; if (tree[2 * V + 2].first == tree[V].first) tree[V].second += tree[2 * V + 2].second; } void change_tile(int i, int j, int t) { int x[4] = {p[i][j], p[i + 1][j], p[i + 1][j + 1], p[i][j + 1]}; sort(x, x + 4); add(x[0], x[1], t); add(x[2], x[3], t * n * m); } void give_initial_chart(int h, int w, vector<int> r, vector<int> c) { T kek = {0, 1}; fill(tree, tree + (1 << 23), kek); k = h * w; n = h + 2; m = w + 2; for (int i = 0; i < n; i++) { vector<int> e(m, k); p.push_back(e); } int t = h * w; for (int i = 0; i < t; i++) { p[r[i] + 1][c[i] + 1] = i; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { x[p[i][j]] = i; y[p[i][j]] = j; } } for (int i = 0; i + 1 < n; i++) { for (int j = 0; j + 1 < m; j++) { change_tile(i, j, 1); } } } void arc(int i, int j, int t) { change_tile(i - 1, j - 1, t); change_tile(i - 1, j, t); change_tile(i, j - 1, t); change_tile(i, j, t); } int swap_seats(int a, int b) { int i1 = x[a], j1 = y[a]; int i2 = x[b], j2 = y[b]; arc(i1, j1, -1); arc(i2, j2, -1); swap(p[i1][j1], p[i2][j2]); swap(x[a], x[b]); swap(y[a], y[b]); arc(i1, j1, 1); arc(i2, j2, 1); if (tree[0].first == 4) return tree[0].second; return 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...