이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include <tuple>
#include <algorithm>
#include <iostream>
static const int INF=1e9+7;
struct Node{
int max[4];
}st[2000000];
int N,H,W;
std::vector<std::tuple<int,int,int> > rectangles;
void pull(int i){
for(int k=0;k<4;k++){
st[i].max[k]=std::max(st[i<<1].max[k],st[i<<1|1].max[k]);
}
}
void build(int i){
for(i+=N;i>1;i>>=1){
pull(i>>1);
}
}
int query(int k,int b){
int a=0;
int res=-INF;
for(a+=N,b+=N;a<b;a>>=1,b>>=1){
if(a&1) res=std::max(res,st[a++].max[k]);
if(b&1) res=std::max(res,st[--b].max[k]);
}
return res;
}
void give_initial_chart(int h, int w, std::vector<int> R, std::vector<int> C) {
H=h;
W=w;
N=h*w;
for(int i=0;i<N;i++){
st[i+N].max[0]=R[i];
st[i+N].max[1]=-R[i];
st[i+N].max[2]=C[i];
st[i+N].max[3]=-C[i];
}
for(int i=N-1;i>0;i--){
pull(i);
}
for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){
rectangles.emplace_back(i*j,i,j);
}
}
std::sort(rectangles.begin(),rectangles.end());
}
int swap_seats(int a, int b) {
for(int k=0;k<4;k++){
std::swap(st[a+N].max[k],st[b+N].max[k]);
}
build(a),build(b);
int cnt=0;
for(auto rect:rectangles){
int area=std::get<0>(rect);
int h=std::get<1>(rect);
int w=std::get<2>(rect);
if(query(0,area)+query(1,area)==h-1&&
query(2,area)+query(3,area)==w-1){
//std::cerr<<"RECT: "<<h<<"x"<<w<<std::endl;
cnt++;
}
}
return cnt;
}
# | 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... |