/ Randle /

记录详情

Runtime Error

/in/foo.cc: In function 'void xmpl_::fast_wts(std::__cxx11::string)':
/in/foo.cc:72:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < s.size(); i++) pc(s[i]);
                   ~~^~~~~~~~~~
/in/foo.cc: In function 'void xmpl_::wts(std::__cxx11::string)':
/in/foo.cc:139:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < s.size(); i++) putchar(s[i]);
                   ~~^~~~~~~~~~
# 状态 耗时 内存占用
#1 Accepted 8ms 9.645 MiB
#2 Accepted 8ms 9.641 MiB
#3 Accepted 8ms 9.641 MiB
#4 Wrong Answer 8ms 9.574 MiB
#5 Accepted 8ms 9.578 MiB
#6 Accepted 8ms 9.543 MiB
#7 Accepted 17ms 11.23 MiB
#8 Accepted 170ms 25.535 MiB
#9 Accepted 11ms 10.629 MiB
#10 Accepted 38ms 18.312 MiB
#11 Accepted 63ms 25.836 MiB
#12 Accepted 80ms 31.324 MiB
#13 Accepted 32ms 20.352 MiB
#14 Runtime Error 37ms 29.492 MiB
#15 Runtime Error 47ms 34.082 MiB
#16 Runtime Error 60ms 38.656 MiB
#17 Wrong Answer 96ms 29.262 MiB
#18 Wrong Answer 100ms 28.562 MiB
#19 Wrong Answer 101ms 28.051 MiB
#20 Accepted 108ms 34.836 MiB

代码

