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

#TimeUsernameProblemLanguageResultExecution timeMemory
297149shayan_pSeats (IOI18_seats)C++17
100 / 100
2769 ms99556 KiB
#include<bits/stdc++.h> #include "seats.h" #define F first #define S second #define PB push_back #define sz(s) (int(s.size())) #define bit(n, k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int inf = 1e9 + 10, maxn = 1e6 + 10; int SM[maxn]; int SZ, now; int mn[4 * maxn], lz[4 * maxn], cnt[4 * maxn]; void mrg(int id){ mn[id] = min(mn[2*id], mn[2*id+1]); cnt[id] = 0; if(mn[id] == mn[2*id]) cnt[id]+= cnt[2*id]; if(mn[id] == mn[2*id+1]) cnt[id]+= cnt[2*id+1]; } void build(int l = 0, int r = SZ, int id = 1){ if(r-l == 1){ now+= SM[l]; mn[id] = now; cnt[id] = 1; return; } int mid = (l+r) >> 1; build(l, mid, 2*id); build(mid, r, 2*id+1); mrg(id); } void shift(int l, int r, int id){ mn[id]+= lz[id]; if(r-l > 1) lz[2*id]+= lz[id], lz[2*id+1]+= lz[id]; lz[id] = 0; } void add(int f, int s, int x, int l = 0, int r = SZ, int id = 1){ shift(l, r, id); if(f >= s || l >= r || s <= l || r <= f) return; if(f <= l && r <= s){ lz[id] = x; shift(l, r, id); return; } int mid = (l+r) >> 1; add(f, s, x, l, mid, 2*id); add(f, s, x, mid, r, 2*id+1); mrg(id); } int ASK(int pos, int l = 0, int r = SZ, int id = 1){ shift(l, r, id); if(r-l == 1) return mn[id]; int mid = (l+r) >> 1; if(pos < mid) return ASK(pos, l, mid, 2*id); else return ASK(pos, mid, r, 2*id+1); } vector<int> A, B; vector< vector<int> > val; int N, M; int what(int x, int y){ if(x < 0 || y < 0 || x >= N || y >= M) return inf; return val[x][y]; } int what(pii p){ return what(p.F, p.S); } void chng(int x, int y, int w){ vector<pii> vec = { {x, y}, {x-1, y}, {x, y-1}, {x-1, y-1} }; sort(vec.begin(), vec.end(), [](pii a, pii b){ return what(a) < what(b); }); add(what(vec[0]), what(vec[1]), w); add(what(vec[2]), what(vec[3]), w); } void chng2(int x, int y){ vector<pii> vec = { {x, y}, {x-1, y}, {x, y-1}, {x-1, y-1} }; sort(vec.begin(), vec.end(), [](pii a, pii b){ return what(a) < what(b); }); int l = what(vec[0]), r = what(vec[1]); l = min(l, SZ); r = min(r, SZ); if(l < r) SM[l]++, SM[r]--; l = what(vec[2]), r = what(vec[3]); l = min(l, SZ); r = min(r, SZ); if(l < r) SM[l]++, SM[r]--; } void all(int x, int y, int w){ chng(x, y, w); chng(x+1, y, w); chng(x, y+1, w); chng(x+1, y+1, w); } void give_initial_chart(int N, int M, vector<int> A, vector<int> B){ ::N = N, ::M = M, ::A = A, ::B = B; SZ = N * M; val.resize(N); for(int i = 0; i < N; i++) val[i].resize(M); for(int i = 0; i < N * M; i++) val[A[i]][B[i]] = i; for(int i = 0; i <= N; i++){ for(int j = 0; j <= M; j++) chng2(i, j); } build(); } int swap_seats(int a, int b){ pii pa = {A[a], B[a]}, pb = {A[b], B[b]}; swap(A[a], A[b]); swap(B[a], B[b]); all(pa.F, pa.S, -1); val[pa.F][pa.S] = b; all(pa.F, pa.S, 1); all(pb.F, pb.S, -1); val[pb.F][pb.S] = a; all(pb.F, pb.S, 1); return mn[1] == 4 ? cnt[1] : 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...