Submission #77384

#TimeUsernameProblemLanguageResultExecution timeMemory
77384Just_Solve_The_ProblemSeats (IOI18_seats)C++11
5 / 100
4030 ms57120 KiB
#include <bits/stdc++.h> #include "seats.h" // #include "grader.cpp" #define pii pair < int, int > #define fr first #define sc second #define mk make_pair #define OK puts("ok"); using namespace std; const int N = (int)1e6 + 7; const int inf = (int)1e9 + 7; int n; struct T { int tree[2][4 * N]; T () { } void upd(int pos, int val, int v = 1, int tl = 1, int tr = n) { if (tl == tr) { tree[0][v] = tree[1][v] = val; return ; } int mid = (tl + tr) >> 1; if (pos <= mid) { upd(pos, val, v + v, tl, mid); } else { upd(pos, val, v + v + 1, mid + 1, tr); } tree[0][v] = min(tree[0][v + v], tree[0][v + v + 1]); tree[1][v] = max(tree[1][v + v], tree[1][v + v + 1]); } pair < int, int > get(int l, int r, int v = 1, int tl = 1, int tr = n) { if (tl > r || tr < l) return make_pair(inf, 0); if (l <= tl && tr <= r) return make_pair(tree[0][v], tree[1][v]); int mid = (tl + tr) >> 1; pair < int, int > tp1, tp2; tp1 = get(l, r, v + v, tl, mid); tp2 = get(l, r, v + v + 1, mid + 1, tr); return make_pair(min(tp1.first, tp2.first), max(tp1.second, tp2.second)); } }; T tr[2]; int h, w; int ans; int r[N], c[N]; void give_initial_chart(int H, int W, vector<int> R, vector<int> C) { h = H; w = W; n = h * w; for (int i = 1; i <= n; i++) { tr[0].upd(i, R[i - 1]); tr[1].upd(i, C[i - 1]); r[i] = R[i - 1]; c[i] = C[i - 1]; } } int swap_seats(int a, int b) { a++; b++; tr[0].upd(a, r[b]); tr[0].upd(b, r[a]); swap(r[a], r[b]); tr[1].upd(a, c[b]); tr[1].upd(b, c[a]); swap(c[a], c[b]); ans = 1; int area; for (int i = 1; i < n; ) { pair < int, int > tp1, tp2; tp1 = tr[0].get(1, i); tp2 = tr[1].get(1, i); area = (tp1.sc - tp1.fr + 1) * (tp2.sc - tp2.fr + 1); if (i == area) { ans++; i++; } else { i = area; } } 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...