답안 #1015943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1015943 2024-07-07T06:26:02 Z TAhmed33 Sprinkler (JOI22_sprinkler) C++
0 / 100
4 ms 5212 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int B = 40;
const int MAXN = 2e5 + 40 + 25;
int n, l, p[MAXN];
vector <int> adj[MAXN];
int dp[MAXN][B + 1], dep[MAXN];
int mul (int x, int y) {
    return (x * 1ll * y) % l;
}
int h[MAXN];
void dfs (int pos, int par) {
    p[pos] = par;
    for (auto j : adj[pos]) {
        if (j != par) {
            dep[j] = 1 + dep[pos];
            dfs(j, pos);
        }
    }
}
void solve () {
    cin >> n >> l;
    for (int i = 1; i < n; i++) {
        int x, y; cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    p[1] = n + 1;
    for (int i = n + 2; i <= n + 40; i++) {
        p[i - 1] = i;
    }
    for (int i = 1; i <= n + 40; i++) {
        for (int j = 0; j <= B; j++) {
            dp[i][j] = 1;
        }
    }
    int q; cin >> q;
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int x, d, w; cin >> x >> d >> w;
            for (int i = d; i >= 0; i--) {
                dp[x][i] = mul(dp[x][i], w);
                if (i) {
                    dp[x][i - 1] = mul(dp[x][i - 1], w);
                }
                x = p[x];
            }
        } else {
            int x; cin >> x;
            int ret = h[x];
            for (int i = 0; i <= B; i++) {
                ret = mul(ret, dp[x][i]);
                if (p[x]) {
                    x = p[x];
                }
            }
            cout << ret << '\n';
        }
    }
}       
signed main () {
    #ifndef ONLINE_JUDGE 
        freopen("input_file", "r", stdin);
        freopen("output_file", "w", stdout);
    #endif
    ios::sync_with_stdio(0); cin.tie(0);
    int tc = 1; //cin >> tc;
    while (tc--) solve();
}

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen("input_file", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen("output_file", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -