제출 #835564

#제출 시각아이디문제언어결과실행 시간메모리
835564mousebeaver자리 배치 (IOI18_seats)C++14
5 / 100
4080 ms56652 KiB
#include "seats.h" #include <bits/stdc++.h> #define pii pair<int, int> #define INF numeric_limits<int>::max()/2 using namespace std; struct inf { int r1; int r2; int c1; int c2; }; int area(inf dat) { return ((1+dat.r2-dat.r1)*(1+dat.c2-dat.c1)); } int left(int i) { return 2*i; } int right(int i) { return 2*i+1; } int par(int i) { return i/2; } inf query(int i, vector<inf>& s, int a, int b, int l, int r) { if(l <= a && b <= r) { return s[i]; } if(r < a || b < l) { return {INF, 0, INF, 0}; } int mid = (a+b)/2; inf q1 = query(left(i), s, a, mid, l, r); inf q2 = query(right(i), s, mid+1, b, l, r); return {min(q1.r1, q2.r1), max(q1.r2, q2.r2), min(q1.c1, q2.c1), max(q1.c2, q2.c2)}; } void update(int i, vector<inf>& s, inf val) { s[i] = val; i = par(i); while(i > 0) { s[i] = {min(s[left(i)].r1, s[right(i)].r1), max(s[left(i)].r2, s[right(i)].r2), min(s[left(i)].c1, s[right(i)].c1), max(s[left(i)].c2, s[right(i)].c2)}; i = par(i); } } vector<inf> s(0); vector<pii> p(0); int segnodes = 1; int n = 1; void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { n = H*W; while(2*n > segnodes) { segnodes *= 2; } s.assign(segnodes, {INF, 0, INF, 0}); p.assign(n, {-1, -1}); for(int i = 0; i < n; i++) { s[i+segnodes/2] = {R[i], R[i], C[i], C[i]}; p[i] = {R[i], C[i]}; } for(int i = segnodes/2-1; i > 0; i--) { s[i] = {min(s[left(i)].r1, s[right(i)].r1), max(s[left(i)].r2, s[right(i)].r2), min(s[left(i)].c1, s[right(i)].c1), max(s[left(i)].c2, s[right(i)].c2)}; } } int swap_seats(int d, int b) { swap(p[d], p[b]); update(segnodes/2+d, s, {p[d].first, p[d].first, p[d].second, p[d].second}); update(segnodes/2+b, s, {p[b].first, p[b].first, p[b].second, p[b].second}); int output = 1; int a = 1; while(a < n) { int left = a; int right = n; while(left < right) { int mid = (left+right)/2; if(area(query(1, s, 1, segnodes/2, 1, mid)) > a) { right = mid; } else { left = mid+1; } } a = area(query(1, s, 1, segnodes/2, 1, left)); output += (a == area(query(1, s, 1, segnodes/2, 1, a))); } return output; }
#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...