이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
};
inf combine(inf a, inf b)
{
return {min(a.r1, b.r1), max(a.r2, b.r2), min(a.c1, b.c1), max(a.c2, b.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});
vector<inf> testS = s;
int output = 1;
int a = 1;
while(a < n)
{
int i = segnodes/2;
inf dat = s[i];
while(area(dat) <= a)
{
i = par(i);
dat = s[i];
}
dat = s[left(i)];
i = right(i);
//Now, we are in the lowest node that contains enough area! => Going back down
while(left(i) < segnodes)
{
if(area(combine(s[left(i)], dat)) > a)
{
i = left(i);
}
else
{
dat = combine(dat, s[left(i)]);
i = right(i);
}
}
dat = combine(dat, s[i]);
a = area(dat);
output += (a == area(query(1, s, 1, segnodes/2, 1, a)));
}
return output;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |