#include <bits/stdc++.h>
#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif
using namespace std;
struct Splay
{
int p, l, r, c, x, y, xl, yl;
Splay() : p(0), l(0), r(0), c(1), x(0), y(0), xl(-1), yl(-1) {}
} tree[1500001];
const int SZ=1<<21;
vector<pair<int,int>> Q;
vector<int> x;
int mtree[2*SZ], lz[2*SZ], R[1500000];
void lazy(int c)
{
if(tree[c].xl>-1) {
tree[c].x=tree[c].xl;
if(tree[c].l) tree[tree[c].l].xl=tree[c].x;
if(tree[c].r) tree[tree[c].r].xl=tree[c].x;
tree[c].xl=-1;
}
tree[c].y=max(tree[c].y,tree[c].yl);
if(tree[c].l) tree[tree[c].l].yl=max(tree[tree[c].l].yl,tree[c].yl);
if(tree[c].r) tree[tree[c].r].yl=max(tree[tree[c].r].yl,tree[c].yl);
tree[c].yl=-1;
}
void update(int c) {tree[c].c=tree[tree[c].l].c+tree[tree[c].r].c+1;}
void rotate(int c)
{
int p=tree[c].p;
if(tree[p].l==c) {
if(tree[c].r) tree[tree[c].r].p=p;
tree[p].l=tree[c].r;
tree[c].r=p;
}
else {
if(tree[c].l) tree[tree[c].l].p=p;
tree[p].r=tree[c].l;
tree[c].l=p;
}
if(tree[p].p) (tree[tree[p].p].l==p ? tree[tree[p].p].l:tree[tree[p].p].r)=c;
tree[c].p=tree[p].p;
tree[p].p=c;
update(p); update(c);
}
void splay(int c)
{
while(tree[c].p) {
int p=tree[c].p;
if(tree[p].p) lazy(tree[p].p);
lazy(p); lazy(c);
if(tree[p].p) rotate((tree[tree[p].p].l==p)==(tree[p].l==c) ? p:c);
rotate(c);
}
lazy(c);
}
int add_node(int c, int v)
{
splay(c);
for(;;) {
lazy(c);
if(tree[c].y<tree[v].y) {
if(tree[c].r==0) {
splay(c);
if(tree[v].r=tree[c].r) tree[tree[v].r].p=v;
tree[c].r=v;
tree[v].p=c;
update(v); update(c);
return c;
}
c=tree[c].r;
}
else {
if(tree[c].l==0) {
splay(c);
if(tree[v].l=tree[c].l) tree[tree[v].l].p=v;
tree[c].l=v;
tree[v].p=c;
update(v); update(c);
return c;
}
c=tree[c].l;
}
}
}
void lazy_propagation(int bit, int s, int e)
{
mtree[bit]=max(mtree[bit],lz[bit]);
if(s<e) {
if(mtree[2*bit]<0x7f7f7f7f) lz[2*bit]=max(lz[2*bit],lz[bit]);
if(mtree[2*bit+1]<0x7f7f7f7f) lz[2*bit+1]=max(lz[2*bit+1],lz[bit]);
}
else if(R[s]>-1) {
tree[R[s]].yl=max(tree[R[s]].yl,lz[bit]);
lazy(R[s]);
}
lz[bit]=-1;
}
void push(int n)
{
int bit=1, s=0, e=SZ-1;
while(s<e) {
int m=(s+e)>>1;
lazy_propagation(bit,s,e);
if(n<=m) tie(bit,e)=make_pair(2*bit,m);
else tie(bit,s)=make_pair(2*bit+1,m+1);
}
lazy_propagation(bit,s,e);
}
void dfs(int &c, int p)
{
int l=tree[p].l, r=tree[p].r;
lazy(p); tree[p].p=tree[p].l=tree[p].r=0;
if(l) dfs(c,l);
c=add_node(c,p);
if(r) dfs(c,r);
}
void query(int n1, int n2, int p, int v, int bit=1, int s=0, int e=SZ-1)
{
int m=(s+e)>>1;
lazy_propagation(bit,s,e);
if(n2<n1 || n2<s || e<n1 || mtree[bit]>v) return;
if(s==e) {
int &c=R[m];
for(;;) {
lazy(c);
if(tree[c].y>v) {
if(tree[c].l==0) {
splay(c);
break;
}
c=tree[c].l;
}
else {
if(tree[c].r==0) {
splay(c);
if(tree[c].r) {
for(lazy(c=tree[c].r);tree[c].l;) lazy(c=tree[c].l);
splay(c);
}
break;
}
c=tree[c].r;
}
}
mtree[SZ+p]=min(mtree[SZ+p],mtree[bit]);
if(tree[c].y<=v) {
mtree[bit]=0x7f7f7f7f;
if(R[p]==-1) {
swap(c,R[p]);
tree[R[p]].xl=x[p];
lazy(R[p]);
return;
}
if(tree[c].c>tree[R[p]].c) swap(c,R[p]);
dfs(R[p],c); c=-1; tree[R[p]].xl=x[p]; lazy(R[p]);
}
else {
mtree[bit]=tree[c].y;
tree[v=tree[c].l].p=0;
tree[c].l=0; update(c);
if(R[p]==-1) {
R[p]=v;
tree[R[p]].xl=x[p]; lazy(R[p]);
return;
}
if(tree[v].c>tree[R[p]].c) swap(v,R[p]);
dfs(R[p],v); tree[R[p]].xl=x[p]; lazy(R[p]);
}
return;
}
query(n1,n2,p,v,2*bit,s,m);
query(n1,n2,p,v,2*bit+1,m+1,e);
mtree[bit]=min(mtree[2*bit],mtree[2*bit+1]);
}
void set_tree(int n1, int n2, int v, int bit=1, int s=0, int e=SZ-1)
{
int m=(s+e)>>1;
lazy_propagation(bit,s,e);
if(n2<n1 || n2<s || e<n1) return;
if(n1<=s && e<=n2) {
lz[bit]=v;
lazy_propagation(bit,s,e);
return;
}
set_tree(n1,n2,v,2*bit,s,m);
set_tree(n1,n2,v,2*bit+1,m+1,e);
mtree[bit]=min(mtree[2*bit],mtree[2*bit+1]);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
TEST(freopen("input.txt","r",stdin));
TEST(freopen("output.txt","w",stdout));
TEST(freopen("debug.txt","w",stderr));
int L, N, B, M;
cin>>L>>N>>M; tree[0].c=0;
memset(lz,-1,sizeof(lz));
memset(R,-1,sizeof(R));
memset(mtree,0x7f,sizeof(mtree));
for(int i=1;i<=N;i++) {
int a, b;
cin>>a>>b;
x.push_back(a);
tree[i].x=a;
tree[i].y=b;
}
Q.resize(M); B=N;
for(auto &[t,a]: Q) {
cin>>t>>a;
if(t==2) x.push_back(L-a);
else if(t==4) {
int b;
cin>>b;
x.push_back(a);
tree[++N].x=a;
tree[a=N].y=b;
}
}
sort(x.begin(),x.end()); x.resize(unique(x.begin(),x.end())-x.begin());
for(int i=1;i<=B;i++) {
int p=lower_bound(x.begin(),x.end(),tree[i].x)-x.begin();
if(R[p]==-1) R[p]=i;
else R[p]=add_node(R[p],i);
mtree[SZ+p]=min(mtree[SZ+p],tree[i].y);
}
for(int i=SZ;--i;) mtree[i]=min(mtree[2*i],mtree[2*i+1]);
for(auto[t,a]: Q) {
int p;
if(t==1) {
splay(a);
R[p=lower_bound(x.begin(),x.end(),tree[a].x)-x.begin()]=a;
push(p);
cout<<tree[a].x<<' '<<tree[a].y<<'\n';
}
else if(t==2) {
p=lower_bound(x.begin(),x.end(),L-a)-x.begin();
push(p); query(0,p-1,p,a);
for(p+=SZ;p>>=1;) mtree[p]=min(max(mtree[2*p],lz[2*p]),max(mtree[2*p+1],lz[2*p+1]));
}
else if(t==3) {
p=upper_bound(x.begin(),x.end(),a)-x.begin()-1;
set_tree(0,p,L-a);
}
else {
p=lower_bound(x.begin(),x.end(),tree[a].x)-x.begin();
push(p);
if(R[p]==-1) R[p]=a;
else R[p]=add_node(R[p],a);
p+=SZ;
for(mtree[p]=min(mtree[p],tree[a].y);p>>=1;) mtree[p]=min(max(mtree[2*p],lz[2*p]),max(mtree[2*p+1],lz[2*p+1]));
}
}
return 0;
}
Compilation message
sweeping.cpp: In function 'int add_node(int, int)':
sweeping.cpp:79:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
79 | if(tree[v].r=tree[c].r) tree[tree[v].r].p=v;
| ~~~~~~~~~^~~~~~~~~~
sweeping.cpp:90:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
90 | if(tree[v].l=tree[c].l) tree[tree[v].l].p=v;
| ~~~~~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
86084 KB |
Output is correct |
2 |
Correct |
52 ms |
86104 KB |
Output is correct |
3 |
Correct |
50 ms |
86060 KB |
Output is correct |
4 |
Correct |
58 ms |
86136 KB |
Output is correct |
5 |
Correct |
62 ms |
86020 KB |
Output is correct |
6 |
Correct |
53 ms |
85968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3230 ms |
128500 KB |
Output is correct |
2 |
Correct |
3242 ms |
128484 KB |
Output is correct |
3 |
Correct |
3171 ms |
128536 KB |
Output is correct |
4 |
Correct |
2680 ms |
127436 KB |
Output is correct |
5 |
Correct |
4296 ms |
128120 KB |
Output is correct |
6 |
Correct |
3982 ms |
128292 KB |
Output is correct |
7 |
Correct |
3237 ms |
128500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2484 ms |
127168 KB |
Output is correct |
2 |
Correct |
2510 ms |
126488 KB |
Output is correct |
3 |
Correct |
1533 ms |
125384 KB |
Output is correct |
4 |
Correct |
1842 ms |
126308 KB |
Output is correct |
5 |
Correct |
2500 ms |
125664 KB |
Output is correct |
6 |
Correct |
2408 ms |
126564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2484 ms |
127168 KB |
Output is correct |
2 |
Correct |
2510 ms |
126488 KB |
Output is correct |
3 |
Correct |
1533 ms |
125384 KB |
Output is correct |
4 |
Correct |
1842 ms |
126308 KB |
Output is correct |
5 |
Correct |
2500 ms |
125664 KB |
Output is correct |
6 |
Correct |
2408 ms |
126564 KB |
Output is correct |
7 |
Correct |
2720 ms |
126696 KB |
Output is correct |
8 |
Correct |
2629 ms |
126576 KB |
Output is correct |
9 |
Correct |
2697 ms |
126692 KB |
Output is correct |
10 |
Correct |
2013 ms |
125544 KB |
Output is correct |
11 |
Correct |
2784 ms |
126500 KB |
Output is correct |
12 |
Correct |
3463 ms |
126424 KB |
Output is correct |
13 |
Correct |
3990 ms |
126376 KB |
Output is correct |
14 |
Correct |
1018 ms |
99728 KB |
Output is correct |
15 |
Correct |
1750 ms |
121712 KB |
Output is correct |
16 |
Correct |
2717 ms |
127376 KB |
Output is correct |
17 |
Correct |
2483 ms |
126496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
86084 KB |
Output is correct |
2 |
Correct |
52 ms |
86104 KB |
Output is correct |
3 |
Correct |
50 ms |
86060 KB |
Output is correct |
4 |
Correct |
58 ms |
86136 KB |
Output is correct |
5 |
Correct |
62 ms |
86020 KB |
Output is correct |
6 |
Correct |
53 ms |
85968 KB |
Output is correct |
7 |
Correct |
3230 ms |
128500 KB |
Output is correct |
8 |
Correct |
3242 ms |
128484 KB |
Output is correct |
9 |
Correct |
3171 ms |
128536 KB |
Output is correct |
10 |
Correct |
2680 ms |
127436 KB |
Output is correct |
11 |
Correct |
4296 ms |
128120 KB |
Output is correct |
12 |
Correct |
3982 ms |
128292 KB |
Output is correct |
13 |
Correct |
3237 ms |
128500 KB |
Output is correct |
14 |
Correct |
2484 ms |
127168 KB |
Output is correct |
15 |
Correct |
2510 ms |
126488 KB |
Output is correct |
16 |
Correct |
1533 ms |
125384 KB |
Output is correct |
17 |
Correct |
1842 ms |
126308 KB |
Output is correct |
18 |
Correct |
2500 ms |
125664 KB |
Output is correct |
19 |
Correct |
2408 ms |
126564 KB |
Output is correct |
20 |
Correct |
2720 ms |
126696 KB |
Output is correct |
21 |
Correct |
2629 ms |
126576 KB |
Output is correct |
22 |
Correct |
2697 ms |
126692 KB |
Output is correct |
23 |
Correct |
2013 ms |
125544 KB |
Output is correct |
24 |
Correct |
2784 ms |
126500 KB |
Output is correct |
25 |
Correct |
3463 ms |
126424 KB |
Output is correct |
26 |
Correct |
3990 ms |
126376 KB |
Output is correct |
27 |
Correct |
1018 ms |
99728 KB |
Output is correct |
28 |
Correct |
1750 ms |
121712 KB |
Output is correct |
29 |
Correct |
2717 ms |
127376 KB |
Output is correct |
30 |
Correct |
2483 ms |
126496 KB |
Output is correct |
31 |
Correct |
2299 ms |
127852 KB |
Output is correct |
32 |
Correct |
2284 ms |
127440 KB |
Output is correct |
33 |
Correct |
1888 ms |
128208 KB |
Output is correct |
34 |
Correct |
2855 ms |
127072 KB |
Output is correct |
35 |
Correct |
2944 ms |
127308 KB |
Output is correct |
36 |
Correct |
2073 ms |
126620 KB |
Output is correct |
37 |
Correct |
3215 ms |
127032 KB |
Output is correct |
38 |
Correct |
3859 ms |
128180 KB |
Output is correct |
39 |
Correct |
3945 ms |
127624 KB |
Output is correct |
40 |
Correct |
2554 ms |
127764 KB |
Output is correct |