Submission #748477

# Submission time Handle Problem Language Result Execution time Memory
748477 2023-05-26T10:51:34 Z doowey Arboras (RMI20_arboras) C++14
0 / 100
1179 ms 6056 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) y -= 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;
    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 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 5692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1179 ms 6056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -