Submission #965200

# Submission time Handle Problem Language Result Execution time Memory
965200 2024-04-18T08:14:04 Z angella Sprinkler (JOI22_sprinkler) C++17
0 / 100
308 ms 193520 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

ll n, q, l, a[N], h[N], par[N], dp[45][N];
vector<int> adj[N];

void init(int v, int p=0) {
    h[v] = h[p] + 1, par[v] = p;
    for(int i=0; i<=41; i++) dp[i][v] = 1;
    for(int u : adj[v]) {
        if(u == p) continue;
        init(u, v);
    }
}

int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>n>>l; Mod = l;
    for(int v,u,i=1; i<n; i++) {
        cin>>v>>u; adj[v].pb(u); adj[u].pb(v);
    }
    init(1);
    for(int i=1; i<=n; i++) cin>>a[i];

    cin>>q;
    for(ll typ,x,d,w,tc=1; tc<=q; tc++) {
        cin>>typ>>x;
        if(typ == 1) {
            cin>>d>>w;
            while(d>=0 && x>0) {
                dp[d][x] = dp[d][x] * w % l;
                //fuck(d);
                d--; x = par[x];
            }
        } else {
            ll v = x, num = 0, res = a[v];
            while(x > 0) {
                if(par[x] > 0) {
                    if(num>=0)res = MOD(res*dp[num][x]);
                    if(num+1<=40)res = MOD(res*dp[num+1][x]);
                    x = par[x];
                } else {
                    for(int i=40;i-num>=0;i--) res=MOD(res*dp[i][x]);
                    break;
                }
                num++;
            }
            cout<<res<<endl;
        }
    }

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7772 KB Output is correct
2 Correct 4 ms 7772 KB Output is correct
3 Correct 4 ms 7772 KB Output is correct
4 Runtime error 12 ms 16276 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7772 KB Output is correct
2 Runtime error 268 ms 175668 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7772 KB Output is correct
2 Runtime error 268 ms 175668 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7768 KB Output is correct
2 Runtime error 298 ms 193520 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7772 KB Output is correct
2 Runtime error 308 ms 187404 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7772 KB Output is correct
2 Correct 4 ms 7772 KB Output is correct
3 Correct 4 ms 7772 KB Output is correct
4 Runtime error 12 ms 16276 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -