/ Randle /

记录详情

Runtime Error

/in/foo.cc: In function 'void gtx::write(int)':
/in/foo.cc:16:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0;
   ^~
/in/foo.cc:16:29: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
   if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0;
                             ^~~
/in/foo.cc: In function 'void gtx::dfs2(int)':
/in/foo.cc:99:8: warning: unused variable 'k' [-Wunused-variable]
    int k = 0;
        ^
/in/foo.cc: In function 'int gtx::main()':
/in/foo.cc:150:9: warning: unused variable 'l' [-Wunused-variable]
     int l = 0;
         ^
# 状态 耗时 内存占用
#1 Accepted 5ms 5.012 MiB
#2 Accepted 5ms 5.055 MiB
#3 Accepted 5ms 4.973 MiB
#4 Accepted 4ms 5.051 MiB
#5 Accepted 5ms 4.957 MiB
#6 Accepted 5ms 4.965 MiB
#7 Accepted 17ms 6.82 MiB
#8 Accepted 197ms 22.699 MiB
#9 Accepted 9ms 6.203 MiB
#10 Accepted 42ms 14.168 MiB
#11 Accepted 74ms 22.051 MiB
#12 Accepted 98ms 27.809 MiB
#13 Accepted 34ms 15.48 MiB
#14 Runtime Error 52ms 23.172 MiB
#15 Runtime Error 44ms 24.945 MiB
#16 Runtime Error 54ms 27.051 MiB
#17 Accepted 119ms 26.047 MiB
#18 Accepted 124ms 25.504 MiB
#19 Accepted 126ms 25.078 MiB
#20 Accepted 125ms 30.797 MiB

