답안 #1090036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090036 2024-09-17T15:57:02 Z Neco_arc Sprinkler (JOI22_sprinkler) C++17
100 / 100
618 ms 96080 KB
#include <bits/stdc++.h>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL

#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Sprinkler"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7

using namespace std;

ll mod = 1e9 + 7; //972663749
const ll base = 911382323;

int n, q;
int par[maxn];
ll f[maxn][42], a[maxn];
vector<int> edges[maxn];

void pre_dfs(int u, int p) {
    for(int v : edges[u]) if(v != p) {
        par[v] = u;
        pre_dfs(v, u);
    }
}

void update(int x, int k, ll w) {
    int i;
    for(i = 0; i <= k && x != 0; ++i) {
        int remain = k - i;
        f[x][remain] = f[x][remain] * w % mod;
        if(remain - 1 >= 0) f[x][remain - 1] = f[x][remain - 1] * w % mod;
        x = par[x];
    }

    if(x == 0) {
        fi(t, 1, k - i) f[0][t] = f[0][t] * w % mod;
    }

}

ll get(int x) {
    ll ans = a[x], d = 0;
    fi(_, 0, 40) {
        ans = ans * f[x][d] % mod;
        x = par[x], ++d;
        if(x == 0) break;
    }
    if(x == 0) ans = ans * f[0][d] % mod;
    return ans;
}

void solve()
{
    cin >> n >> mod;
    fi(i, 1, n - 1) {
        int x, y; cin >> x >> y;
        edges[x].push_back(y), edges[y].push_back(x);
    }
    fi(i, 1, n) cin >> a[i];

    fi(i, 0, n) fi(j, 0, 41) f[i][j] = 1;
    pre_dfs(1, 0);

    cin >> q;
    fi(i, 1, q) {
        int type, x, k, w; cin >> type >> x;
        if(type == 1) cin >> k >> w, update(x, k, w);
        else cout << get(x) << '\n';
    }

}


int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen(Neco".inp", "r")) {
        freopen(Neco".inp", "r", stdin);
        freopen(Neco".out", "w", stdout);
    }


    int nTest = 1;
