QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#199234#6733. Moniphant SleeprascalrabbitWA 0ms3560kbC++142.1kb2023-10-03 23:44:272023-10-03 23:44:27

Judging History

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

  • [2023-10-03 23:44:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3560kb
  • [2023-10-03 23:44:27]
  • 提交

answer

// what is matter? never mind.
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 400005
#define inf 0x3f3f3f3f

struct node{
	int a,b,tagc,c,d,tagd,e;
	// -a+b C -c+d D +e
	void add(int x){
		//		assert(x>=0);
		e+=x;
	}
	void sub(int x){
		e-=x;
		if(tagd&&e<0)tagd=0;
		if(e<0)d+=e,e=0;
		if(d<0)c+=d,d=0;
	}
	void C(){
		if(tagd){
			tagd=e=0;
		}
		else {
			d+=e;
			e=0;
			if(d<0)c+=d,d=0;
//			return;
		}
		if(tagc)return;
		if(b+c<0) a+=c+b,b=d;
		else b=d+b+c;
		if(b<0)a+=b,b=0;
		tagc=1;
	}
	void D(){
		if(!tagd){
			d+=e;
			e=0;
			tagd=1;
		}
	}
	int F(){
		return a+b+c+d+e;
	}
	bool emp(){
		return !a&&!b&&!c&&!d&&!e&&!tagc&&!tagd;
	}
};

node operator +(node a,node b){
	a.sub(-b.a);
	a.add(b.b);
	if(b.tagc) a.C();
	a.sub(-b.c);
	a.add(b.d);
	if(b.tagd) a.D();
	a.add(b.e);
	return a;
}
void operator +=(node &a,node b){
	a=a+b;
}

node tr[maxn<<2];

void down(int p){
	if(!tr[p].emp())
		tr[p<<1]+=tr[p],tr[p<<1|1]+=tr[p],tr[p]={0,0,0,0,0,0,0};
}
void mdf(int p,int l,int r,int nl,int nr,node v){
	if(l>=nl&&r<=nr)return tr[p]+=v,void();
	int mid=l+r>>1; down(p);
	if(nl<=mid)mdf(p<<1,l,mid,nl,nr,v);
	if(nr>mid)mdf(p<<1|1,mid+1,r,nl,nr,v);
}
int ask(int p,int l,int r,int x){
	if(l==r)return tr[p].F();
	int mid=l+r>>1; down(p);
	if(x<=mid)return ask(p<<1,l,mid,x);
	else return ask(p<<1|1,mid+1,r,x);
}

int n,m;
node O[6];

signed main()
{
	n=read(),m=read();
	tr[1]={0,500000,0,0,0,0,0};
	O[1]={0,1,0,0,0,0,0};
	O[2]={-1,0,0,0,0,0,0};
	O[3]={0,0,0,0,0,1,0};
	O[4]={0,0,1,0,0,0,0};
	For(_,1,m){
		int op=read(),l,r;
		if(op<=4) l=read(),r=read(),mdf(1,1,n,l,r,O[op]);
		else l=read(),r=read(),cout<<ask(1,1,n,l)<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3560kb

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:

500008

result:

wrong answer 1st numbers differ - expected: '500004', found: '500008'