#include<bits/stdc++.h>
#define int long long
#define rg register
#define il inline
#define TT(T, Args) template<typename T, typename... Args>
#define up(i, a, b) for (rg int i = (a); i <= (b); i++)
#define down(i, a, b) for (rg int i = (a); i >= (b); i--)
#define rep(i, a) for (rg auto i : a)
using namespace std;
namespace xmpl_{
#define SIZE (1 << 24)
	namespace Fast_read{
		char buf[SIZE], *S, *T;
		il char Getchar(){
			if (S == T){
				T = (S = buf) + fread(buf, 1, SIZE, stdin);
				if (S == T) return '\n';
			}
			return *S++;
		}
	}
	namespace Fast_write{
		char buf[SIZE], *S = buf, *T = buf + SIZE;
		il void flush(){
			fwrite(buf, 1, S - buf, stdout);
			S = buf;
		}
		il void Putchar(char c){
			*S++ = c;
			if (S == T) flush();
		}
		struct F{
			~F(){
				flush();
			}
		}fly;
#undef SIZE
	}
#define gc Fast_read::Getchar
#define pc Fast_write::Putchar
	il int fast_rd(){
		int f = 1, x = 0;
		char ch = gc();
		while(ch < '0' || ch > '9'){
			if (ch == '-') f = -1;
			ch = gc();
		}
		while(ch >= '0' && ch <= '9'){
			x = x * 10 + ch - '0';
			ch = gc();
		}
		return x * f;
	}
	il void fast_wt(int x){
		if (x < 0){
			pc('-');
			x = -x;
		}
		if (x > 9) fast_wt(x / 10);
		pc(x % 10 + 48);
	}
	il string fast_rds(){
		string s = "";
		char ch = gc();
		while((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')){
			s += ch;
			ch = gc();
		}
		return s;
	}
	il void fast_wts(string s){
		for (int i = 0; i < s.size(); i++) pc(s[i]);
	}
	il int rd(){
		int f = 1, x = 0;
		char ch = getchar();
		while(ch < '0' || ch > '9'){
			if (ch == '-') f = -1;
			ch = getchar();
		}
		while(ch >= '0' && ch <= '9'){
			x = x * 10 + ch - '0';
			ch = getchar();
		}
		return x * f;
	}
	TT(T, Args) il void rd(T &x){
		int f = 1;
		x = 0;
		char ch = getchar();
		while(ch < '0' || ch > '9'){
			if (ch == '-') f = -1;
			ch = getchar();
		}
		while(ch >= '0' && ch <= '9'){
			x = x * 10 + ch - '0';
			ch = getchar();
		}
		x *= f;
	}
	TT(T, Args) il void rd(T &x, Args &...args){
		rd(x), rd(args...);
	}
	TT(T, Args) il void fast_rd(T &x){
		int f = 1;
		x = 0;
		char ch = gc();
		while(ch < '0' || ch > '9'){
			if (ch == '-') f = -1;
			ch = gc();
		}
		while(ch >= '0' && ch <= '9'){
			x = x * 10 + ch - '0';
			ch = gc();
		}
		x *= f;
	}
	TT(T, Args) il void fast_rd(T &x, Args &...args){
		fast_rd(x), fast_rd(args...);
	}
	il void wt(int x){
		if (x < 0){
			putchar('-');
			x = -x;
		}
		if (x > 9) wt(x / 10);
		putchar(x % 10 + 48);
	}
	il string rds(){
		string s = "";
		char ch = getchar();
		while((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')){
			s += ch;
			ch = getchar();
		}
		return s;
	}
	il void wts(string s){
		for (int i = 0; i < s.size(); i++) putchar(s[i]);
	}
	il int max(int x, int y){
		return (x > y ? x : y);
	}
	il int min(int a, int b){
		return (a < b ? a : b);
	}
	il int max(int x, int y, int z){
		return max(x, max(y, z));
	}
	il int min(int a, int b, int c){
		return min(a, min(b, c));
	}
	il int qmul(int a, int b, int p){
		int res = 0;
		while(b){
			if (b & 1) res = (res + a) % p;
			a = (a + a) % p;
			b >>= 1ll;
		}
		return res;
	}
	il int qpow(int a, int b, int p){
		int res = 1;
		while(b){
			if (b & 1) res = qmul(res, a, p);
			a = qmul(a, a, p);
			b >>= 1ll;
		}
		return res;
	}
	const int Q = 1e6 + 5;
	int fac[Q] = {0}, inv[Q] = {0}, finv[Q] = {0};
	il void init(int n, int p){
		fac[0] = inv[0] = finv[0] = fac[1] = inv[1] = finv[1] = 1;
		for (int i = 2; i <= n; i++){
			fac[i] = 1ll * fac[i - 1] * i % p;
			inv[i] = (p - 1ll * p / i * inv[p % i] % p) % p;
			finv[i] = 1ll * finv[i - 1] * inv[i] % p;
		}
	}
	il int A(int n, int m, int p){
		if (m > n || m < 0) return 0;
		return 1ll * fac[n] * finv[n - m] % p;
	}
	il int C(int n, int m, int p){
		if (m > n || m < 0) return 0;
		return 1ll * fac[n] * finv[m] % p * finv[n - m] % p;
	}
	il int Lucas(int n, int m, int p){
		if (!m) return 1;
		return (1ll * C(n % p, m % p, p) * Lucas(n / p, m / p, p)) % p;
	}
	il int gcd(int a, int b){
		if (!b) return a;
		return gcd(b, a % b);
	}
	il int lcm(int a, int b){
		return 1ll * a * b / gcd(a, b);
	}
	const int W = 1e5 + 5;
	struct int64{
		int d[W];
		int64(){
			memset(d, 0, sizeof(d));
			d[0] = 1;
		}
		int64(int x){
			int64();
			int it = 0;
			while(x){
				d[++it] = x % 10;
				x /= 10;
			}
			d[0] = it;
		}
		bool operator < (const int64 &x) const{
			if (d[0] ^ x.d[0]) return d[0] < x.d[0];
			int it = d[0];
			while(d[it] == x.d[it] && it > 1) it--;
			if (it >= 1) return d[it] < x.d[it];
			else return 0;
		}
		int64 operator * (const int &x){
			int64 ans;
			int len;
			ans.d[0] = d[0];
			for (int i = 1; i <= d[0]; i++) ans.d[i] = d[i] * x;
			for (int i = 1; i <= ans.d[0] || ans.d[i]; i++){
				ans.d[i + 1] += ans.d[i] / 10;
				ans.d[i] %= 10;
				len = i + 1;
			}
			ans.d[0] = len;
			if (!ans.d[len]) ans.d[0]--;
			return ans;
		}
		int64 operator / (const int &x){
			int64 ans;
			ans.d[0] = d[0];
			int res = 0;
			for (int i = d[0]; i >= 1; i--){ 
				res = res * 10 + d[i];
				ans.d[i] = res / x;
				res %= x;
			}
			while(!ans.d[ans.d[0]] && ans.d[0] > 1) ans.d[0]--; 
			return ans;
		}
	};
	std::ostream &operator << (std::ostream &ans, const int64 &x){
		for (int i = x.d[0]; i >= 1; i--) ans << x.d[i];
		return ans;
	}
}
using namespace xmpl_;
using namespace std;

const int N = 4e5 + 5, M = 1e6 + 5, K = 2e6 + 5;
int n, q, fa[N], b[N], l[N], s;
int max1[N], max2[N], max3[N], imax[N], omax[N];
vector<int> g[N];

il void init(){
	
}

il void clear(){
	
}

il void dfs(int u){
	if (!u) return ;
	if (g[u].empty()){
		max1[u] = b[u], imax[u] = l[u];
		return ;
	}
	vector<int> vec;
	vec.push_back(b[u]);
	rep(v, g[u]){
		dfs(v);
		vec.push_back(max1[v]), vec.push_back(max2[v]), vec.push_back(max3[v]);
		imax[u] = max(imax[u], imax[v]);
	} 
	imax[u] = max(imax[u], l[u]);
	sort(vec.begin(), vec.end(), greater<int>());
	max1[u] = vec[0], max2[u] = vec[1], max3[u] = vec[2];
}

il int dfs2(int u, int mx){
	int ans = 0;
	if (b[u] ^ mx) ans = mx;
	rep(v, g[u]) ans = max(ans, dfs2(v, mx));
	return ans;
}

il int calc1(int u){
	if (omax[u]) return omax[u];
	if (u == 1) return omax[u] = 0;
	int f = fa[u], ans = l[f];
	rep(v, g[f]){
		if (v == u) continue;
		ans = max(ans, imax[v]);
	}
	return omax[u] = max(ans, calc1(f));
}

il void calc2(){
	up(i, 1, n) if (g[i].empty()) calc1(i);
}

il void work(){
	rd(n, q);
	up(i, 2, n) fa[i] = rd(), g[fa[i]].push_back(i);
	up(i, 1, n) rd(b[i], l[i]), max1[i] = max2[i] = max3[i] = -1, imax[i] = omax[i] = 0;
	dfs(1), calc2();
	while(q--){
		s = rd();
		if (max2[s] == -1) wt(0);
		else if (max3[s] == -1) wt(min(max2[s] + omax[s], max1[s]));
		else if (!omax[s] && max1[s] == max2[s] && max1[s] == max3[s]) wt(dfs2(s, max1[s])); 
		else if (max2[s] + omax[s] > max1[s]) wt(max1[s]);
		else if (max2[s] + omax[s] < max1[s]) wt(max2[s] + omax[s]);
		else{
			if (max2[s] ^ max3[s]) wt(min(max1[s], max3[s] + omax[s]));
			else wt(max1[s]);
		}
		wts("\n");
	}
}

signed main(){
//#define file 114514
#ifdef file
	freopen("soldier.in", "r", stdin);
	freopen("soldier.out", "w", stdout);
#endif	
	//	init();
	int t = 1;
	//	t = rd();
	while(t--){
		//		clear();
		work();
		//		puts("");
	}
	return 0;
}

信息

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