//    cin >> nTest;


    while(nTest--)
    {
        solve();
    }


    return 0;
}

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 4 ms 5468 KB Output is correct
5 Correct 3 ms 5468 KB Output is correct
6 Correct 3 ms 5468 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 3 ms 5468 KB Output is correct
9 Correct 2 ms 5000 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 5044 KB Output is correct
12 Correct 4 ms 5172 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 4 ms 4956 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 5020 KB Output is correct
26 Correct 4 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 442 ms 91216 KB Output is correct
3 Correct 253 ms 91920 KB Output is correct
4 Correct 385 ms 94544 KB Output is correct
5 Correct 343 ms 91472 KB Output is correct
6 Correct 242 ms 91024 KB Output is correct
7 Correct 246 ms 91860 KB Output is correct
8 Correct 201 ms 92280 KB Output is correct
9 Correct 507 ms 95824 KB Output is correct
10 Correct 274 ms 95824 KB Output is correct
11 Correct 408 ms 91220 KB Output is correct
12 Correct 236 ms 91688 KB Output is correct
13 Correct 159 ms 92100 KB Output is correct
14 Correct 163 ms 92612 KB Output is correct
15 Correct 159 ms 91984 KB Output is correct
16 Correct 173 ms 92500 KB Output is correct
17 Correct 170 ms 92752 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 5180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 442 ms 91216 KB Output is correct
3 Correct 253 ms 91920 KB Output is correct
4 Correct 385 ms 94544 KB Output is correct
5 Correct 343 ms 91472 KB Output is correct
6 Correct 242 ms 91024 KB Output is correct
7 Correct 246 ms 91860 KB Output is correct
8 Correct 201 ms 92280 KB Output is correct
9 Correct 507 ms 95824 KB Output is correct
10 Correct 274 ms 95824 KB Output is correct
11 Correct 408 ms 91220 KB Output is correct
12 Correct 236 ms 91688 KB Output is correct
13 Correct 159 ms 92100 KB Output is correct
14 Correct 163 ms 92612 KB Output is correct
15 Correct 159 ms 91984 KB Output is correct
16 Correct 173 ms 92500 KB Output is correct
17 Correct 170 ms 92752 KB Output is correct
18 Correct 3 ms 4952 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 5180 KB Output is correct
23 Correct 2 ms 5168 KB Output is correct
24 Correct 440 ms 91348 KB Output is correct
25 Correct 308 ms 91904 KB Output is correct
26 Correct 377 ms 95824 KB Output is correct
27 Correct 337 ms 91472 KB Output is correct
28 Correct 248 ms 91656 KB Output is correct
29 Correct 241 ms 91320 KB Output is correct
30 Correct 211 ms 92360 KB Output is correct
31 Correct 492 ms 94504 KB Output is correct
32 Correct 297 ms 96080 KB Output is correct
33 Correct 436 ms 91252 KB Output is correct
34 Correct 257 ms 91732 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 4956 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 2 ms 5168 KB Output is correct
43 Correct 2 ms 4988 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 3 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 562 ms 92772 KB Output is correct
3 Correct 618 ms 92472 KB Output is correct
4 Correct 484 ms 92244 KB Output is correct
5 Correct 374 ms 88624 KB Output is correct
6 Correct 247 ms 88636 KB Output is correct
7 Correct 235 ms 88912 KB Output is correct
8 Correct 183 ms 89288 KB Output is correct
9 Correct 492 ms 91476 KB Output is correct
10 Correct 594 ms 92988 KB Output is correct
11 Correct 443 ms 88352 KB Output is correct
12 Correct 455 ms 89168 KB Output is correct
13 Correct 311 ms 89996 KB Output is correct
14 Correct 318 ms 90376 KB Output is correct
15 Correct 3 ms 4952 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4968 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 541 ms 94076 KB Output is correct
3 Correct 588 ms 91756 KB Output is correct
4 Correct 507 ms 92720 KB Output is correct
5 Correct 415 ms 90116 KB Output is correct
6 Correct 258 ms 90320 KB Output is correct
7 Correct 237 ms 89940 KB Output is correct
8 Correct 196 ms 90452 KB Output is correct
9 Correct 500 ms 95316 KB Output is correct
10 Correct 536 ms 93780 KB Output is correct
11 Correct 476 ms 90912 KB Output is correct
12 Correct 471 ms 89396 KB Output is correct
13 Correct 326 ms 90244 KB Output is correct
14 Correct 310 ms 90720 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 5140 KB Output is correct
17 Correct 3 ms 4952 KB Output is correct
18 Correct 2 ms 5164 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 4 ms 5468 KB Output is correct
5 Correct 3 ms 5468 KB Output is correct
6 Correct 3 ms 5468 KB Output is correct
7 Correct 3 ms 5468 KB Output is correct
8 Correct 3 ms 5468 KB Output is correct
9 Correct 2 ms 5000 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 5044 KB Output is correct
12 Correct 4 ms 5172 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 4 ms 4956 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 5020 KB Output is correct
26 Correct 4 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 2 ms 4952 KB Output is correct
30 Correct 442 ms 91216 KB Output is correct
31 Correct 253 ms 91920 KB Output is correct
32 Correct 385 ms 94544 KB Output is correct
33 Correct 343 ms 91472 KB Output is correct
34 Correct 242 ms 91024 KB Output is correct
35 Correct 246 ms 91860 KB Output is correct
36 Correct 201 ms 92280 KB Output is correct
37 Correct 507 ms 95824 KB Output is correct
38 Correct 274 ms 95824 KB Output is correct
39 Correct 408 ms 91220 KB Output is correct
40 Correct 236 ms 91688 KB Output is correct
41 Correct 159 ms 92100 KB Output is correct
42 Correct 163 ms 92612 KB Output is correct
43 Correct 159 ms 91984 KB Output is correct
44 Correct 173 ms 92500 KB Output is correct
45 Correct 170 ms 92752 KB Output is correct
46 Correct 3 ms 4952 KB Output is correct
47 Correct 3 ms 4956 KB Output is correct
48 Correct 3 ms 4956 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
50 Correct 2 ms 5180 KB Output is correct
51 Correct 2 ms 5168 KB Output is correct
52 Correct 440 ms 91348 KB Output is correct
53 Correct 308 ms 91904 KB Output is correct
54 Correct 377 ms 95824 KB Output is correct
55 Correct 337 ms 91472 KB Output is correct
56 Correct 248 ms 91656 KB Output is correct
57 Correct 241 ms 91320 KB Output is correct
58 Correct 211 ms 92360 KB Output is correct
59 Correct 492 ms 94504 KB Output is correct
60 Correct 297 ms 96080 KB Output is correct
61 Correct 436 ms 91252 KB Output is correct
62 Correct 257 ms 91732 KB Output is correct
63 Correct 2 ms 4956 KB Output is correct
64 Correct 2 ms 4956 KB Output is correct
65 Correct 2 ms 4956 KB Output is correct
66 Correct 2 ms 4956 KB Output is correct
67 Correct 2 ms 4956 KB Output is correct
68 Correct 2 ms 4956 KB Output is correct
69 Correct 2 ms 4956 KB Output is correct
70 Correct 2 ms 5168 KB Output is correct
71 Correct 2 ms 4988 KB Output is correct
72 Correct 2 ms 4956 KB Output is correct
73 Correct 2 ms 4956 KB Output is correct
74 Correct 2 ms 4956 KB Output is correct
75 Correct 3 ms 4956 KB Output is correct
76 Correct 2 ms 4956 KB Output is correct
77 Correct 2 ms 4956 KB Output is correct
78 Correct 2 ms 4956 KB Output is correct
79 Correct 562 ms 92772 KB Output is correct
80 Correct 618 ms 92472 KB Output is correct
81 Correct 484 ms 92244 KB Output is correct
82 Correct 374 ms 88624 KB Output is correct
83 Correct 247 ms 88636 KB Output is correct
84 Correct 235 ms 88912 KB Output is correct
85 Correct 183 ms 89288 KB Output is correct
86 Correct 492 ms 91476 KB Output is correct
87 Correct 594 ms 92988 KB Output is correct
88 Correct 443 ms 88352 KB Output is correct
89 Correct 455 ms 89168 KB Output is correct
90 Correct 311 ms 89996 KB Output is correct
91 Correct 318 ms 90376 KB Output is correct
92 Correct 3 ms 4952 KB Output is correct
93 Correct 2 ms 4956 KB Output is correct
94 Correct 2 ms 4968 KB Output is correct
95 Correct 2 ms 4952 KB Output is correct
96 Correct 3 ms 5212 KB Output is correct
97 Correct 2 ms 4952 KB Output is correct
98 Correct 541 ms 94076 KB Output is correct
99 Correct 588 ms 91756 KB Output is correct
100 Correct 507 ms 92720 KB Output is correct
101 Correct 415 ms 90116 KB Output is correct
102 Correct 258 ms 90320 KB Output is correct
103 Correct 237 ms 89940 KB Output is correct
104 Correct 196 ms 90452 KB Output is correct
105 Correct 500 ms 95316 KB Output is correct
106 Correct 536 ms 93780 KB Output is correct
107 Correct 476 ms 90912 KB Output is correct
108 Correct 471 ms 89396 KB Output is correct
109 Correct 326 ms 90244 KB Output is correct
110 Correct 310 ms 90720 KB Output is correct
111 Correct 2 ms 4956 KB Output is correct
112 Correct 2 ms 5140 KB Output is correct
113 Correct 3 ms 4952 KB Output is correct
114 Correct 2 ms 5164 KB Output is correct
115 Correct 2 ms 4956 KB Output is correct
116 Correct 440 ms 89168 KB Output is correct
117 Correct 486 ms 91736 KB Output is correct
118 Correct 474 ms 95740 KB Output is correct
119 Correct 400 ms 91472 KB Output is correct
120 Correct 281 ms 91220 KB Output is correct
121 Correct 256 ms 91984 KB Output is correct
122 Correct 194 ms 92360 KB Output is correct
123 Correct 494 ms 95024 KB Output is correct
124 Correct 549 ms 94548 KB Output is correct
125 Correct 423 ms 90436 KB Output is correct
126 Correct 442 ms 91728 KB Output is correct
127 Correct 498 ms 92136 KB Output is correct
128 Correct 325 ms 93008 KB Output is correct
129 Correct 349 ms 93520 KB Output is correct