# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
748484 |
2023-05-26T10:55:25 Z |
doowey |
Arboras (RMI20_arboras) |
C++14 |
|
5000 ms |
6380 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e5 + 1;
const int MOD = (int)1e9 + 7;
int p[N];
ll w[N];
pii f[N];
pii g[N];
ll total = 0ll;
void inc(ll y){
y %= MOD;
total += y;
if(total < 0) total += MOD;
else if(total >= MOD) total -= MOD;
}
bool update(int id, pii nw){
inc(-f[id].fi - g[id].fi);
bool ret = false;
if(nw.se == f[id].se){
f[id] = nw;
ret = true;
}
else if(nw.fi > f[id].fi){
g[id] = f[id];
f[id] = nw;
ret = true;
}
else if(nw.fi > g[id].fi){
g[id] = nw;
}
inc(f[id].fi + g[id].fi);
return ret;
}
int main(){
fastIO;
//freopen("in.txt", "r", stdin);
int n;
cin >> n;
for(int i = 1; i < n; i ++ ){
cin >> p[i];
}
for(int i = 0 ; i < n; i ++ ){
f[i].se = -1;
}
for(int i = 1; i < n; i ++ ){
cin >> w[i];
}
for(int i = n - 1; i > 0 ; i -- ){
update(p[i], mp(f[i].fi + w[i], i));
}
int u;
ll ad;
cout << total << "\n";
int q;
cin >> q;
for(int i = 1; i <= q; i ++ ){
cin >> u >> ad;
w[u] += ad;
while(u > 0){
if(update(p[u], mp(f[u].fi + w[u], u))) u = p[u];
else break;
}
cout << total << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
5604 KB |
Output is correct |
2 |
Correct |
48 ms |
5608 KB |
Output is correct |
3 |
Correct |
42 ms |
5580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1611 ms |
5676 KB |
Output is correct |
2 |
Execution timed out |
5042 ms |
6380 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
52 ms |
5604 KB |
Output is correct |
5 |
Correct |
48 ms |
5608 KB |
Output is correct |
6 |
Correct |
42 ms |
5580 KB |
Output is correct |
7 |
Correct |
1611 ms |
5676 KB |
Output is correct |
8 |
Execution timed out |
5042 ms |
6380 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |