Submission #117965

#TimeUsernameProblemLanguageResultExecution timeMemory
117965Osama_AlkhodairySeats (IOI18_seats)C++17
5 / 100
4105 ms57004 KiB
#include <bits/stdc++.h> #include "seats.h" //#include "grader.cpp" using namespace std; #pragma GCC optimize("O3") const int N = 1000001; struct segment{ int n, tree[4 * N]; int inv = 0; // inv = 0 -> min // inv = 1 -> max void resize(int nn, int x){ n = nn; inv = x; } void update(int l, int r, int node, int ind, int val){ if(r < l || r < ind || l > ind) return; if(l == r){ tree[node] = val; return; } int mid = (l + r) / 2; update(l, mid, 2 * node, ind, val); update(mid + 1, r, 2 * node + 1, ind, val); tree[node] = min(tree[2 * node], tree[2 * node + 1]); } void update(int ind, int val){ if(inv) val *= -1; update(0, n - 1, 1, ind, val); } int query(int l, int r, int node, int s, int e){ if(r < l || r < s || l > e) return 1e9; if(s <= l && r <= e) return tree[node]; int mid = (l + r) / 2; return min(query(l, mid, 2 * node, s, e), query(mid + 1, r, 2 * node + 1, s, e)); } int query(int pref){ int ret = query(0, n - 1, 1, 0, pref); if(inv) ret *= -1; return ret; } }; int n, m; vector <int> x, y; segment tree[4]; void update(int i){ tree[0].update(i, x[i]); tree[1].update(i, x[i]); tree[2].update(i, y[i]); tree[3].update(i, y[i]); } void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { n = H; m = W; x = R; y = C; tree[0].resize(n * m, 0); tree[1].resize(n * m, 1); tree[2].resize(n * m, 0); tree[3].resize(n * m, 1); for(int i = 0 ; i < n * m ; i++){ update(i); } } int area(int g){ int mnx = tree[0].query(g); int mxx = tree[1].query(g); int mny = tree[2].query(g); int mxy = tree[3].query(g); return (mxx - mnx + 1) * (mxy - mny + 1); } int swap_seats(int a, int b) { swap(x[a], x[b]); swap(y[a], y[b]); update(a); update(b); int ret = 0; int cur = 0; while(cur < n * m){ int ar = area(cur); if(ar == cur + 1){ ret++; cur++; } else{ cur = ar - 1; } } return ret; }
#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...