Submission #410001

#TimeUsernameProblemLanguageResultExecution timeMemory
410001luciocfSeats (IOI18_seats)C++14
11 / 100
4097 ms73732 KiB
#include <bits/stdc++.h> #include "seats.h" #define ff first #define ss second using namespace std; typedef pair<int, int> pii; const int maxn = 1e3+10; int n, m; vector<int> x, y; struct SegmentTree { pii tree[4*1000*1000]; void build(int node, int l, int r, int q) { if (l == r) { if (!q) tree[node] = {x[l], x[l]}; else tree[node] = {y[l], y[l]}; return; } int mid = (l+r)>>1; build(2*node, l, mid, q); build(2*node+1, mid+1, r, q); tree[node].ff = min(tree[2*node].ff, tree[2*node+1].ff); tree[node].ss = max(tree[2*node].ss, tree[2*node+1].ss); } void upd(int node, int l, int r, int pos, int v) { if (l == r) { tree[node] = {v, v}; return; } int mid = (l+r)>>1; if (pos <= mid) upd(2*node, l, mid, pos, v); else upd(2*node+1, mid+1, r, pos, v); tree[node].ff = min(tree[2*node].ff, tree[2*node+1].ff); tree[node].ss = max(tree[2*node].ss, tree[2*node+1].ss); } pii query(int node, int l, int r, int a, int b) { if (l > b || r < a) return {n*m, 0}; if (l >= a && r <= b) return tree[node]; int mid = (l+r)>>1; pii p1 = query(2*node, l, mid, a, b); pii p2 = query(2*node+1, mid+1, r, a, b); return {min(p1.ff, p2.ff), max(p1.ss, p2.ss)}; } } seg_x, seg_y; void give_initial_chart(int H, int W, vector<int> R, vector<int> C) { n = H, m = W; for (int i = 0; i < n*m; i++) { x.push_back(R[i]); y.push_back(C[i]); } seg_x.build(1, 0, n*m-1, 0); seg_y.build(1, 0, n*m-1, 1); } int sub_1(void) { int mn_x = x[0], mx_x = x[0]; int mn_y = y[0], mx_y = y[0]; int ans = 1; for (int i = 1; i < n*m; i++) { mn_x = min(mn_x, x[i]); mx_x = max(mx_x, x[i]); mn_y = min(mn_y, y[i]); mx_y = max(mx_y, y[i]); if ((mx_x-mn_x+1)*(mx_y-mn_y+1) == i+1) ans++; } return ans; } int sub_2(void) { int ans = 0; for (int i = 0; i < n*m; ) { pii px = seg_x.query(1, 0, n*m-1, 0, i); pii py = seg_y.query(1, 0, n*m-1, 0, i); int mn_x = px.ff, mx_x = px.ss; int mn_y = py.ff, mx_y = py.ss; if ((mx_x-mn_x+1)*(mx_y-mn_y+1) == i+1) ans++; i = max(i+1, (mx_x-mn_x+1)*(mx_y-mn_y+1)-1); } return ans; } int swap_seats(int a, int b) { int xa = x[a], ya = y[a]; int xb = x[b], yb = y[b]; x[a] = xb, y[a] = yb; x[b] = xa, y[b] = ya; seg_x.upd(1, 0, n*m-1, a, x[a]); seg_x.upd(1, 0, n*m-1, b, x[b]); seg_y.upd(1, 0, n*m-1, a, y[a]); seg_y.upd(1, 0, n*m-1, b, y[b]); if (n <= 1000 && m <= 1000) return sub_2(); return sub_1(); }
#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...