Submission #77377

#TimeUsernameProblemLanguageResultExecution timeMemory
77377Just_Solve_The_ProblemSeats (IOI18_seats)C++11
5 / 100
4100 ms57248 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]); } int get(int l, int r, int tp, int v = 1, int tl = 1, int tr = n) { if (tl > r || tr < l) return ((tp == 0) ? inf : 0); if (l <= tl && tr <= r) return tree[tp][v]; int mid = (tl + tr) >> 1; int temp; if (tp == 0) temp = min(get(l, r, tp, v + v, tl, mid), get(l, r, tp, v + v + 1, mid + 1, tr)); else temp = max(get(l, r, tp, v + v, tl, mid), get(l, r, tp, v + v + 1, mid + 1, tr)); return temp; } }; 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 = 0; for (int i = 1; i <= n; i++) { int area = (tr[0].get(1, i, 1) - tr[0].get(1, i, 0) + 1) * (tr[1].get(1, i, 1) - tr[1].get(1, i, 0) + 1); if (i == area) { ans++; } else { i = area - 1; } } 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...