This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> p(n);
p[n-1] = -1;
for(int i = 0; i < n-1; i++) {
cin >> p[i];
p[i]--;
}
int q;
cin >> q;
for(int i = 0; i < q; i++) {
char type;
cin >> type;
if (type == 'I') {
int idx;
cin >> idx;
idx--;
cout << a[idx] << "\n";
} else if (type == 'P') {
int idx, by;
cin >> idx >> by;
idx--;
a[idx] += by;
vector<bool> vis(n+1, false);
while(1) {
int par = p[idx];
if (par == -1 || vis[par]) break;
a[par] = max(a[par], a[idx]);
idx = par;
}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |