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

#TimeUsernameProblemLanguageResultExecution timeMemory
206364batmendSeats (IOI18_seats)C++14
100 / 100
3380 ms69592 KiB
#include "seats.h" #include<bits/stdc++.h> using namespace std; const int N = 1000005; int n, m, k; int posx[N], posy[N]; int num[N]; int minv[2100000], minc[2100000], lazy[2100000]; // initial values are 0, thus, minv is 0 for every val; int a[5]; void build(int id, int l, int r); int get(int x, int y); void supd(int id, int l, int r, int ll, int rr, int val); void upd(int x, int y, int v); void change(int x, int y, int v); void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { n = H; m = W; k = H * W; build(1, 0, k - 1); // initially every val is 0; for (int i = 0; i < k ; i++) { posy[i] = R[i]; posx[i] = C[i]; num[posy[i]*m+posx[i]]=i; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { upd(j, i, 1); } } } int swap_seats(int a, int b) { change(posx[a], posy[a], b); change(posx[b], posy[b], a); swap(posx[a], posx[b]); swap(posy[a], posy[b]); return minc[1]; } void change(int x, int y, int v) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { upd(x+i, y+j, -1); } } num[y * m + x] = v; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { upd(x+i, y+j, 1); } } } void build(int id, int l, int r) { minc[id] = r - l + 1; if (r == l) return; int mid = (l + r) / 2; build(2 * id, l, mid); build(2 * id + 1, mid + 1, r); } int get(int x, int y) { if (x < 0 || x >= m || y < 0 || y >= n) return k; return num[y * m + x]; } void supd(int id, int l, int r, int ll, int rr, int v) { if (l > rr || r < ll) return; if (ll <= l && r <= rr) { lazy[id] += v; minv[id] += v; return; } int mid = (l + r) / 2; supd(2*id, l, mid, ll, rr, v); supd(2*id + 1, mid + 1, r, ll, rr, v); if (minv[2*id] > minv[2*id+1]) { minv[id] = minv[2*id+1]; minc[id] = minc[2*id+1]; } if (minv[2*id] < minv[2*id+1]) { minv[id] = minv[2*id]; minc[id] = minc[2*id]; } if (minv[2*id] == minv[2*id + 1]) { minv[id] = minv[2*id]; minc[id] = minc[2*id] + minc[2*id + 1]; } minv[id] += lazy[id]; } void upd(int x, int y, int v) { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { a[2 * i + j] = get(x - i, y - j); } } sort (a, a + 4); if (a[0] < a[1]) supd(1, 0, k - 1, a[0], a[1] - 1, v); if (a[2] < a[3]) supd(1, 0, k - 1, a[2], a[3] - 1, v); }
#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...