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

#TimeUsernameProblemLanguageResultExecution timeMemory
640048qwerasdfzxclSeats (IOI18_seats)C++17
100 / 100
690 ms162880 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 1e9+100; struct Node{ int prf, sum, cnt; Node(){} Node(int _prf, int _sum, int _cnt): prf(_prf), sum(_sum), cnt(_cnt) {} Node operator + (const Node &N) const{ int tmp = sum + N.prf; if (tmp < prf) return Node(tmp, sum + N.sum, N.cnt); if (tmp > prf) return Node(prf, sum + N.sum, cnt); return Node(prf, sum + N.sum, cnt + N.cnt); } }; struct Seg{ Node tree[2202000]; int sz; void init(int n, int a[]){ sz = 1048576; for (int i=sz;i<sz+n;i++) tree[i] = Node(a[i-sz], a[i-sz], 1); for (int i=sz+n;i<sz*2;i++) tree[i] = Node(INF, 0, 0); for (int i=sz-1;i;i--) tree[i] = tree[i<<1] + tree[i<<1|1]; } void update(int p, int x){ p += sz-1; tree[p] = Node(x, x, 1); for (p>>=1;p;p>>=1) tree[p] = tree[p<<1] + tree[p<<1|1]; } }tree; vector<vector<int>> a, chk; int n, m, d[1001000], X[1001000], Y[1001000], dx[4] = {0, 0, 1, 1}, dy[4] = {0, 1, 0, 1}; void calc(int x, int y, int o){ pair<int, int> adj[4]; for (int k=0;k<4;k++){ adj[k] = {a[x+dx[k]][y+dy[k]], k}; } sort(adj, adj+4); int tmp[5] = {0}; tmp[1] = 1; tmp[2] = (adj[0].second+adj[1].second==3)?1:0; tmp[3] = 1; tmp[4] = 0; for (int i=1;i<=4;i++) if (adj[i-1].first < INF){ if (o) d[adj[i-1].first] += (tmp[i] - tmp[i-1]); else d[adj[i-1].first] -= (tmp[i]-tmp[i-1]); } } void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { n = H, m = W; a.resize(n+2, vector<int>(m+2, INF)); chk.resize(n+2, vector<int>(m+2, 0)); for (int i=1;i<=n*m;i++){ a[R[i-1] + 1][C[i-1] + 1] = i; X[i] = R[i-1] + 1; Y[i] = C[i-1] + 1; } for (int i=0;i<=n;i++){ for (int j=0;j<=m;j++){ calc(i, j, 1); } } tree.init(n*m, d+1); //for (int i=1;i<=n*m;i++) tree.update(i, d[i]); } int swap_seats(int A, int B) { ++A, ++B; int C[2] = {A, B}; for (auto p:C){ for (int i=-1;i<=0;i++){ for (int j=-1;j<=0;j++) if (!chk[X[p]+i][Y[p]+j]){ calc(X[p]+i, Y[p]+j, 0); chk[X[p]+i][Y[p]+j] = 1; } } } swap(a[X[A]][Y[A]], a[X[B]][Y[B]]); swap(X[A], X[B]); swap(Y[A], Y[B]); for (auto p:C){ for (int i=-1;i<=0;i++){ for (int j=-1;j<=0;j++) if (chk[X[p]+i][Y[p]+j]){ calc(X[p]+i, Y[p]+j, 1); chk[X[p]+i][Y[p]+j] = 0; } } } for (auto p:C){ for (int i=-1;i<=1;i++){ for (int j=-1;j<=1;j++) if (a[X[p]+i][Y[p]+j] < INF){ tree.update(a[X[p]+i][Y[p]+j], d[a[X[p]+i][Y[p]+j]]); } } } return tree.tree[1].cnt; }
#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...