QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95649#70. Bitaro, who Leaps through Timetricyzhkx0 2ms15584kbC++142.2kb2023-04-11 08:54:452023-04-11 08:54:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-11 08:54:48]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:15584kb
  • [2023-04-11 08:54:45]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,q,L[300010],R[300010];
ll ans[300010];
struct Query{int op,a,b,c,d;}que[300010];
struct node
{
	int L,R,typ,x;
	ll y;
	node(int _L=0,int _R=0):L(_L),R(_R),typ(0),y(0){}
	int pos(int t)const{return max(min(t,R),L);}
	ll calc(int t)const{return typ?max(t-x,0)+y:max(t-R,0);}
	node operator+(const node &a)const
	{
		node ans;
		if(typ || a.typ || max(L,a.L)>min(R,a.R))
		{
			ans.typ=1;
			ans.L=a.pos(L);ans.R=a.pos(R);
			assert(pos(a.L)==pos(a.R));
			ans.x=pos(a.L);ans.y=a.calc(ans.x)+y;
		}
		else
		{
			ans.typ=0;
			ans.L=max(L,a.L);ans.R=min(R,a.R);
		}
		return ans;
	}
}val[300010];
void build(int rt,int l,int r)
{
	if(l==r) return val[rt]=node(L[l]-l,R[l]-1-l),void();
	int mid=(l+r)/2;
	build(rt*2,l,mid);build(rt*2+1,mid+1,r);
	val[rt]=val[rt*2]+val[rt*2+1];
}
void update(int rt,int l,int r,int x,int y,int z)
{
	if(l==r) return val[rt]=node(y-x,z-1-x),void();
	int mid=(l+r)/2;
	if(x<=mid) update(rt*2,l,mid,x,y,z);
	else update(rt*2+1,mid+1,r,x,y,z);
	val[rt]=val[rt*2]+val[rt*2+1];
}
node query(int rt,int l,int r,int x,int y)
{
	if(x<=l && r<=y) return val[rt];
	int mid=(l+r)/2;
	if(y<=mid) return query(rt*2,l,mid,x,y);
	else if(x>mid) return query(rt*2+1,mid+1,r,x,y);
	else return query(rt*2,l,mid,x,y)+query(rt*2+1,mid+1,r,x,y);
}
void solve()
{
	build(1,1,n-1);
	for(int i=1;i<=q;i++)
		if(que[i].op==1) update(1,1,n-1,que[i].a,que[i].b,que[i].c);
		else if(que[i].a<que[i].c)
		{
			int x=que[i].a,y=que[i].c,t1=que[i].b-x,t2=que[i].d-y;
			node v=query(1,1,n-1,x,y-1);
			ans[i]=v.calc(t1)+max(v.pos(t1)-t2,0);
		}
}
int main()
{
	cin>>n>>q;
	for(int i=1;i<n;i++) scanf("%d%d",&L[i],&R[i]);
	for(int i=1;i<=q;i++)
	{
		scanf("%d%d%d%d",&que[i].op,&que[i].a,&que[i].b,&que[i].c);
		if(que[i].op==2) scanf("%d",&que[i].d);
	}
	for(int i=1;i<=q;i++)
		if(que[i].a==que[i].c) ans[i]=max(que[i].b-que[i].d,0);
	solve();
	reverse(L+1,L+n);reverse(R+1,R+n);
	for(int i=1;i<=n;i++)
		if(que[i].op==1) que[i].a=n-que[i].a;
		else que[i].a=n-que[i].a+1,que[i].c=n-que[i].c+1;
	solve();
	for(int i=1;i<=q;i++)
		if(que[i].op==2) printf("%lld\n",ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 15584kb

input:

20 18
115497790 671208773
326245299 528973482
100582193 437996818
89058008 771100620
768935396 842907844
187943946 997369106
455078418 542835554
536691525 970171971
564540350 570234421
657178750 753833933
386375484 979995375
389681484 772601117
634873482 897954663
87193815 139420775
259946990 394597...

output:

1311190384
286505553
1007027668
236944355
946740303
106582836
0
418804603
191096499

result:

wrong answer 1st lines differ - expected: '1155445816', found: '1311190384'

Subtask #2:

score: 0
Dangerous Syscalls

Test #42:

score: 0
Dangerous Syscalls

input:

274318 300000
489215489 676617321
780126019 788585486
556851007 580284394
233372413 595198772
519202713 898223077
502895565 696411826
206200999 769856900
270143414 346344669
729812429 901771242
663771137 938786194
472985796 990513077
846601694 992055636
178982840 919444964
27052680 316046043
8183731...

output:


result:


Subtask #3:

score: 0
Dangerous Syscalls

Test #56:

score: 0
Dangerous Syscalls

input:

270695 300000
513123795 772355425
210106247 394028231
276162603 911454418
105669187 977348162
173662950 272706156
152814457 669922258
344843731 523572913
316675910 752220119
109044474 322732409
555169512 652867118
622530606 779759913
153668285 339269709
150911093 937002300
186921016 855255616
118867...

output:


result: