이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000100
#define MID ((l+r)/2)
#define ll long long
#define F first
#define S second
typedef pair<int, int> ii;
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
int n, m;
static int rl, rr;
static ii val;
static int x;
static pair<ii, ii> RAND = {{MOD, MOD}, {0,0}};
struct seg_tree{
seg_tree *left=0;
seg_tree *right=0;
pair<ii, ii> v = RAND;
void update(int l=0, int r=MOD){
if(l==r && l==x){
v = {val, val};
}
else if(l>x || r<x) assert(0);
else{
pair<ii, ii> ans1 = RAND;
pair<ii, ii> ans2 = RAND;
if(x<=MID){
if(!left) left = new seg_tree;
left->update(l, MID);
}
else{
if(!right) right = new seg_tree;
right->update(MID+1, r);
}
if(left) ans1 = left->v;
if(right) ans2 = right->v;
v = {{min(ans1.F.F, ans2.F.F), min(ans1.F.S, ans2.F.S)}, {max(ans1.S.F, ans2.S.F), max(ans1.S.S, ans2.S.S)}};
}
}
pair<ii,ii> query(int l=0, int r=MOD){
if(rl<=l && r<=rr) return v;
else if(r<rl || rr<l) return RAND;
else{
if(!left) left = new seg_tree;
if(!right) right = new seg_tree;
pair<ii, ii> ans1 = left->query(l, MID);
pair<ii, ii> ans2 = right->query(MID+1, r);
return {{min(ans1.F.F, ans2.F.F), min(ans1.F.S, ans2.F.S)}, {max(ans1.S.F, ans2.S.F), max(ans1.S.S, ans2.S.S)}};
}
}
};
seg_tree seg;
pair<ii, ii> query(int l, int r){
rl = l;
rr = r;
return seg.query();
}
void update(ii v, int xx){
val = v;
x = xx;
seg.update();
}
template<typename T>
struct sum_seg_tree{
struct node{
T val;
T laz;
int left=-1;
int right=-1;
node() {val=0, laz=0, left=-1, right=-1;}
node(T v) {val=v, laz=0, right=-1, left=-1;}
};
vector<node> seg;
static inline int N;
const int RAND_VALUE=0;
sum_seg_tree(int n){N=n, seg.assign(1, node());}
inline node merge(node par, node a, node b){
node ret;
ret.left = par.left, ret.right = par.right;
ret.val = a.val + b.val;
return ret;
}
inline void update_node(int ind, int val, int l, int r){
seg[ind].val = val * (r-l+1);
seg[ind].laz = val;
}
inline void down(node &par, int l, int r){
if(par.laz){
seg[par.left].val += par.laz * (MID-l+1);
seg[par.right].val += par.laz * (r-MID);
seg[par.left].laz = par.laz;
seg[par.right].laz = par.laz;
}
par.laz = 0;
}
inline void create_children(int ind){
node par = seg[ind];
if(par.left==-1) par.left=seg.size(), seg.push_back(node());
if(par.right==-1) par.right=seg.size(), seg.push_back(node());
seg[ind] = par;
}
void build(vector<T>& arr, int l=0, int r=N-1, int ind=0){
if(l==r) seg[ind] = node(arr[l]);
else{
create_children(ind);
build(arr,l,MID,seg[ind].left);
build(arr,MID+1,r,seg[ind].right);
seg[ind] = merge(seg[ind], seg[seg[ind].left], seg[seg[ind].right]);
}
}
void update(int rl, int rr, int val, int l=0, int r=N-1, int ind=0){
if(rl<=l && r<=rr) update_node(ind, val,l,r);
else if(rr<l || r<rl) return;
else{
create_children(ind);
down(seg[ind],l,r);
update(rl,rr,val,l,MID,seg[ind].left);
update(rl,rr,val,MID+1,r,seg[ind].right);
seg[ind] = merge(seg[ind], seg[seg[ind].left], seg[seg[ind].right]);
}
}
node _query(int rl, int rr, int l=0, int r=N-1, int ind=0){
if(rl<=l && r<=rr) return seg[ind];
else if(rl>r || l>rr) return RAND_VALUE;
else{
create_children(ind);
down(seg[ind],l,r);
return merge(seg[ind], _query(rl, rr, l, MID, seg[ind].left), _query(rl,rr,MID+1,r,seg[ind].right));
}
}
T query(int l, int r){
return _query(l,r).val;
}
};
vector<ii> pos;
pair<ii, ii> prv[1020000];
sum_seg_tree<int> sseg(1020000);
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
cerr<<"STARTED"<<endl;
n = H, m = W;
pos.resize(n*m);
FOR(i, n*m){
pos[i] = {R[i], C[i]};
update({R[i], C[i]}, i);
}
pair<ii, ii> val = RAND;
int i=0;
int r=0;
while(i<n*m){
//cerr<<i<<" ";
val.F.F = min(val.F.F, pos[i].F);
val.F.S = min(val.F.S, pos[i].S);
val.S.F = max(val.S.F, pos[i].F);
val.S.S = max(val.S.S, pos[i].S);
prv[i] = val;
int q = (val.S.F - val.F.F+1) * (val.S.S - val.F.S+1);
if(q==i+1) r++, sseg.update(i,i,1);
i++;
}
cerr<<"DONE"<<endl;
}
int swap_seats(int a, int b) {
/*
if(n+m<=2000){
int r=0;
int i=0;
pair<ii, ii> temp1 = query(a, a);
pair<ii, ii> temp2 = query(b, b);
update(temp1.F, b);
update(temp2.F, a);
while(i<n*m){
//cerr<<i<<" ";
pair<ii, ii> ans = query(0, i);
int q = (ans.S.F - ans.F.F+1) * (ans.S.S - ans.F.S+1);
if(q==i+1) r++, i++;
else i = q-1;
}
}
//else{*/
if(a>b) swap(a,b);
pair<ii, ii> val = RAND;
if(a>0) val = prv[a-1];
swap(pos[a], pos[b]);
int i = a;
int r = 0;
while(i<=b){
//cerr<<i<<" ";
val.F.F = min(val.F.F, pos[i].F);
val.F.S = min(val.F.S, pos[i].S);
val.S.F = max(val.S.F, pos[i].F);
val.S.S = max(val.S.S, pos[i].S);
int q = (val.S.F - val.F.F+1) * (val.S.S - val.F.S+1);
if(q==i+1) r++, sseg.update(i,i,1);
else sseg.update(i,i,0);
prv[i] = val;
i++;
}
return sseg.query(0,n*m);
//}
//return r;
}
컴파일 시 표준 에러 (stderr) 메시지
seats.cpp:89:9: warning: inline variables are only available with '-std=c++17' or '-std=gnu++17'
89 | static inline int N;
| ^~~~~~
# | 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... |