Submission #421774

#TimeUsernameProblemLanguageResultExecution timeMemory
421774KeshiSeats (IOI18_seats)C++17
17 / 100
4051 ms48624 KiB
//In the name of God #include <bits/stdc++.h> #include "seats.h" using namespace std; typedef int ll; typedef pair<ll, ll> pll; const ll maxn = 1e6 + 100; const ll mod = 1e9 + 7; const ll inf = 1e9; #define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define Mp make_pair #define F first #define S second #define Sz(x) ll((x).size()) #define all(x) (x).begin(), (x).end() #define lc (id << 1) #define rc (lc | 1) struct rect{ ll mnx, mny, mxx, mxy; }; ll h, w, ans; rect p[maxn]; rect rct[maxn]; bool ok[maxn]; rect mrg(rect l, rect r){ rect m = {min(l.mnx, r.mnx), min(l.mny, r.mny), max(l.mxx, r.mxx), max(l.mxy, r.mxy)}; return m; } inline ll cal(rect rct){ return (rct.mxx - rct.mnx + 1) * (rct.mxy - rct.mny + 1); } void give_initial_chart(int H, int W, vector<int> R, vector<int> C){ h = H; w = W; rct[0] = {inf, inf, -inf, -inf}; for(ll i = 0; i < H * W; i++){ p[i] = {R[i], C[i], R[i], C[i]}; rct[i + 1] = mrg(rct[i], p[i]); } for(ll i = 1; i <= H * W; i++){ ok[i] = ll(cal(rct[i]) == i); ans += ok[i]; } return; } int swap_seats(int a, int b){ if(a > b) swap(a, b); swap(p[a], p[b]); a = max(1, a - 2); b = min(h * w, b + 2); for(ll i = a; i <= b; i++){ rct[i] = mrg(rct[i - 1], p[i - 1]); ans -= ok[i]; ok[i] = ll(cal(rct[i]) == i); ans += ok[i]; } return ans; }
#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...