QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114812#6608. Descent of DragonsEric_caiWA 3ms13872kbC++141.7kb2023-06-23 17:14:562023-06-23 17:14:59

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-23 17:14:59]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:13872kb
  • [2023-06-23 17:14:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
int n,q,cnt;
int ls[maxn*30],rs[maxn*30],rt[maxn],p[maxn*4],w[maxn*30],fa[maxn*30];
int build(int id,int l,int r)
{
	int x=++cnt;
	p[id]=x;
	if(l==r) return x;
	int mid=(l+r)>>1;
	ls[x]=build(id<<1,l,mid);
	rs[x]=build(id<<1|1,mid+1,r);
	fa[ls[x]]=fa[rs[x]]=x;
	return x;
}
int merge(int id1,int id2,int l,int r)
{
	if(id1==0 || id2==0) return id1+id2;
	if(l==r) return id1;
	int mid=(l+r)>>1;
	ls[id1]=merge(ls[id1],ls[id2],l,mid);
	rs[id1]=merge(rs[id1],rs[id2],mid+1,r);
	fa[ls[id1]]=fa[rs[id1]]=id1;
	return id1;
}
void update(int id,int &id1,int &id2,int l,int r,int x,int y)
{
	if(id1==0) return;
	if(id2==0) id2=++cnt;
	if(p[id]==id1) p[id]=id2;
	if(l>=x && r<=y)
	{
		id2=merge(id2,id1,l,r);
		id1=0;
		return;
	}
	int mid=(l+r)>>1;
	if(x<=mid) update(id<<1,ls[id1],ls[id2],l,mid,x,y);
	if(y>mid) update(id<<1|1,rs[id1],rs[id2],mid+1,r,x,y);
	fa[ls[id1]]=fa[rs[id1]]=id1,fa[ls[id2]]=fa[rs[id2]]=id2;
	if(ls[id1]+rs[id1]==0) id1=0;
	if(ls[id2]+rs[id2]==0) id2=0;
}
int query(int id,int l,int r,int x,int y)
{
	if(l>=x && r<=y)
	{
		id=p[id];
		while(fa[id]!=0) id=fa[id];
		return w[id];
	}
	int mid=(l+r)>>1,ret=0;
	if(x<=mid) ret=max(ret,query(id<<1,l,mid,x,y));
	if(y>mid) ret=max(ret,query(id<<1|1,mid+1,r,x,y));
	return ret;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int k,l,r,x;
	cin>>n>>q;
	rt[0]=build(1,1,n);
	for(int i=1;i<=q;i++)
	{
		cin>>k>>l>>r;
		if(k==1)
		{
			cin>>x;
			if(x>q) continue;
			w[rt[x]]=w[rt[x+1]]=0;
			update(1,rt[x],rt[x+1],1,n,l,r);
			w[rt[x]]=x,w[rt[x+1]]=x+1;
		}
		if(k==2) cout<<query(1,1,n,l,r)<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 13624kb

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: 0
Accepted
time: 3ms
memory: 11644kb

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:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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:

ok 198 numbers

Test #3:

score: 0
Accepted
time: 3ms
memory: 13704kb

input:

1000 1000
1 26 189 2
1 485 923 7
1 108 839 9
1 200 260 8
1 196 296 1
1 894 897 7
1 215 510 3
1 117 333 9
2 395 646
1 548 762 8
1 317 340 0
1 354 879 0
1 294 373 8
1 277 979 5
1 10 295 8
2 769 784
1 271 850 4
1 233 440 4
1 416 542 3
1 454 470 7
1 439 956 5
1 644 722 1
1 732 951 4
1 423 768 5
1 43 962...

output:

0
1
1
1
1
1
3
3
3
3
3
3
3
3
3
5
4
5
4
5
1
5
5
1
6
6
6
6
7
7
6
7
6
7
7
10
10
10
10
10
10
10
8
10
8
8
10
10
5
10
10
10
10
10
10
10
5
6
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10...

result:

ok 197 numbers

Test #4:

score: -100
Wrong Answer
time: 3ms
memory: 13872kb

input:

1000 1000
1 646 946 11
1 192 372 8
1 14 516 45
2 664 910
1 164 693 0
1 285 411 16
1 682 888 40
2 153 569
1 407 481 18
1 961 985 4
1 22 904 11
1 195 213 34
2 46 767
1 73 106 5
1 172 573 38
1 277 322 9
1 230 555 29
1 882 882 18
1 140 276 7
1 15 102 21
1 319 383 29
1 289 814 22
1 795 905 45
1 205 415 3...

output:

0
1
1
1
1
0
1
1
0
1
1
1
1
0
1
1
0
1
1
3
0
1
0
3
2
3
1
1
0
1
3
3
1
1
1
1
3
3
0
3
3
1
0
3
0
3
3
3
3
1
1
3
3
1
0
3
3
3
3
1
2
4
4
4
4
2
2
4
2
0
3
5
4
5
4
5
5
5
5
0
5
5
0
5
5
5
4
5
5
2
5
5
5
5
5
4
5
5
5
5
5
6
5
5
0
5
6
6
6
6
6
6
6
6
6
1
6
6
6
6
6
7
7
8
8
7
7
3
3
8
3
7
7
0
8
7
6
7
7
1
1
9
9
7
8
9
7
7
7
9
...

result:

wrong answer 95th numbers differ - expected: '6', found: '5'