Submission #1278045

#TimeUsernameProblemLanguageResultExecution timeMemory
1278045minggaSprinkler (JOI22_sprinkler)C++20
0 / 100
1522 ms98480 KiB
// Author: caption_mingle
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 2e5 + 7;
int n, l, a[N], par[N], q;
int ext[N][50];

vector<int> g[N];

int mul(int x, int y) {
	x %= l, y %= l;
    return (1ll * x * y) % l;
}

void dfs(int u, int p) {
    for(int v : g[u]) {
        if(v == p) continue;
        par[v] = u;
        dfs(v, u);
    }
}

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    #define task ""
    if(fopen(task ".INP", "r")) {
        freopen(task ".INP", "r", stdin);
        freopen(task ".OUT", "w", stdout);
    }
    cin >> n >> l;
    for(int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        for(int j = 0; j <= 40; j++) {
            ext[i][j] = 1;
        }
    }
    dfs(1, 0);
    cin >> q;
    for(int i = 1; i <= q; i++) {
        int t; cin >> t;
        if(t == 1) {
            int x, d, w; cin >> x >> d >> w;
            for(int j = d, u = x; j >= 0 and u != 0; j--, u = par[u]) {
                ext[u][j] = mul(ext[u][j], w);
            }
        } else {
            int x; cin >> x;
            int cur = a[x];
            for(int j = 0, u = x; j <= 40 and u != 0; j++, u = par[u]) {
                if(u == 1) {
                    for(int t = j; t <= 40; t++) {
                        cur = mul(cur, ext[u][t]);
                    }
                    break;
                } else {
                	cur = mul(cur, ext[u][j]);
                	cur = mul(cur, ext[u][j + 1]);
                }
            }
            cout << cur << ln;
        }
    }
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task ".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(task ".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...