QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#112077#6608. Descent of DragonsxiaoyaowudiWA 4ms5440kbC++172.9kb2023-06-09 20:38:272023-06-09 20:38:32

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-09 20:38:32]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:5440kb
  • [2023-06-09 20:38:27]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <random>
#include <chrono>
constexpr int N(6e5+10),M(2e7);
namespace T
{
	struct _z
	{
		int lc,rc,fa;
	}z[M];
	int sz;
	void clear(int n){sz=n;}
	void pu(int u)
	{
		if(z[u].lc) z[z[u].lc].fa=u;
		if(z[u].rc) z[z[u].rc].fa=u;
	}
	int merge(int u,int v)
	{
		if(!u || !v) return u|v;
		z[u].lc=merge(z[u].lc,z[v].lc);
		z[u].rc=merge(z[u].rc,z[v].rc);
		pu(u);return u;
	}
	void split(int u,int cl,int cr,int pos,int &x,int &y)//[1,pos],(pos,n]
	{
		if(!u){x=y=0;return;}
		if(pos<cl){x=0;y=u;return;}else if(pos>=cr){x=u;y=0;return;}int mid((cl+cr)>>1);
		if(pos<=mid)
		{
			int w,t;split(z[u].lc,cl,mid,pos,w,t);
			if(!t && !z[u].rc){x=u;y=0;pu(x);return;}
			y=u;z[y].lc=t;pu(y);
			if(w) x=++sz,z[x].rc=0,z[x].lc=w,pu(x);
			else x=0;
		}
		else
		{
			int w,t;split(z[u].rc,mid+1,cr,pos,w,t);
			if(!w && !z[u].lc){y=u;x=0;pu(y);return;}
			x=u;z[x].rc=w;pu(x);
			if(t) y=++sz,z[y].lc=0,z[y].rc=t,pu(y);
			else y=0;
		}
	}
	int col(int u)
	{
		while(z[u].fa>0) u=z[u].fa;
		return -z[u].fa;
	}
	int lm(int u)
	{
		if(!u) return -1;
		while(z[u].lc || z[u].rc)
		{
			if(z[u].lc) u=z[u].lc;
			else u=z[u].rc;
		}
		return u;
	}
	int rm(int u)
	{
		if(!u) return -1;
		while(z[u].lc || z[u].rc)
		{
			if(z[u].rc) u=z[u].rc;
			else u=z[u].lc;
		}
		return u;
	}
	int build(int cl,int cr)
	{
		if(cl==cr){z[cl].lc=z[cl].rc=0;return cl;}
		int mid((cl+cr)>>1);int u(++sz);z[u].lc=build(cl,mid),z[u].rc=build(mid+1,cr);pu(u);return u;
	}
}
struct _q
{
	int tp,l,r,x;
}qs[N];int rt[N];
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);int n,q;std::cin>>n>>q;int L(1);while(L<(n+2)) L<<=1;
	for(int i(1);i<=q;++i)
	{
		int t,l,r;std::cin>>t>>l>>r;++l;++r;qs[i]=(_q){t,l,r,0};
		if(t==1) std::cin>>qs[i].x;
	}
	constexpr int A(5e5);
	for(int len(1);len<=(L>>1);len<<=1)
	{
		std::fill(rt,rt+A+1,0);
		T::clear(L);rt[0]=T::build(1,L);
		for(int i(1);i<=q;++i)
		{
			int &l(qs[i].l),&r(qs[i].r),&x(qs[i].x),tp(qs[i].tp);
			if(tp==1)
			{
				if(len==1)
				{
					int _l,_m,_r,_t;T::split(rt[x],1,L,l-1,_l,_t);T::split(_t,1,L,r,_m,_r);
					rt[x]=T::merge(_l,_r);T::z[rt[x]].fa=-x;
					if(!_m)
					{
						l=r=-1;
					}
					else
					{
						l=T::lm(_m),r=T::rm(_m);
						rt[x+1]=T::merge(_m,rt[x+1]);T::z[rt[x+1]].fa=-(x+1);
					}
				}
				else
				{
					if(~l && ~r)
					{
						int rl((l-1)/len+1),rr((r-1)/len+1),_l,_m,_r,_t;
						T::split(rt[x],1,L,rl-1,_l,_t);T::split(_t,1,L,rr,_m,_r);
						rt[x]=T::merge(_l,_r);T::z[rt[x]].fa=-x;
						rt[x+1]=T::merge(_m,rt[x+1]);T::z[rt[x+1]].fa=-(x+1);
					}
				}
			}
			else
			{
				int rl((l+len-2)/len+1),rr(r/len);
				if(rl<=rr)
				{
					x=std::max(x,T::col(rl));
					if(rr!=rl) x=std::max(x,T::col(rr));
				}
			}
		}
	}
	for(int i(1);i<=q;++i) if(qs[i].tp==2) std::cout<<qs[i].x<<"\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 5372kb

input:

5 5
1 3 5 0
1 1 4 1
1 1 5 2
2 2 2
2 4 5

output:

0
3

result:

ok 2 number(s): "0 3"

Test #2:

score: -100
Wrong Answer
time: 4ms
memory: 5440kb

input:

1000 1000
2 234 913
1 693 735 47
1 702 959 94
2 273 286
1 814 896 47
1 560 566 15
1 46 699 97
2 494 527
1 721 879 68
1 87 437 26
1 163 938 15
1 816 912 58
2 284 670
2 713 763
1 49 542 13
1 669 874 41
2 795 855
1 601 962 93
1 413 747 50
1 528 710 73
2 255 435
1 329 871 86
1 24 236 48
1 22 48 41
1 29 ...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
0
2
2
2
2
2
1
0
0
1
0
1
0
0
0
0
0
2
2
0
2
0
0
0
0
2
0
2
2
2
2
2
2
2
2
2
2
0
0
2
0
0
0
3
3
3
0
0
0
1
1
1
3
2
2
2
2
3
1
3
2
2
3
3
2
2
1
3
2
3
3
3
3
3
3
3
2
2
3
3
2
3
2
1
3
3
2
1
3
3
3
1
1
2
2
3
2
1
1
3
3
2
2
2
3
2
3
2
3
2
2
3
3
2
2
1
2
3
2
3
4
4
4
4
2
4
2
4
4
4
...

result:

wrong answer 1st numbers differ - expected: '0', found: '2'