代码

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
//#define int long long
namespace gtx{
//	Fast IO
	void read(int &x){
		x = 0;int h = 1;char tmp;
		do{tmp=getchar();if(tmp=='-')h*=-1;}while(!isdigit(tmp));
		while(isdigit(tmp)) x*=10,x+=tmp-'0',tmp=getchar();
		x*=h;
	}
	void read(char &x){do{x=getchar();}while(x==' '||x=='\n'||x=='\r');}
	void write(char x){putchar(x);}
	void write(int x){
		if(x<0) putchar('-'),x=-x;int st[200]={0},tot=0;
		do{st[++tot]=x%10,x/=10;} while(x);
		while(tot){putchar(st[tot--]+'0');};
	}
	void write(int x,char y){write(x);write(y);}
	const int MAXN = 2e5+10;
	int n,q,maxn[MAXN][3],cnt[MAXN][3];
	int maxl[MAXN][2],maxlc[MAXN][2];
	int sonl[MAXN][4],sonlc[MAXN][4];
	int fath[MAXN];
	vector<int> v[MAXN];
	struct solder{
		int b,l;
	}a[MAXN];
	void modify(int x,int p,int cp){
		if(p>maxn[x][0]){
			maxn[x][2] = maxn[x][1];
			cnt[x][2] = cnt[x][1];
			maxn[x][1] = maxn[x][0];
			cnt[x][1] = cnt[x][0];
			maxn[x][0] = p;
			cnt[x][0] = cp;
		}else if(p==maxn[x][0]) cnt[x][0]+=cp;
		else if(p>maxn[x][1]){
			maxn[x][2] = maxn[x][1];
			cnt[x][2] = cnt[x][1];
			maxn[x][1] = p;
			cnt[x][1] = cp;
		}else if(p==maxn[x][1]) cnt[x][1]+=cp;
		else if(p>maxn[x][2]){
			maxn[x][2] = p;
			cnt[x][2] = cp;
		}else if(p==maxn[x][2]) cnt[x][2]+=cp;
	}
	void modifyl(int x,int l,int cl){
		if(sonl[x][0]<l){
			sonl[x][3] = sonl[x][2];
			sonlc[x][3] = sonlc[x][2];
			sonl[x][2] = sonl[x][1];
			sonlc[x][2] = sonlc[x][1];
			sonl[x][1] = sonl[x][0];
			sonlc[x][1] = sonlc[x][0];
			sonl[x][0] = l;
			sonlc[x][0] = cl;
		}else if(sonl[x][0]==l){
			sonlc[x][0] += cl;
		}else if(sonl[x][1]<l){
			sonl[x][3] = sonl[x][2];
			sonlc[x][3] = sonlc[x][2];
			sonl[x][2] = sonl[x][1];
			sonlc[x][2] = sonlc[x][1];
			sonl[x][1] = l;
			sonlc[x][1] = cl;
		}else if(sonl[x][1]==l){
			sonlc[x][1] += cl;
		}else if(sonl[x][2]<l){
			sonl[x][3] = sonl[x][2];
			sonlc[x][3] = sonlc[x][2];
			sonl[x][2] = l;
			sonlc[x][2] = cl;
		}else if(sonl[x][2]==l){
			sonlc[x][2] += cl;
		}else if(sonl[x][3]<l){
			sonl[x][3] = l;
			sonlc[x][3] = cl;
		}else sonlc[x][3] += cl;
	}
	void dfs1(int x){
		maxn[x][0] = a[x].b;
		cnt[x][0] = 1;
		sonl[x][0] = a[x].l;
		sonlc[x][0] = 1;
		for(int i:v[x]){
			dfs1(i);
			modify(x,maxn[i][0],cnt[i][0]);
			modify(x,maxn[i][1],cnt[i][1]);
			modify(x,maxn[i][2],cnt[i][2]);
			modifyl(x,sonl[i][0],sonlc[i][0]);
			modifyl(x,sonl[i][1],sonlc[i][1]);
		}
	}
	void dfs2(int x){
		if(x==6){
			int k = 0;
		}
		if(x!=1){
			int a = maxl[fath[x]][0];
			int b = maxl[fath[x]][1];
			int c;int d;int now=0;
			if(sonl[fath[x]][now]==sonl[x][0]
				&&sonlc[fath[x]][now]==sonlc[x][0]) now++;
			if(sonl[fath[x]][now]==sonl[x][1]
				&&sonlc[fath[x]][now]==sonlc[x][1]) now++;
			c = sonl[fath[x]][now++];
			if(sonl[fath[x]][now]==sonl[x][0]
				&&sonlc[fath[x]][now]==sonlc[x][0]) now++;
			if(sonl[fath[x]][now]==sonl[x][1]
				&&sonlc[fath[x]][now]==sonlc[x][1]) now++;
			d = sonl[fath[x]][now++];
			set<int> st;
			st.insert(a);
			st.insert(b);
			st.insert(c);
			st.insert(d);
			maxl[x][0] = *st.rbegin();
			maxl[x][1] = (st.size()==1)?(-0x3f3f3f3f3f):*(++st.rbegin());
		}
		for(int i:v[x]){
			dfs2(i);
		}
	}
	signed main(){
		read(n);read(q);
		for(int i = 2;i<=n;i++){
			read(fath[i]);
			v[fath[i]].push_back(i);
		}
		for(int i = 1;i<=n;i++){
			read(a[i].b);read(a[i].l);
		}
		dfs1(1);dfs2(1);
//		for(int i = 1;i<=n;i++){
//			cout << i << endl;
//			cout << "maxn0:" << maxn[i][0] << " " << cnt[i][0] << endl;
//			cout << "maxn1:" << maxn[i][1] << " " << cnt[i][1] << endl;
//			cout << "maxn2:" << maxn[i][2] << " " << cnt[i][2] << endl;
//			cout << "sonl0:" << sonl[i][0] << endl;
//			cout << "sonl1:" << sonl[i][1] << endl;
//			cout << "maxl:" << maxl[i] << endl;
//		}
		while(q--){
			int s;
			read(s);
			if(s==6){
				int l = 0;
			}
			int max1 = maxn[s][0];
			int max2 = maxn[s][1];
			int max3 = maxn[s][2];
//			cout << max1 << " " << max2 << " " << max3 << endl;
			if(!cnt[s][1]){if(cnt[s][0]==1||(maxl[s][0]==0)) write(0,endl);else write(max1,endl);}
			else if(cnt[s][0]>1&&(maxl[s][0]!=0)) write(max1,endl);
			else if(max2+maxl[s][0]<max1) write(max2+maxl[s][0],endl);
			else if(max2+maxl[s][0]>max1) write(max1,endl);
			else write(max((max3!=0)?(max3+maxl[s][0]):0,max2+maxl[s][1]),endl);
//			else write(max2+maxl[s][1],endl);
//			else write((max3!=0)?(max3+maxl[s][0]):0,endl);
		}
		return 0;
	}
}
signed main(){
//	freopen("soldier.in","r",stdin);
//	freopen("soldier.out","w",stdout);
//	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T = 1;
//	gtx::read(T);
	while(T--) gtx::main();
	return 0;
}
/*
mem: 21MB/256MB
*/

信息

递交者
类型
递交
题目
士兵训练(CQ直辖市noip模拟赛) T3
题目数据
下载
语言
C++
递交时间
2024-09-02 16:03:33
评测时间
2024-09-02 16:03:33
评测机
分数
85
总耗时
1152ms
峰值内存
30.797 MiB