QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627401#9373. Query on Tree275307894a#WA 69ms28604kbC++143.5kb2024-10-10 15:49:122024-10-10 15:49:13

Judging History

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

  • [2024-10-10 15:49:13]
  • 评测
  • 测评结果:WA
  • 用时:69ms
  • 内存:28604kb
  • [2024-10-10 15:49:12]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=5e5+5,M=N*4+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,q;
ll A[N];
namespace DS{
	#define ls v<<1
	#define rs v<<1|1
	ll f[M],g[M];
	void clr(int l=1,int r=n,int v=1){
		f[v]=g[v]=0;if(l==r) return;
		int m=l+r>>1;clr(l,m,ls);clr(m+1,r,rs);
	}
	void up(int v){f[v]=max(f[ls],f[rs])+g[v];}
	void Pf(int v,ll w){g[v]+=w;f[v]+=w;}
	ll add(int x,int y,ll z,int l=1,int r=n,int v=1){
		if(x>y) return -INF;
		if(x<=l&&r<=y) return Pf(v,z),f[v];int m=l+r>>1;
		return max(x<=m?add(x,y,z,l,m,ls):-INF,y>m?add(x,y,z,m+1,r,rs):-INF)+g[v];
	}
	#undef ls
	#undef rs
}
vector<int> S[N];
int id[N],ih;
int l[N][12],r[N][12];
int d[N],fa[N];
void tag(int x,int La,int d){
	queue<pii> q;
	q.emplace(x,d);
	while(!q.empty()){
		auto [x,d]=q.front();q.pop();
		if(!id[x]) id[x]=++ih,DS::add(id[x],id[x],A[x]),gdb(x,id[x]);
		if(d) for(int i:S[x]) q.emplace(i,d-1);
	}
}
void make(int x,int La){
	fa[x]=La;d[x]=d[La]+1;
	if(La) S[x].erase(find(all(S[x]),La));
	for(int i:S[x]) make(i,x);
}
void dfs(int x,int La){
	tag(x,La,10);
	for(int i:S[x]) dfs(i,x);
	Me(l[x],0x3f);Me(r[x],-0x3f); 
	l[x][0]=r[x][0]=id[x];
	for(int i:S[x]){
		for(int j=0;j<=11;j++){
			l[x][min(j+1,11)]=min(l[x][min(j+1,11)],l[i][j]);
			r[x][min(j+1,11)]=max(r[x][min(j+1,11)],r[i][j]);
		}
	}
}
void Solve(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++) S[i].clear(),id[i]=0;
	DS::clr();
	for(int i=1;i<=n;i++) scanf("%lld",&A[i]);
	for(int i=1;i<n;i++){
		int x,y;scanf("%d%d",&x,&y);
		S[x].push_back(y);S[y].push_back(x);
	}
	ih=0;
	make(1,0);
	dfs(1,0);
	gdb(DS::f[1],DS::f[2],DS::f[3],DS::f[4],DS::f[5]);
	while(q--){
		int op,x;
		scanf("%d%d",&op,&x);
		if(op==1||op==2){
			int k,v;scanf("%d%d",&k,&v);
			ll mx=-INF;
			if(op==1){
				int L=n+1,R=0;
				for(int i=k;~i&&x;i--){
					if(L>R) mx=max(mx,DS::add(l[x][i],r[x][i],v));
					else mx=max(mx,max(DS::add(l[x][i],L-1,v),DS::add(R+1,r[x][i],v)));
					if(i>=2) L=l[x][i-2],R=r[x][i-2];
					else L=n+1,R=0;
					x=fa[x];
				}
			}else{
				for(int i=k;~i;i--){
					mx=max(mx,DS::add(l[x][i],r[x][i],v));
					if(x^1) mx=max(mx,DS::add(l[x][i-1],r[x][i-1],v)),x=fa[x];
					gdb(i,mx,v,l[x][i],r[x][i]);
				}
			}
			if(mx<=-INF) puts("GG");
			else printf("%lld\n",mx);
		}else{
			int v;scanf("%d",&v);
			ll mx=-INF;
			for(int i=0;i<=11;i++) mx=max(mx,DS::add(l[x][i],r[x][i],v));
			if(mx<=-INF) puts("GG");
			else printf("%lld\n",mx);
		}
	}
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 28604kb

input:

1
5 5
1 2 1 3 2
1 2
2 3
2 4
4 5
2 2 1 0
1 2 1 3
3 4 -5
2 5 2 3
3 2 -1

output:

3
6
1
5
4

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 58ms
memory: 26524kb

input:

10000
3 9
42973045452542 34994498886390 -91733395797555
1 3
1 2
1 1 5 -71952967
3 1 -816873082
1 1 5 -842437577
2 3 7 254550528
3 3 -854082700
2 3 2 699808309
3 3 554885567
1 2 7 595565507
1 3 0 -318374053
3 2
-63158159333100 77264362049163 -99188430131116
1 2
3 2
2 2 4 -305866230
3 1 -549738403
3 5...

output:

GG
42972228579460
GG
42972483129988
-91734812202809
42973182938297
-91733557508933
GG
-91733875882986
77264056182933
77263506444530
7065382376488
7065749360235
7066534912965
-85115611272570
-85114714781312
96492412785032
-20428913156111
-20428197540063
96491742171666
-14945310996805
96491180203461
-...

result:

ok 200000 lines

Test #3:

score: -100
Wrong Answer
time: 69ms
memory: 26484kb

input:

10000
4 32
-1057044448491 -93293078803919 -24212938548357 74427756948193
1 3
1 2
3 4
3 1 -82365883
1 2 9 -730670945
2 4 2 -618745828
2 1 2 774032949
3 3 6733210
3 3 -843683844
3 1 327410390
3 1 -865685600
1 4 6 -951367966
3 2 107763506
1 3 2 721870187
2 3 3 -530847597
2 2 1 451029291
3 2 231297873
3...

output:

74427674582310
GG
74427055836482
74427829869431
74427836602641
74426992918797
74427320329187
74426454643587
GG
-93292817648557
-93292095778370
74425923795990
-1057589620769
-93291944298803
74425228504438
74425430401539
-93291936231808
74425906008467
GG
-1058067327518
74424997886529
74424370598990
74...

result:

wrong answer 148th lines differ - expected: '88719103200930', found: '23979066183953'