QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#371433#5069. VacationC1942huangjiaxuWA 492ms90304kbC++145.2kb2024-03-30 11:58:002024-03-30 11:58:02

Judging History

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

  • [2024-03-30 11:58:02]
  • 评测
  • 测评结果:WA
  • 用时:492ms
  • 内存:90304kb
  • [2024-03-30 11:58:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=4e5+5;
typedef long long ll;
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin)),p1==p2)?EOF:*p1++
template<class rd>
void read(rd &x){
	char c=getchar();int f=1;
	for(;c!='-'&&(c<48||c>57);c=getchar());
	if(c=='-')f=-f,c=getchar();
	for(x=0;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=f;
}
int n,m,B,pn,a[N],pos[N],pl[N],pr[N],ls;
ll sl[N],sr[N],S,Mx;
#define L k<<1
#define R k<<1|1
struct node{
	ll lmx,rmx,mx,sum;
}tr[N<<2];
inline node operator +(node a,node b){
	node c;
	c.sum=a.sum+b.sum;
	c.lmx=max(a.lmx,a.sum+b.lmx);
	c.rmx=max(b.rmx,b.sum+a.rmx);
	c.mx=max(max(a.mx,b.mx),a.rmx+b.lmx);
	return c;
}
struct seg1{
	node tr[N<<2];
	void build(int k,int l,int r){
		if(l==r){
			tr[k].mx=tr[k].lmx=tr[k].rmx=tr[k].sum=a[l];
			return;
		}
		int mid=l+r>>1;
		build(L,l,mid),build(R,mid+1,r);
		if(r-l+1<=B)tr[k]=tr[L]+tr[R];
	}
	void modify(int k,int l,int r,int x,int v){
		if(l==r){
			tr[k].mx=tr[k].lmx=tr[k].rmx=tr[k].sum=v;
			return;
		}
		int mid=l+r>>1;
		if(x<=mid)modify(L,l,mid,x,v);
		else modify(R,mid+1,r,x,v);
		if(r-l+1<=B)tr[k]=tr[L]+tr[R];
	}
	node query(int k,int l,int r,int x,int y){
		if(x<=l&&r<=y)return tr[k];
		int mid=l+r>>1;
		if(x<=mid&&y>mid)return query(L,l,mid,x,y)+query(R,mid+1,r,x,y);
		if(x<=mid)return query(L,l,mid,x,y);
		else return query(R,mid+1,r,x,y);
	}
}T1;
struct seg3{
	ll *s1,*s2,*tg,*m1,*m2;
	inline void pushup(int k){
		s2[k]=s2[L]+s2[R];
		s1[k]=max(s1[L],s1[R]);
		m2[k]=max(m2[L],s2[L]+m2[R]);
		m1[k]=max(m1[L],max(m1[R]+s2[L],s1[R]+m2[L]));
	}
	inline void pushtg(int k,ll v){
		tg[k]+=v,s1[k]+=v,m1[k]+=v;
	}
	inline void pushdown(int k){
		if(tg[k]){
			pushtg(L,tg[k]);
			pushtg(R,tg[k]);
			tg[k]=0;
		}
	}
	void build(int k,int l,int r){
		tg[k]=0;
		if(l==r){
			s2[k]=m2[k]=sr[l],s1[k]=m1[k]=sl[l];
			return;
		}
		int mid=l+r>>1;
		build(L,l,mid),build(R,mid+1,r);
		pushup(k);
	}
#define New new ll [B<<2]
	void init(int x){
		s1=New,s2=New,tg=New,m1=New,m2=New;
		for(int i=1;i<=B;++i){
			sr[i]=a[pl[x+1]+i-1];
			sl[i]=a[pl[x]+i-1];
		}
		for(int i=B;i;--i)sl[i]+=sl[i+1];
		build(1,1,B);
	}
	void modify(int k,int l,int r,int x,ll v){
		if(x>=r)return pushtg(k,v);
		int mid=l+r>>1;
		pushdown(k);
		if(x>mid)modify(R,mid+1,r,x,v);
		modify(L,l,mid,x,v);
		pushup(k);
	}
	void modify2(int k,int l,int r,int x,int v){
		if(l==r)return s2[k]=m2[k]=v,void();
		int mid=l+r>>1;
		pushdown(k);
		if(x<=mid)modify2(L,l,mid,x,v);
		else modify2(R,mid+1,r,x,v);
		pushup(k);
	}
	void query2(int k,int l,int r,int y){
		if(r<=y){
			Mx=max(Mx,S+m2[k]);
			S+=s2[k];
			return;
		}
		pushdown(k);
		int mid=l+r>>1;
		if(y>mid)query2(L,l,mid,y);
		query2(R,mid+1,r,y);
	}
	ll query(int k,int l,int r,int x,int y){
		if(x<=l){
			if(y<l)return Mx+s1[k];
			if(y>=r)return max(Mx+s1[k],S+m1[k]);
		}
		int mid=l+r>>1;
		pushdown(k);
		ll res=0;
		if(x<=mid)res=max(res,query(L,l,mid,x,y));
		if(ls<min(l,y))query2(L,l,mid,y),ls=mid;
		res=max(res,query(R,mid+1,r,x,y));
		if(ls<min(mid+1,y))query2(R,mid+1,r,y),ls=r;
		return res;
	}
}T3[N];
struct seg2{
	ll mx[N<<2];
	void build(int k,int l,int r,bool fg=0){
		if(l==r){
			if(fg)return mx[k]=T3[l-1].m1[1],void();
			ll s=0;
			for(int i=pl[l];i<=pr[l];++i){
				s=max(0ll,s+a[i]);
				mx[k]=max(mx[k],s);
			}
			return;
		}
		int mid=l+r>>1;
		build(L,l,mid,fg),build(R,mid+1,r,fg);
		mx[k]=max(mx[L],mx[R]);
	}
	void modify(int k,int l,int r,int x,int v){
		if(l==r)return mx[k]=v,void();
		int mid=l+r>>1;
		if(x<=mid)modify(L,l,mid,x,v);
		else modify(R,mid+1,r,x,v);
		mx[k]=max(mx[L],mx[R]);
	}
	ll query(int k,int l,int r,int x,int y){
		if(x<=l&&r<=y)return mx[k];
		int mid=l+r>>1;ll res=0;
		if(x<=mid)res=max(res,query(L,l,mid,x,y));
		if(y>mid)res=max(res,query(R,mid+1,r,x,y));
		return res;
	}
}T2,T4;
void Modify(int x,int y){
	int lx=pos[x];
	T1.modify(1,1,n,x,y);
	T2.modify(1,1,pn,lx,T1.query(1,1,n,pl[lx],pr[lx]).mx);
	if(lx<pn){
		T3[lx].modify(1,1,B,x-pl[lx]+1,y-a[x]);
		T4.modify(1,2,pn,lx+1,T3[lx].m1[1]);
	}
	if(lx>1){
		T3[lx-1].modify2(1,1,B,x-pl[lx]+1,y);
		T4.modify(1,2,pn,lx,T3[lx-1].m1[1]);
	}
	a[x]=y;
}
ll Query(int l,int r){
	if(r-l+1<=B)return max(0ll,T1.query(1,1,n,l,r).mx);
	int lx=pos[l],rx=pos[r];
	if(l==pl[lx])--lx;
	if(r==pr[rx])++rx;
	ll res=0;
	if(lx+1<rx)res=max(res,T2.query(1,1,pn,lx+1,rx-1));
	if(lx+2<rx)res=max(res,T4.query(1,2,pn,lx+2,rx-1));
	if(lx==pos[l]){
		S=Mx=ls=0;
		res=max(res,max(T3[lx].query(1,1,B,l-pl[lx]+1,min(r,pr[lx+1])-pl[lx+1]+1),T1.query(1,1,n,l,pr[lx]).mx));
	}
	if(rx==pos[r]){
		S=Mx=ls=0;
		res=max(res,max(T3[rx-1].query(1,1,B,max(l,pl[rx-1])-pl[rx-1]+1,r-pl[rx]+1),T1.query(1,1,n,pl[rx],r).mx));
	}
	return res;
}
int main(){
	read(n),read(m),read(B);
	for(int i=1;i<=n;++i)read(a[i]),pos[i]=(i-1)/B+1;
	pn=pos[n];
	while(n%B!=0)++n,pos[n]=pn;
	for(int i=1;i<=pn;++i)pl[i]=(i-1)*B+1,pr[i]=i*B;
	T1.build(1,1,n),T2.build(1,1,pn);
	for(int i=1;i<pos[n];++i)T3[i].init(i);
	if(pn>1)T4.build(1,2,pn,1);
	for(int i=1,op,x,y;i<=m;++i){
		read(op),read(x),read(y);
		if(op==1)Modify(x,y);
		else printf("%lld\n",Query(x,y));
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3916kb

input:

5 6 3
0 -5 -3 8 -3
2 3 5
1 2 5
2 1 5
1 4 -3
2 3 5
2 1 5

output:

8
10
0
5

result:

ok 4 number(s): "8 10 0 5"

Test #2:

score: 0
Accepted
time: 425ms
memory: 90304kb

input:

200000 500000 1
387060158 961744470 37167782 737122872 -532977662 1604246 -30977399 871848791 444997246 454204578 -813187501 -660394286 448014171 -835115276 -631880452 887715308 258530352 805589560 -414653327 -156732249 -335096199 -80266237 367896009 738406627 -903652056 446120866 415658444 -1347916...

output:

999902477
999981999
999343404
999847372
999957587
998160312
999981999
999981999
999981999
999980061
999981999
999981999
999981999
999876122
999981999
999996602
999981999
999981999
999981999
999723649
999981999
999957587
999896087
999981999
999981999
999981999
999981999
999981999
999957587
999981999
...

result:

ok 250051 numbers

Test #3:

score: -100
Wrong Answer
time: 492ms
memory: 66312kb

input:

200000 500000 5
802774074 383481934 -295470374 285359286 751657057 197444479 626916547 -828168464 288373833 -493446966 -208422769 956745384 919286225 959643271 -176531848 -380256966 357111771 -50890039 -637284768 -337010918 259019684 752475630 -259898780 98620995 -704832505 -532710796 -971600790 -84...

output:

4544135313
4544135313
4443416295
3390067591
4544135313
4544135313
4322308420
4386413596
4386413596
4165697630
4322308420
4287938127
4443416295
4544135313
4386413596
4165697630
4386413596
4386413596
4386413596
4323325838
4443416295
4386413596
4385851999
4544135313
4443416295
4443416295
4323325838
432...

result:

wrong answer 415th numbers differ - expected: '3819280371', found: '3678752364'