답안 #571685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571685 2022-06-02T14:21:05 Z maomao90 Sprinkler (JOI22_sprinkler) C++17
100 / 100
1010 ms 73644 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

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

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 400005;
const int MAXD = 41;

int n, l;
vii adj[MAXN];
int h[MAXN];
int q;
int lz[MAXD][MAXN];

int p[MAXN];
void dfs(int u) {
    REP (i, 0, adj[u].size()) {
        if (adj[u][i].FI == p[u]) {
            swap(adj[u][i], adj[u][SZ(adj[u]) - 1]);
            break;
        }
    }
    for (auto &[v, id] : adj[u]) {
        if (v == p[u]) continue;
        p[v] = u;
        dfs(v);
    }
}

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n >> l;
    REP (i, 1, n) {
        int a, b; cin >> a >> b;
        adj[a].pb({b, 0});
        adj[b].pb({a, 0});
    }
    dfs(1);
    REP (i, 1, n + 1) {
        cin >> h[i];
    }
    REP (i, 0, MAXD) {
        REP (j, 0, n + 1) {
            lz[i][j] = 1;
        }
    }
    cin >> q;
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int x, d, w; cin >> x >> d >> w;
            int u = x;
            RREP (i, d, 0) {
                lz[i][u] = (ll) lz[i][u] * w % l;
                if (i) {
                    lz[i - 1][u] = (ll) lz[i - 1][u] * w % l;
                }
                if (p[u] == 0) {
                    RREP (j, i - 2, 0) {
                        lz[j][u] = (ll) lz[j][u] * w % l;
                    }
                    break;
                }
                u = p[u];
            }
        } else {
            int x; cin >> x;
            int ans = h[x];
            int u = x;
            REP (i, 0, MAXD) {
                ans = (ll) ans * lz[i][u] % l;
                if (p[u] == 0) {
                    break;
                }
                u = p[u];
            }
            cout << ans << '\n';
        }
    }
    return 0;
}

/*
6 10
5 6
1 2
1 4
2 6
3 6
9
2
3
4
9
1
2
1 4 1 9
2 1

4 7
1 2
2 3
3 4
1
1
1
1
2
1 1 0 2
2 1
*/

Compilation message

