QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204513#7563. Fun on Treeucup-team918#WA 1124ms62796kbC++175.7kb2023-10-07 12:38:132023-10-07 12:38:14

Judging History

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

  • [2023-10-07 12:38:14]
  • 评测
  • 测评结果:WA
  • 用时:1124ms
  • 内存:62796kb
  • [2023-10-07 12:38:13]
  • 提交

answer

//Was yea ra,rra yea ra synk sphilar yor en me exec hymme METAFALICA waath!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define ll long long
#define ull unsigned ll
#define lowbit(x) (x&(-x))
#define djq 998244353
const short sint=0x3f3f;
const int inf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;
const double alpha=0.73;
const double PI=acos(-1);
inline void file(){
	freopen("ball.in","r",stdin);
	freopen("ball.out","w",stdout);
}
char buf[1<<21],*p1=buf,*p2=buf;
inline int getc(){
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,(1<<20)+5,stdin),p1==p2)?EOF:*p1++;
}
//#define getc getchar
inline ll read(){
	rg ll ret=0,f=0;char ch=getc();
    while(!isdigit(ch)){if(ch==EOF)exit(0);if(ch=='-')f=1;ch=getc();}
    while(isdigit(ch)){ret=ret*10+ch-48;ch=getc();}
    return f?-ret:ret;
}
inline int rdstr(char* s){
	char ch=getc(); int len(0);
	while(ch<33||ch>126) ch=getc();
	while(ch>=33&&ch<=126) (*s++)=ch,++len,ch=getc();
	return len;
}
#define ep emplace
#define epb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define it iterator
#define mkp make_pair
#define naive return 0*puts("Yes")
#define angry return 0*puts("No")
#define fls fflush(stdout)
#define rep(i,a) for(rg int i=1;i<=a;++i)
#define per(i,a) for(rg int i=a;i;--i)
#define rep0(i,a) for(rg int i=0;i<=a;++i)
#define per0(i,a) for(rg int i=a;~i;--i)
#define szf sizeof
typedef vector<int> vec;
typedef pair<int,int> pii;
struct point{ int x,y; point(int x=0,int y=0):x(x),y(y) {} inline bool operator<(const point& T)const{ return x^T.x?x<T.x:y<T.y; }; };
inline int ksm(int base,int p){int ret=1;while(p){if(p&1)ret=1ll*ret*base%djq;base=1ll*base*base%djq,p>>=1;}return ret;}
inline void pls(int& x,const int k){ x=(x+k>=djq?x+k-djq:x+k); }
inline int add(const int a,const int b){ return a+b>=djq?a+b-djq:a+b; }
inline void sub(int& x,const int k){ x=(x-k<0?x-k+djq:x-k); }
inline int inc(const int a,const int b){ return a<b?a-b+djq:a-b; }
inline void ckmn(int& x,const int k){ x=(k<x?k:x); }
inline void ckmx(int& x,const int k){ x=(k>x?k:x); }
inline void ckmn(ll& x,const ll k){ x=(k<x?k:x); }
inline void ckmx(ll& x,const ll k){ x=(k>x?k:x); }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


