QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#142021#6733. Moniphant SleepOvO_ZuoWA 762ms50696kbC++142.5kb2023-08-18 11:10:012023-09-05 22:11:14

Judging History

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

  • [2023-09-05 22:11:14]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:762ms
  • 内存:50696kb
  • [2023-08-18 11:10:02]
  • 评测
  • 测评结果:0
  • 用时:726ms
  • 内存:50708kb
  • [2023-08-18 11:10:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n,q;
struct seg{
	int z,f,der,tz,tf;
	bool cl,mn;
	seg(int a=0,int b=0,int c=0,int d=0,int e=0,bool f=0,bool g=0):z(a),f(b),der(c),tz(d),tf(e),cl(f),mn(g){}
	void init()
	{
		z=f=der=tz=tf=0;
		cl=mn=0;
	}
	void add(int x){ der+=x;}
	void sub(int x)
	{
		der+=x;
		if(der<0)
		{
			mn=0;
			tz+=x;
			der=0;
		}		
		if(tz<0) tf=tz,tz=0;
	}
	void upd()
	{
		if(mn) return;
		tz+=der;
		der=0;
		mn=1;
	}
	void clear()
	{
		if(!mn) tz+=der;
		mn=0;der=0;
		if(cl) return;
		if(z+tf<0) f+=z+tf,z=tz;
		else z+=tz+tf;
		tz=tf=0;
		cl=1;		
	}
	seg operator+(seg a)
	{
		seg res=seg(z,f,der,tz,tf,cl,mn);
		res.sub(a.f),res.add(a.z);
		if(a.cl) res.clear();
		res.sub(a.tf),res.add(a.tz);
		if(a.mn) res.upd();
		res.add(a.der);
		//cout<<z<<" "<<f<<" "<<tz<<" "<<tf<<" "<<der<<" "<<cl<<" "<<mn<<"   "<<a.z<<" "<<a.f<<" "<<a.tz<<" "<<a.tf<<" "<<a.der<<" "<<a.cl<<" "<<a.mn<<endl;
		return res;
	}
	int v(){ return z+f+der+tz+tf;}
}shu[N<<2];
void build(int l,int r,int idx)
{
	if(l==r)
	{
		shu[idx].z=500000;
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,idx<<1),build(mid+1,r,idx<<1|1);
}
void push_down(int idx)
{
	shu[idx<<1]=shu[idx<<1]+shu[idx];
	shu[idx<<1|1]=shu[idx<<1|1]+shu[idx];
	shu[idx].init();
}
void modify(int l,int r,int tl,int tr,seg vv,int idx)
{
	if(l>=tl&&r<=tr)
	{
		shu[idx]=shu[idx]+vv;
		return;
	}
	push_down(idx);
	int mid=(l+r)>>1;
	if(mid>=tl) modify(l,mid,tl,tr,vv,idx<<1);
	if(mid<tr) modify(mid+1,r,tl,tr,vv,idx<<1|1);
}
int query(int l,int r,int tar,int idx)
{
	if(l==r) return shu[idx].v();
	push_down(idx);
	int mid=(l+r)>>1;
	if(mid>=tar) return query(l,mid,tar,idx<<1);
	else return query(mid+1,r,tar,idx<<1|1);
}
int main()
{
	scanf("%d%d",&n,&q);
	int i,op,l,r;
	build(1,n,1);
	for(i=1;i<=q;i++)
	{
		scanf("%d%d%d",&op,&l,&r);
		if(op==1) modify(1,n,l,r,seg(1,0,0,0,0,0,0),1);
		else if(op==2) modify(1,n,l,r,seg(0,-1,0,0,0,0,0),1);
		else if(op==3) modify(1,n,l,r,seg(0,0,0,0,0,0,1),1);
		else if(op==4) modify(1,n,l,r,seg(0,0,0,0,0,1,0),1);
		else printf("%d\n",query(1,n,l,1));
		//cout<<"query:"<<query(1,n,1,1)<<endl;
	}
	return 0;
}
/*
一/二操作为区间 +1/-1
四操作为跳转至有效的3操作中最小的后,将所有其余信息清空
不妨每次将清空后的位置视为0点,记录变化量
三操作时,只有更新最小值时需要操作:
	将最小值记为当前位置,并将变化量清空
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 50696kb

input:

1 9
1 1 1
1 1 1
1 1 1
3 1 1
2 1 1
1 1 1
1 1 1
4 1 1
5 1 1

output:

500004

result:

ok 1 number(s): "500004"

Test #2:

score: 0
Accepted
time: 9ms
memory: 50584kb

input:

3 7
2 1 3
3 1 3
1 1 3
1 1 3
5 1 1
4 1 3
5 1 1

output:

500001
499999

result:

ok 2 number(s): "500001 499999"

Test #3:

score: -100
Wrong Answer
time: 762ms
memory: 50632kb

input:

500000 500000
2 132991 371170
5 15281 15281
1 278642 397098
2 152103 176573
2 13797 47775
3 139320 370045
3 79054 432340
3 82556 212775
4 270171 469418
5 148000 148000
3 371255 401414
5 71051 71051
2 358945 473071
2 231663 265401
2 20243 58131
1 247710 313373
5 154549 154549
1 17317 233265
5 37602 3...

output:

500000
499999
500000
499999
500000
500001
500000
499999
500002
500000
500000
500000
500001
500003
500000
500003
500000
500004
500002
500002
500000
500000
500001
500001
500000
500001
500004
500000
500001
500004
500001
500004
500004
500005
500005
500006
500006
500003
500001
500004
500000
500004
500008...

result:

wrong answer 4th numbers differ - expected: '499998', found: '499999'