sprinkler.cpp: In function 'void dfs(int)':
sprinkler.cpp:16:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
   50 |     REP (i, 0, adj[u].size()) {
      |          ~~~~~~~~~~~~~~~~~~~            
sprinkler.cpp:50:5: note: in expansion of macro 'REP'
   50 |     REP (i, 0, adj[u].size()) {
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9940 KB Output is correct
2 Correct 8 ms 9980 KB Output is correct
3 Correct 8 ms 10016 KB Output is correct
4 Correct 7 ms 10256 KB Output is correct
5 Correct 6 ms 10196 KB Output is correct
6 Correct 7 ms 10196 KB Output is correct
7 Correct 9 ms 10196 KB Output is correct
8 Correct 6 ms 10252 KB Output is correct
9 Correct 7 ms 10004 KB Output is correct
10 Correct 7 ms 9924 KB Output is correct
11 Correct 7 ms 9988 KB Output is correct
12 Correct 7 ms 9984 KB Output is correct
13 Correct 7 ms 10020 KB Output is correct
14 Correct 6 ms 9992 KB Output is correct
15 Correct 12 ms 10008 KB Output is correct
16 Correct 6 ms 9988 KB Output is correct
17 Correct 6 ms 9940 KB Output is correct
18 Correct 6 ms 9980 KB Output is correct
19 Correct 9 ms 9912 KB Output is correct
20 Correct 9 ms 9928 KB Output is correct
21 Correct 9 ms 9984 KB Output is correct
22 Correct 6 ms 9912 KB Output is correct
23 Correct 8 ms 9940 KB Output is correct
24 Correct 8 ms 9980 KB Output is correct
25 Correct 6 ms 9980 KB Output is correct
26 Correct 6 ms 9940 KB Output is correct
27 Correct 6 ms 10036 KB Output is correct
28 Correct 9 ms 9976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9940 KB Output is correct
2 Correct 679 ms 62692 KB Output is correct
3 Correct 455 ms 63244 KB Output is correct
4 Correct 543 ms 69600 KB Output is correct
5 Correct 496 ms 62568 KB Output is correct
6 Correct 365 ms 61208 KB Output is correct
7 Correct 335 ms 63316 KB Output is correct
8 Correct 252 ms 62152 KB Output is correct
9 Correct 682 ms 73644 KB Output is correct
10 Correct 410 ms 73072 KB Output is correct
11 Correct 641 ms 61928 KB Output is correct
12 Correct 360 ms 60304 KB Output is correct
13 Correct 248 ms 63180 KB Output is correct
14 Correct 263 ms 63684 KB Output is correct
15 Correct 240 ms 57776 KB Output is correct
16 Correct 244 ms 62012 KB Output is correct
17 Correct 251 ms 60688 KB Output is correct
18 Correct 6 ms 9992 KB Output is correct
19 Correct 8 ms 9940 KB Output is correct
20 Correct 5 ms 9940 KB Output is correct
21 Correct 5 ms 9988 KB Output is correct
22 Correct 6 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9940 KB Output is correct
2 Correct 679 ms 62692 KB Output is correct
3 Correct 455 ms 63244 KB Output is correct
4 Correct 543 ms 69600 KB Output is correct
5 Correct 496 ms 62568 KB Output is correct
6 Correct 365 ms 61208 KB Output is correct
7 Correct 335 ms 63316 KB Output is correct
8 Correct 252 ms 62152 KB Output is correct
9 Correct 682 ms 73644 KB Output is correct
10 Correct 410 ms 73072 KB Output is correct
11 Correct 641 ms 61928 KB Output is correct
12 Correct 360 ms 60304 KB Output is correct
13 Correct 248 ms 63180 KB Output is correct
14 Correct 263 ms 63684 KB Output is correct
15 Correct 240 ms 57776 KB Output is correct
16 Correct 244 ms 62012 KB Output is correct
17 Correct 251 ms 60688 KB Output is correct
18 Correct 6 ms 9992 KB Output is correct
19 Correct 8 ms 9940 KB Output is correct
20 Correct 5 ms 9940 KB Output is correct
21 Correct 5 ms 9988 KB Output is correct
22 Correct 6 ms 9940 KB Output is correct
23 Correct 5 ms 9912 KB Output is correct
24 Correct 546 ms 62624 KB Output is correct
25 Correct 346 ms 62720 KB Output is correct
26 Correct 538 ms 73316 KB Output is correct
27 Correct 453 ms 62244 KB Output is correct
28 Correct 324 ms 62788 KB Output is correct
29 Correct 327 ms 62580 KB Output is correct
30 Correct 229 ms 62640 KB Output is correct
31 Correct 583 ms 69760 KB Output is correct
32 Correct 341 ms 72256 KB Output is correct
33 Correct 545 ms 62336 KB Output is correct
34 Correct 425 ms 62548 KB Output is correct
35 Correct 6 ms 9940 KB Output is correct
36 Correct 6 ms 9940 KB Output is correct
37 Correct 5 ms 9940 KB Output is correct
38 Correct 6 ms 9984 KB Output is correct
39 Correct 6 ms 10024 KB Output is correct
40 Correct 6 ms 9940 KB Output is correct
41 Correct 6 ms 9940 KB Output is correct
42 Correct 6 ms 9976 KB Output is correct
43 Correct 5 ms 9996 KB Output is correct
44 Correct 7 ms 10068 KB Output is correct
45 Correct 6 ms 9980 KB Output is correct
46 Correct 7 ms 9940 KB Output is correct
47 Correct 6 ms 9940 KB Output is correct
48 Correct 7 ms 9940 KB Output is correct
49 Correct 6 ms 9984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9940 KB Output is correct
2 Correct 624 ms 70256 KB Output is correct
3 Correct 847 ms 68136 KB Output is correct
4 Correct 579 ms 67996 KB Output is correct
5 Correct 568 ms 59432 KB Output is correct
6 Correct 454 ms 59616 KB Output is correct
7 Correct 339 ms 59780 KB Output is correct
8 Correct 300 ms 60072 KB Output is correct
9 Correct 688 ms 67036 KB Output is correct
10 Correct 867 ms 69704 KB Output is correct
11 Correct 634 ms 59428 KB Output is correct
12 Correct 874 ms 59996 KB Output is correct
13 Correct 715 ms 61004 KB Output is correct
14 Correct 621 ms 61824 KB Output is correct
15 Correct 7 ms 10068 KB Output is correct
16 Correct 7 ms 9940 KB Output is correct
17 Correct 6 ms 9940 KB Output is correct
18 Correct 8 ms 9940 KB Output is correct
19 Correct 6 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9996 KB Output is correct
2 Correct 691 ms 68780 KB Output is correct
3 Correct 1010 ms 65712 KB Output is correct
4 Correct 646 ms 67752 KB Output is correct
5 Correct 613 ms 61076 KB Output is correct
6 Correct 404 ms 61064 KB Output is correct
7 Correct 421 ms 61408 KB Output is correct
8 Correct 258 ms 61368 KB Output is correct
9 Correct 631 ms 72172 KB Output is correct
10 Correct 791 ms 70988 KB Output is correct
11 Correct 595 ms 61964 KB Output is correct
12 Correct 758 ms 60376 KB Output is correct
13 Correct 615 ms 61192 KB Output is correct
14 Correct 678 ms 62000 KB Output is correct
15 Correct 5 ms 9940 KB Output is correct
16 Correct 5 ms 9940 KB Output is correct
17 Correct 7 ms 9940 KB Output is correct
18 Correct 7 ms 9976 KB Output is correct
19 Correct 5 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9940 KB Output is correct
2 Correct 8 ms 9980 KB Output is correct
3 Correct 8 ms 10016 KB Output is correct
4 Correct 7 ms 10256 KB Output is correct
5 Correct 6 ms 10196 KB Output is correct
6 Correct 7 ms 10196 KB Output is correct
7 Correct 9 ms 10196 KB Output is correct
8 Correct 6 ms 10252 KB Output is correct
9 Correct 7 ms 10004 KB Output is correct
10 Correct 7 ms 9924 KB Output is correct
11 Correct 7 ms 9988 KB Output is correct
12 Correct 7 ms 9984 KB Output is correct
13 Correct 7 ms 10020 KB Output is correct
14 Correct 6 ms 9992 KB Output is correct
15 Correct 12 ms 10008 KB Output is correct
16 Correct 6 ms 9988 KB Output is correct
17 Correct 6 ms 9940 KB Output is correct
18 Correct 6 ms 9980 KB Output is correct
19 Correct 9 ms 9912 KB Output is correct
20 Correct 9 ms 9928 KB Output is correct
21 Correct 9 ms 9984 KB Output is correct
22 Correct 6 ms 9912 KB Output is correct
23 Correct 8 ms 9940 KB Output is correct
24 Correct 8 ms 9980 KB Output is correct
25 Correct 6 ms 9980 KB Output is correct
26 Correct 6 ms 9940 KB Output is correct
27 Correct 6 ms 10036 KB Output is correct
28 Correct 9 ms 9976 KB Output is correct
29 Correct 5 ms 9940 KB Output is correct
30 Correct 679 ms 62692 KB Output is correct
31 Correct 455 ms 63244 KB Output is correct
32 Correct 543 ms 69600 KB Output is correct
33 Correct 496 ms 62568 KB Output is correct
34 Correct 365 ms 61208 KB Output is correct
35 Correct 335 ms 63316 KB Output is correct
36 Correct 252 ms 62152 KB Output is correct
37 Correct 682 ms 73644 KB Output is correct
38 Correct 410 ms 73072 KB Output is correct
39 Correct 641 ms 61928 KB Output is correct
40 Correct 360 ms 60304 KB Output is correct
41 Correct 248 ms 63180 KB Output is correct
42 Correct 263 ms 63684 KB Output is correct
43 Correct 240 ms 57776 KB Output is correct
44 Correct 244 ms 62012 KB Output is correct
45 Correct 251 ms 60688 KB Output is correct
46 Correct 6 ms 9992 KB Output is correct
47 Correct 8 ms 9940 KB Output is correct
48 Correct 5 ms 9940 KB Output is correct
49 Correct 5 ms 9988 KB Output is correct
50 Correct 6 ms 9940 KB Output is correct
51 Correct 5 ms 9912 KB Output is correct
52 Correct 546 ms 62624 KB Output is correct
53 Correct 346 ms 62720 KB Output is correct
54 Correct 538 ms 73316 KB Output is correct
55 Correct 453 ms 62244 KB Output is correct
56 Correct 324 ms 62788 KB Output is correct
57 Correct 327 ms 62580 KB Output is correct
58 Correct 229 ms 62640 KB Output is correct
59 Correct 583 ms 69760 KB Output is correct
60 Correct 341 ms 72256 KB Output is correct
61 Correct 545 ms 62336 KB Output is correct
62 Correct 425 ms 62548 KB Output is correct
63 Correct 6 ms 9940 KB Output is correct
64 Correct 6 ms 9940 KB Output is correct
65 Correct 5 ms 9940 KB Output is correct
66 Correct 6 ms 9984 KB Output is correct
67 Correct 6 ms 10024 KB Output is correct
68 Correct 6 ms 9940 KB Output is correct
69 Correct 6 ms 9940 KB Output is correct
70 Correct 6 ms 9976 KB Output is correct
71 Correct 5 ms 9996 KB Output is correct
72 Correct 7 ms 10068 KB Output is correct
73 Correct 6 ms 9980 KB Output is correct
74 Correct 7 ms 9940 KB Output is correct
75 Correct 6 ms 9940 KB Output is correct
76 Correct 7 ms 9940 KB Output is correct
77 Correct 6 ms 9984 KB Output is correct
78 Correct 5 ms 9940 KB Output is correct
79 Correct 624 ms 70256 KB Output is correct
80 Correct 847 ms 68136 KB Output is correct
81 Correct 579 ms 67996 KB Output is correct
82 Correct 568 ms 59432 KB Output is correct
83 Correct 454 ms 59616 KB Output is correct
84 Correct 339 ms 59780 KB Output is correct
85 Correct 300 ms 60072 KB Output is correct
86 Correct 688 ms 67036 KB Output is correct
87 Correct 867 ms 69704 KB Output is correct
88 Correct 634 ms 59428 KB Output is correct
89 Correct 874 ms 59996 KB Output is correct
90 Correct 715 ms 61004 KB Output is correct
91 Correct 621 ms 61824 KB Output is correct
92 Correct 7 ms 10068 KB Output is correct
93 Correct 7 ms 9940 KB Output is correct
94 Correct 6 ms 9940 KB Output is correct
95 Correct 8 ms 9940 KB Output is correct
96 Correct 6 ms 9940 KB Output is correct
97 Correct 7 ms 9996 KB Output is correct
98 Correct 691 ms 68780 KB Output is correct
99 Correct 1010 ms 65712 KB Output is correct
100 Correct 646 ms 67752 KB Output is correct
101 Correct 613 ms 61076 KB Output is correct
102 Correct 404 ms 61064 KB Output is correct
103 Correct 421 ms 61408 KB Output is correct
104 Correct 258 ms 61368 KB Output is correct
105 Correct 631 ms 72172 KB Output is correct
106 Correct 791 ms 70988 KB Output is correct
107 Correct 595 ms 61964 KB Output is correct
108 Correct 758 ms 60376 KB Output is correct
109 Correct 615 ms 61192 KB Output is correct
110 Correct 678 ms 62000 KB Output is correct
111 Correct 5 ms 9940 KB Output is correct
112 Correct 5 ms 9940 KB Output is correct
113 Correct 7 ms 9940 KB Output is correct
114 Correct 7 ms 9976 KB Output is correct
115 Correct 5 ms 9940 KB Output is correct
116 Correct 628 ms 60112 KB Output is correct
117 Correct 776 ms 62900 KB Output is correct
118 Correct 612 ms 72776 KB Output is correct
119 Correct 598 ms 62436 KB Output is correct
120 Correct 444 ms 61756 KB Output is correct
121 Correct 421 ms 62824 KB Output is correct
122 Correct 304 ms 62844 KB Output is correct
123 Correct 634 ms 70884 KB Output is correct
124 Correct 787 ms 69152 KB Output is correct
125 Correct 607 ms 61180 KB Output is correct
126 Correct 785 ms 62464 KB Output is correct
127 Correct 780 ms 63152 KB Output is correct
128 Correct 594 ms 63656 KB Output is correct
129 Correct 773 ms 64988 KB Output is correct