Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
27829 | 沈仲恩 | 【S】T1最大后缀值个数 | C++ | 解答错误 | 50 | 384 MS | 24408 KB | 1271 | 2024-03-31 09:51:16 |
#include <bits/stdc++.h> #define int long long #define pii pair<int, int> #define mkp make_pair using namespace std; int n, fa[1000005], mx[1000005], val[1000005], res[1000005]; bool hs[1000005], chain = 1; struct ii { int x; ii(int xx) { x = xx; } bool operator < (const ii i) const { return x > i.x; } }; vector <ii> lst; signed main() { scanf("%lld", &n); for (int i = 2; i <= n; i++) { scanf("%lld", &fa[i]); hs[fa[i]] = 1; if (fa[i] != i - 1) chain = 0; } for (int i = 1; i <= n; i++) scanf("%lld", &val[i]); if (chain || n >= 20000) { for (int i = 1; i <= n; i++) { int p = upper_bound(lst.begin(), lst.end(), ii(val[i])) - lst.begin(); while (lst.size() > p) lst.pop_back(); lst.push_back(val[i]); printf("%lld ", lst.size()); } return 0; } for (int i = 1; i <= n; i++) { mx[i] = val[i]; res[i]++; for (int j = fa[i]; j; j = fa[j]) if (val[j] >= mx[i]) mx[i] = val[j], res[i]++; printf("%lld ", res[i]); } return 0; }