ll a[200005],dis[200005];
int n,q;
vec e[200005];
int fa[200005],dep[200005],sz[200005],son[200005],top[200005],btm[200005];
int dfn[200005],pos[200005],tim;
void dfs1(int x){
	dep[x]=dep[fa[x]]+1,dis[x]+=dis[fa[x]],sz[x]=1;
	for(int y:e[x]) dfs1(y),sz[x]+=sz[y],son[x]=(sz[y]>sz[son[x]]?y:son[x]);
}
void dfs2(int x,int ntop){
	top[x]=ntop,pos[dfn[x]=++tim]=x,btm[x]=x;
	if(son[x]) dfs2(son[x],ntop),btm[x]=btm[son[x]];
	for(int y:e[x]) if(y!=son[x]) dfs2(y,y);
}
struct info{
	ll v; int id;
	info(ll v=0,int id=0):v(v),id(id) {}
	inline bool operator<(const info& T)const{ return v==T.v?id>T.id:v<T.v; }
	inline info operator+(const ll& k)const{ return info(v+k,id); }
	inline info operator-(const ll& k)const{ return info(v-k,id); }
};
struct seg1{
	ll tg[200005<<2];
	info mx[200005<<2];
	inline void up(int x){ mx[x]=max(mx[x<<1],mx[x<<1|1])+tg[x]; }
	void build(int x,int l,int r,info* vl){
		if(l==r) return mx[x]=vl[l],void();
		const int mid=l+r>>1;
		build(x<<1,l,mid,vl),build(x<<1|1,mid+1,r,vl);
		up(x);
	}
	void modify(int x,int l,int r,int sl,int sr,ll k){
		if(sl>sr) return;
		if(sl<=l&&sr>=r) return mx[x]=mx[x]+k,tg[x]+=k,void();
		const int mid=l+r>>1;
		if(sl<=mid) modify(x<<1,l,mid,sl,sr,k);
		if(sr>mid) modify(x<<1|1,mid+1,r,sl,sr,k);
		up(x);
	}
	void upd(int x,int l,int r,int y,info k){
		if(l==r) return mx[x]=k,void();
		const int mid=l+r>>1; k=k-tg[x];
		y<=mid?upd(x<<1,l,mid,y,k):upd(x<<1|1,mid+1,r,y,k);
		up(x);
	}
	info qry(int x,int l,int r,int sl,int sr){
		if(sl>sr) return info(-linf,-1);
		if(sl<=l&&sr>=r) return mx[x];
		const int mid=l+r>>1; info res=info(-linf,-1);
		if(sl<=mid) res=max(res,qry(x<<1,l,mid,sl,sr));
		if(sr>mid) res=max(res,qry(x<<1|1,mid+1,r,sl,sr));
		return res+tg[x];
	}
}t1,t2;
inline info subq(int x,int y){
	if(!y) return t1.qry(1,1,n,dfn[x],dfn[x]+sz[x]-1);
	return max(t1.qry(1,1,n,dfn[x],dfn[y]-1),t1.qry(1,1,n,dfn[y]+sz[y],dfn[x]+sz[x]-1));
}
struct bit{
	ll t[200005];
	inline void ad(int x,const ll k){ while(x<=n) t[x]+=k,x+=(x&(-x)); }
	inline void modify(int l,int r,const ll k){ ad(l,k); if(r<n) ad(r+1,-k); }
	inline ll qr(int x){ ll res(0); while(x) res+=t[x],x-=(x&(-x)); return res; }
}t3;
void modify(int x,const ll k){
	t1.modify(1,1,n,dfn[x],dfn[x]+sz[x]-1,-k);
	if(top[x]!=x) t2.modify(1,1,n,dfn[x],dfn[btm[x]],-k);
	t3.modify(dfn[x],dfn[x]+sz[x]-1,-k);
	x=fa[top[x]];
	while(x) t2.upd(1,1,n,dfn[x],subq(x,son[x])-(dis[x]*2)),x=fa[top[x]];
}
void print(info x){ printf("[id=%d,value=%lld]\n",x.id,x.v); }
info query(int x){
	info res=info(-linf,-1);
	int y(0); const int z=x;
	while(x){
		//print(subq(x,y)+(dis[z]-dis[x]*2));
		res=max(res,subq(x,y)+(dis[z]-dis[x]*2));
		if(top[x]!=x) res=max(res,t2.qry(1,1,n,dfn[top[x]],dfn[fa[x]])+(dis[z]+t3.qr(dfn[top[x]])));
		y=top[x],x=fa[top[x]];
	}
	return res;
}
info initvl[200005];
signed main(){
	//file();
	n=read(),q=read();
	rep(i,n) a[i]=read();
	for(rg int i=2;i<=n;++i) fa[i]=read(),dis[i]=read(),e[fa[i]].epb(i);
	dfs1(1),dfs2(1,1);
	rep(i,n) initvl[dfn[i]]=info(dis[i]-a[i],i);
	t1.build(1,1,n,initvl);
	rep(i,n) initvl[dfn[i]]=subq(i,son[i])-dis[i]*2;
	t2.build(1,1,n,initvl);
	rep(i,q){
		const int x=read(),y=read();
		const ll V=read();
		modify(y,V);
		const info ans=query(x);
		printf("%d %lld\n",ans.id,ans.v);
	}
	return 0;
}
/*

*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 50596kb

input:

6 6
1 1 4 5 1 4
1 5
2 0
3 2
4 1
5 6
3 2 -100000
1 2 100000
1 1 0
2 2 66
3 1 5
4 4 -3

output:

6 100005
6 10
6 10
1 4
1 -1
1 1

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 8ms
memory: 50400kb

input:

5 6
-10 0 2 -4 8
1 7
1 1
2 2
2 -2
1 1 100
2 1 -100
1 1 0
4 3 10
2 5 3
5 2 2

output:

4 -87
1 17
4 13
1 19
1 17
1 15

result:

ok 6 lines

Test #3:

score: 0
Accepted
time: 4ms
memory: 49348kb

input:

6 3
0 0 0 0 0 0
1 10
1 10
1 -100
4 10
4 11
1 1 0
4 1 0
1 4 1000

output:

2 10
6 11
2 10

result:

ok 3 lines

Test #4:

score: 0
Accepted
time: 3ms
memory: 50204kb

input:

2 0
1 1
1 3

output:


result:

ok 0 lines

Test #5:

score: -100
Wrong Answer
time: 1124ms
memory: 62796kb

input:

200000 200000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 ...

output:

119017 15000000000
120167 17000000000
119017 15000000000
119017 15000000000
120167 17000000000
120167 15000000000
120167 16000000000
119017 17000000000
119017 16000000000
119017 12000000000
119017 17000000000
120167 16000000000
120167 14000000000
120167 17000000000
120167 18000000000
120167 16000000...

result:

wrong answer 68277th lines differ - expected: '130674 15000000000', found: '191485 15000000000'