답안 #551403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551403 2022-04-20T14:58:51 Z BalintR Sprinkler (JOI22_sprinkler) C++17
100 / 100
700 ms 63296 KB
#include <bits/stdc++.h>
using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef complex<double> cmplx;
template <typename T> using minPq = priority_queue<T, vector<T>, greater<T>>;
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define ms(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define fs first
#define sn second
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int) (v).size())
#define lbv(v, x) (lower_bound((v).begin(), (v).end(), x) - (v).begin())
#define ubv(v, x) (upper_bound((v).begin(), (v).end(), x) - (v).begin())
template <typename T> inline void UNIQUE(vector<T> &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) {cout << #x << ' ' << x << endl;}
#define dbgArr(arr, n) {cout << #arr; FR(_i, n) cout << ' ' << arr[_i]; cout << endl;}

const int MN = 2e5 + 5;
const int H = 40;
int n, mod, q;
vi adjList[MN];
int par[MN];
int init[MN];
int arr[MN][H+2];

void dfs(int n1){
    for(int n2 : adjList[n1]){
        if(n2 != par[n1]) par[n2] = n1, dfs(n2);
    }
}

int main(){
    boost();
    cin >> n >> mod;
    FR(i, n-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        adjList[a].pb(b);
        adjList[b].pb(a);
    }
    FR(i, n) cin >> init[i];

    par[0] = -1;
    dfs(0);
    fill_n(arr[0], MN*(H+2), 1);

    cin >> q;
    while(q--){
        int type; cin >> type;

        if(type == 1){
            int a, d, v;
            cin >> a >> d >> v;
            a--;
            while(a >= 0 && d >= 0){
                arr[a][d] = (ll) arr[a][d] * v % mod;
                a = par[a];
                d--;
            }
        }
        else {
            int a; cin >> a; a--;
            ll res = init[a];
            int d = 0;
            while(a >= 0 && d <= H){
                if(a == 0){
                    FOR(i, d, H+2) res = res * arr[a][i] % mod;
                    break;
                }
                res = res * arr[a][d] % mod;
                res = res * arr[a][d+1] % mod;
                a = par[a];
                d++;
            }
            cout << res << '\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 37844 KB Output is correct
2 Correct 18 ms 37876 KB Output is correct
3 Correct 18 ms 37844 KB Output is correct
4 Correct 21 ms 37940 KB Output is correct
5 Correct 19 ms 37884 KB Output is correct
6 Correct 21 ms 37888 KB Output is correct
7 Correct 20 ms 37836 KB Output is correct
8 Correct 19 ms 37836 KB Output is correct
9 Correct 18 ms 37800 KB Output is correct
10 Correct 17 ms 37844 KB Output is correct
11 Correct 19 ms 37844 KB Output is correct
12 Correct 19 ms 37844 KB Output is correct
13 Correct 18 ms 37844 KB Output is correct
14 Correct 18 ms 37844 KB Output is correct
15 Correct 18 ms 37920 KB Output is correct
16 Correct 19 ms 37800 KB Output is correct
17 Correct 21 ms 37880 KB Output is correct
18 Correct 22 ms 37808 KB Output is correct
19 Correct 20 ms 37844 KB Output is correct
20 Correct 19 ms 37844 KB Output is correct
21 Correct 18 ms 37884 KB Output is correct
22 Correct 20 ms 37868 KB Output is correct
23 Correct 18 ms 37796 KB Output is correct
24 Correct 18 ms 37844 KB Output is correct
25 Correct 19 ms 37896 KB Output is correct
26 Correct 18 ms 37844 KB Output is correct
27 Correct 17 ms 37844 KB Output is correct
28 Correct 20 ms 37832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 637 ms 57136 KB Output is correct
3 Correct 397 ms 55072 KB Output is correct
4 Correct 527 ms 59084 KB Output is correct
5 Correct 456 ms 57044 KB Output is correct
6 Correct 389 ms 54200 KB Output is correct
7 Correct 390 ms 55216 KB Output is correct
8 Correct 300 ms 55648 KB Output is correct
9 Correct 637 ms 61688 KB Output is correct
10 Correct 406 ms 60544 KB Output is correct
11 Correct 573 ms 55568 KB Output is correct
12 Correct 335 ms 52540 KB Output is correct
13 Correct 263 ms 57764 KB Output is correct
14 Correct 253 ms 57296 KB Output is correct
15 Correct 247 ms 48148 KB Output is correct
16 Correct 263 ms 51508 KB Output is correct
17 Correct 266 ms 51920 KB Output is correct
18 Correct 18 ms 37964 KB Output is correct
19 Correct 19 ms 37848 KB Output is correct
20 Correct 18 ms 37892 KB Output is correct
21 Correct 22 ms 37792 KB Output is correct
22 Correct 18 ms 37844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 37844 KB Output is correct
2 Correct 637 ms 57136 KB Output is correct
3 Correct 397 ms 55072 KB Output is correct
4 Correct 527 ms 59084 KB Output is correct
5 Correct 456 ms 57044 KB Output is correct
6 Correct 389 ms 54200 KB Output is correct
7 Correct 390 ms 55216 KB Output is correct
8 Correct 300 ms 55648 KB Output is correct
9 Correct 637 ms 61688 KB Output is correct
10 Correct 406 ms 60544 KB Output is correct
11 Correct 573 ms 55568 KB Output is correct
12 Correct 335 ms 52540 KB Output is correct
13 Correct 263 ms 57764 KB Output is correct
14 Correct 253 ms 57296 KB Output is correct
15 Correct 247 ms 48148 KB Output is correct
16 Correct 263 ms 51508 KB Output is correct
17 Correct 266 ms 51920 KB Output is correct
18 Correct 18 ms 37964 KB Output is correct
19 Correct 19 ms 37848 KB Output is correct
20 Correct 18 ms 37892 KB Output is correct
21 Correct 22 ms 37792 KB Output is correct
22 Correct 18 ms 37844 KB Output is correct
23 Correct 20 ms 37916 KB Output is correct
24 Correct 560 ms 57332 KB Output is correct
25 Correct 400 ms 56696 KB Output is correct
26 Correct 531 ms 63296 KB Output is correct
27 Correct 446 ms 56916 KB Output is correct
28 Correct 381 ms 57400 KB Output is correct
29 Correct 376 ms 57168 KB Output is correct
30 Correct 355 ms 57824 KB Output is correct
31 Correct 669 ms 61288 KB Output is correct
32 Correct 400 ms 62412 KB Output is correct
33 Correct 515 ms 57148 KB Output is correct
34 Correct 381 ms 57272 KB Output is correct
35 Correct 18 ms 37836 KB Output is correct
36 Correct 17 ms 37804 KB Output is correct
37 Correct 22 ms 37868 KB Output is correct
38 Correct 23 ms 37852 KB Output is correct
39 Correct 18 ms 37800 KB Output is correct
40 Correct 18 ms 37844 KB Output is correct
41 Correct 17 ms 37832 KB Output is correct
42 Correct 17 ms 37844 KB Output is correct
43 Correct 18 ms 37844 KB Output is correct
44 Correct 17 ms 37800 KB Output is correct
45 Correct 18 ms 37844 KB Output is correct
46 Correct 18 ms 37788 KB Output is correct
47 Correct 19 ms 37796 KB Output is correct
48 Correct 21 ms 37860 KB Output is correct
49 Correct 18 ms 37844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 37872 KB Output is correct
2 Correct 680 ms 59612 KB Output is correct
3 Correct 623 ms 58656 KB Output is correct
4 Correct 567 ms 58760 KB Output is correct
5 Correct 492 ms 54352 KB Output is correct
6 Correct 435 ms 54152 KB Output is correct
7 Correct 342 ms 54192 KB Output is correct
8 Correct 286 ms 54424 KB Output is correct
9 Correct 662 ms 58556 KB Output is correct
10 Correct 608 ms 59908 KB Output is correct
11 Correct 561 ms 53992 KB Output is correct
12 Correct 567 ms 54600 KB Output is correct
13 Correct 378 ms 55156 KB Output is correct
14 Correct 355 ms 56172 KB Output is correct
15 Correct 20 ms 37844 KB Output is correct
16 Correct 16 ms 37844 KB Output is correct
17 Correct 17 ms 37820 KB Output is correct
18 Correct 23 ms 37816 KB Output is correct
19 Correct 18 ms 37828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 37836 KB Output is correct
2 Correct 690 ms 59980 KB Output is correct
3 Correct 600 ms 58048 KB Output is correct
4 Correct 564 ms 59116 KB Output is correct
5 Correct 507 ms 55960 KB Output is correct
6 Correct 461 ms 55948 KB Output is correct
7 Correct 416 ms 55700 KB Output is correct
8 Correct 322 ms 56168 KB Output is correct
9 Correct 636 ms 62356 KB Output is correct
10 Correct 592 ms 60192 KB Output is correct
11 Correct 560 ms 56504 KB Output is correct
12 Correct 577 ms 54916 KB Output is correct
13 Correct 382 ms 56140 KB Output is correct
14 Correct 374 ms 56336 KB Output is correct
15 Correct 18 ms 37844 KB Output is correct
16 Correct 19 ms 37844 KB Output is correct
17 Correct 22 ms 37904 KB Output is correct
18 Correct 18 ms 37908 KB Output is correct
19 Correct 21 ms 37792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 37844 KB Output is correct
2 Correct 18 ms 37876 KB Output is correct
3 Correct 18 ms 37844 KB Output is correct
4 Correct 21 ms 37940 KB Output is correct
5 Correct 19 ms 37884 KB Output is correct
6 Correct 21 ms 37888 KB Output is correct
7 Correct 20 ms 37836 KB Output is correct
8 Correct 19 ms 37836 KB Output is correct
9 Correct 18 ms 37800 KB Output is correct
10 Correct 17 ms 37844 KB Output is correct
11 Correct 19 ms 37844 KB Output is correct
12 Correct 19 ms 37844 KB Output is correct
13 Correct 18 ms 37844 KB Output is correct
14 Correct 18 ms 37844 KB Output is correct
15 Correct 18 ms 37920 KB Output is correct
16 Correct 19 ms 37800 KB Output is correct
17 Correct 21 ms 37880 KB Output is correct
18 Correct 22 ms 37808 KB Output is correct
19 Correct 20 ms 37844 KB Output is correct
20 Correct 19 ms 37844 KB Output is correct
21 Correct 18 ms 37884 KB Output is correct
22 Correct 20 ms 37868 KB Output is correct
23 Correct 18 ms 37796 KB Output is correct
24 Correct 18 ms 37844 KB Output is correct
25 Correct 19 ms 37896 KB Output is correct
26 Correct 18 ms 37844 KB Output is correct
27 Correct 17 ms 37844 KB Output is correct
28 Correct 20 ms 37832 KB Output is correct
29 Correct 18 ms 37844 KB Output is correct
30 Correct 637 ms 57136 KB Output is correct
31 Correct 397 ms 55072 KB Output is correct
32 Correct 527 ms 59084 KB Output is correct
33 Correct 456 ms 57044 KB Output is correct
34 Correct 389 ms 54200 KB Output is correct
35 Correct 390 ms 55216 KB Output is correct
36 Correct 300 ms 55648 KB Output is correct
37 Correct 637 ms 61688 KB Output is correct
38 Correct 406 ms 60544 KB Output is correct
39 Correct 573 ms 55568 KB Output is correct
40 Correct 335 ms 52540 KB Output is correct
41 Correct 263 ms 57764 KB Output is correct
42 Correct 253 ms 57296 KB Output is correct
43 Correct 247 ms 48148 KB Output is correct
44 Correct 263 ms 51508 KB Output is correct
45 Correct 266 ms 51920 KB Output is correct
46 Correct 18 ms 37964 KB Output is correct
47 Correct 19 ms 37848 KB Output is correct
48 Correct 18 ms 37892 KB Output is correct
49 Correct 22 ms 37792 KB Output is correct
50 Correct 18 ms 37844 KB Output is correct
51 Correct 20 ms 37916 KB Output is correct
52 Correct 560 ms 57332 KB Output is correct
53 Correct 400 ms 56696 KB Output is correct
54 Correct 531 ms 63296 KB Output is correct
55 Correct 446 ms 56916 KB Output is correct
56 Correct 381 ms 57400 KB Output is correct
57 Correct 376 ms 57168 KB Output is correct
58 Correct 355 ms 57824 KB Output is correct
59 Correct 669 ms 61288 KB Output is correct
60 Correct 400 ms 62412 KB Output is correct
61 Correct 515 ms 57148 KB Output is correct
62 Correct 381 ms 57272 KB Output is correct
63 Correct 18 ms 37836 KB Output is correct
64 Correct 17 ms 37804 KB Output is correct
65 Correct 22 ms 37868 KB Output is correct
66 Correct 23 ms 37852 KB Output is correct
67 Correct 18 ms 37800 KB Output is correct
68 Correct 18 ms 37844 KB Output is correct
69 Correct 17 ms 37832 KB Output is correct
70 Correct 17 ms 37844 KB Output is correct
71 Correct 18 ms 37844 KB Output is correct
72 Correct 17 ms 37800 KB Output is correct
73 Correct 18 ms 37844 KB Output is correct
74 Correct 18 ms 37788 KB Output is correct
75 Correct 19 ms 37796 KB Output is correct
76 Correct 21 ms 37860 KB Output is correct
77 Correct 18 ms 37844 KB Output is correct
78 Correct 17 ms 37872 KB Output is correct
79 Correct 680 ms 59612 KB Output is correct
80 Correct 623 ms 58656 KB Output is correct
81 Correct 567 ms 58760 KB Output is correct
82 Correct 492 ms 54352 KB Output is correct
83 Correct 435 ms 54152 KB Output is correct
84 Correct 342 ms 54192 KB Output is correct
85 Correct 286 ms 54424 KB Output is correct
86 Correct 662 ms 58556 KB Output is correct
87 Correct 608 ms 59908 KB Output is correct
88 Correct 561 ms 53992 KB Output is correct
89 Correct 567 ms 54600 KB Output is correct
90 Correct 378 ms 55156 KB Output is correct
91 Correct 355 ms 56172 KB Output is correct
92 Correct 20 ms 37844 KB Output is correct
93 Correct 16 ms 37844 KB Output is correct
94 Correct 17 ms 37820 KB Output is correct
95 Correct 23 ms 37816 KB Output is correct
96 Correct 18 ms 37828 KB Output is correct
97 Correct 24 ms 37836 KB Output is correct
98 Correct 690 ms 59980 KB Output is correct
99 Correct 600 ms 58048 KB Output is correct
100 Correct 564 ms 59116 KB Output is correct
101 Correct 507 ms 55960 KB Output is correct
102 Correct 461 ms 55948 KB Output is correct
103 Correct 416 ms 55700 KB Output is correct
104 Correct 322 ms 56168 KB Output is correct
105 Correct 636 ms 62356 KB Output is correct
106 Correct 592 ms 60192 KB Output is correct
107 Correct 560 ms 56504 KB Output is correct
108 Correct 577 ms 54916 KB Output is correct
109 Correct 382 ms 56140 KB Output is correct
110 Correct 374 ms 56336 KB Output is correct
111 Correct 18 ms 37844 KB Output is correct
112 Correct 19 ms 37844 KB Output is correct
113 Correct 22 ms 37904 KB Output is correct
114 Correct 18 ms 37908 KB Output is correct
115 Correct 21 ms 37792 KB Output is correct
116 Correct 597 ms 54964 KB Output is correct
117 Correct 609 ms 57620 KB Output is correct
118 Correct 607 ms 62244 KB Output is correct
119 Correct 544 ms 57304 KB Output is correct
120 Correct 480 ms 56588 KB Output is correct
121 Correct 411 ms 57568 KB Output is correct
122 Correct 375 ms 57796 KB Output is correct
123 Correct 690 ms 61896 KB Output is correct
124 Correct 700 ms 60696 KB Output is correct
125 Correct 592 ms 55664 KB Output is correct
126 Correct 583 ms 57380 KB Output is correct
127 Correct 577 ms 58112 KB Output is correct
128 Correct 470 ms 55244 KB Output is correct
129 Correct 407 ms 47420 KB Output is correct