답안 #590737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590737 2022-07-06T09:50:27 Z Ronin13 Sprinkler (JOI22_sprinkler) C++14
100 / 100
1049 ms 98552 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb push_back
#define epb emplace_back
using namespace std;


ll mod;
const int NMAX = 2e5 + 1;
vector <vector <int> > g(NMAX);
vector <int >p(NMAX);
const int KMAX = 41;
ll d[NMAX][KMAX];

void dfs(int v, int e = -1){
    p[v] = e;
    for(int to : g[v]){
        if(to == e) continue;
        dfs(to, v);
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    cin >> mod;
    ll h[n + 1];
    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++){
        for(int j = 0 ; j < KMAX; j++) d[i][j] = 1;
    }
    for(int i= 1; i <= n; i++){
        cin >> h[i];
    }
    dfs(1);
    int q; cin >> q;
    while(q--){
        int type; cin >> type;
        if(type == 1){
            int v;
            cin >> v;
            int dd; cin >> dd;
            ll w; cin >> w;
            vector <pii> vec;
            int cur = v;
            int cur1 = dd;
            while(vec.size() <= dd){
                vec.pb({cur, cur1});
                cur = p[cur];
                if(cur == -1) break;
                cur1--;
            }
            reverse(vec.begin(), vec.end());
            for(int i = 0; i <= vec[0].s; i++){
                int x = vec[0].f;
                d[x][i] *= w;
                d[x][i] %= mod;
            }
            for(int i = 1; i < vec.size(); i++){
                int x = vec[i].f;
                int y = vec[i].s;
                d[x][y - 1] *= w;
                d[x][y - 1] %= mod;
                d[x][y] *= w;
                d[x][y] %= mod;
            }
            /*for(int i = 1; i <= n; i++){
                for(int j = 0; j <= 40; j++){
                    cout << d[i][j] << ' ';
                }
                cout << "\n";
            }*/
        }
        if(type == 2){
            int v; cin >> v;
            vector <int> vec;
            int cur = v;
            while(cur != -1 && vec.size() <= 40){
                vec.pb(cur);
                cur = p[cur];
            }
            ll ans = 1;
            for(int i = 0; i < vec.size(); i++){
                int x = vec[i];
                ans *= d[x][i];
                ans %= mod;
            }
            ans *= h[v];
            ans %= mod;
            cout << ans << "\n";
        }
    }
    return 0;
}

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:56:30: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |             while(vec.size() <= dd){
      |                   ~~~~~~~~~~~^~~~~
sprinkler.cpp:68:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |             for(int i = 1; i < vec.size(); i++){
      |                            ~~^~~~~~~~~~~~
sprinkler.cpp:92:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |             for(int i = 0; i < vec.size(); i++){
      |                            ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 4 ms 5716 KB Output is correct
4 Correct 4 ms 6216 KB Output is correct
5 Correct 5 ms 6216 KB Output is correct
6 Correct 4 ms 6100 KB Output is correct
7 Correct 4 ms 6220 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 3 ms 5716 KB Output is correct
10 Correct 3 ms 5844 KB Output is correct
11 Correct 4 ms 5716 KB Output is correct
12 Correct 4 ms 5716 KB Output is correct
13 Correct 3 ms 5716 KB Output is correct
14 Correct 3 ms 5828 KB Output is correct
15 Correct 3 ms 5716 KB Output is correct
16 Correct 3 ms 5828 KB Output is correct
17 Correct 4 ms 5828 KB Output is correct
18 Correct 4 ms 5844 KB Output is correct
19 Correct 4 ms 5716 KB Output is correct
20 Correct 4 ms 5716 KB Output is correct
21 Correct 4 ms 5824 KB Output is correct
22 Correct 3 ms 5716 KB Output is correct
23 Correct 4 ms 5716 KB Output is correct
24 Correct 4 ms 5820 KB Output is correct
25 Correct 3 ms 5716 KB Output is correct
26 Correct 4 ms 5716 KB Output is correct
27 Correct 3 ms 5716 KB Output is correct
28 Correct 4 ms 5716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 709 ms 89784 KB Output is correct
3 Correct 428 ms 90224 KB Output is correct
4 Correct 576 ms 95800 KB Output is correct
5 Correct 595 ms 89928 KB Output is correct
6 Correct 421 ms 89420 KB Output is correct
7 Correct 395 ms 90164 KB Output is correct
8 Correct 305 ms 90704 KB Output is correct
9 Correct 749 ms 98460 KB Output is correct
10 Correct 478 ms 98336 KB Output is correct
11 Correct 811 ms 89620 KB Output is correct
12 Correct 402 ms 90164 KB Output is correct
13 Correct 281 ms 90428 KB Output is correct
14 Correct 259 ms 90976 KB Output is correct
15 Correct 286 ms 90316 KB Output is correct
16 Correct 303 ms 90836 KB Output is correct
17 Correct 312 ms 91332 KB Output is correct
18 Correct 3 ms 5828 KB Output is correct
19 Correct 3 ms 5716 KB Output is correct
20 Correct 3 ms 5844 KB Output is correct
21 Correct 4 ms 5716 KB Output is correct
22 Correct 3 ms 5844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 709 ms 89784 KB Output is correct
3 Correct 428 ms 90224 KB Output is correct
4 Correct 576 ms 95800 KB Output is correct
5 Correct 595 ms 89928 KB Output is correct
6 Correct 421 ms 89420 KB Output is correct
7 Correct 395 ms 90164 KB Output is correct
8 Correct 305 ms 90704 KB Output is correct
9 Correct 749 ms 98460 KB Output is correct
10 Correct 478 ms 98336 KB Output is correct
11 Correct 811 ms 89620 KB Output is correct
12 Correct 402 ms 90164 KB Output is correct
13 Correct 281 ms 90428 KB Output is correct
14 Correct 259 ms 90976 KB Output is correct
15 Correct 286 ms 90316 KB Output is correct
16 Correct 303 ms 90836 KB Output is correct
17 Correct 312 ms 91332 KB Output is correct
18 Correct 3 ms 5828 KB Output is correct
19 Correct 3 ms 5716 KB Output is correct
20 Correct 3 ms 5844 KB Output is correct
21 Correct 4 ms 5716 KB Output is correct
22 Correct 3 ms 5844 KB Output is correct
23 Correct 3 ms 5716 KB Output is correct
24 Correct 694 ms 89732 KB Output is correct
25 Correct 424 ms 90184 KB Output is correct
26 Correct 582 ms 98552 KB Output is correct
27 Correct 555 ms 89968 KB Output is correct
28 Correct 503 ms 90000 KB Output is correct
29 Correct 357 ms 89804 KB Output is correct
30 Correct 321 ms 90840 KB Output is correct
31 Correct 712 ms 95948 KB Output is correct
32 Correct 463 ms 98436 KB Output is correct
33 Correct 709 ms 89744 KB Output is correct
34 Correct 408 ms 90252 KB Output is correct
35 Correct 4 ms 5716 KB Output is correct
36 Correct 5 ms 5844 KB Output is correct
37 Correct 3 ms 5716 KB Output is correct
38 Correct 3 ms 5844 KB Output is correct
39 Correct 3 ms 5844 KB Output is correct
40 Correct 3 ms 5824 KB Output is correct
41 Correct 3 ms 5716 KB Output is correct
42 Correct 5 ms 5716 KB Output is correct
43 Correct 3 ms 5716 KB Output is correct
44 Correct 3 ms 5716 KB Output is correct
45 Correct 3 ms 5716 KB Output is correct
46 Correct 3 ms 5820 KB Output is correct
47 Correct 3 ms 5844 KB Output is correct
48 Correct 4 ms 5828 KB Output is correct
49 Correct 3 ms 5716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 774 ms 95512 KB Output is correct
3 Correct 1049 ms 94128 KB Output is correct
4 Correct 726 ms 94084 KB Output is correct
5 Correct 742 ms 86944 KB Output is correct
6 Correct 439 ms 87148 KB Output is correct
7 Correct 456 ms 87172 KB Output is correct
8 Correct 302 ms 87760 KB Output is correct
9 Correct 804 ms 93036 KB Output is correct
10 Correct 928 ms 95396 KB Output is correct
11 Correct 756 ms 86576 KB Output is correct
12 Correct 786 ms 87472 KB Output is correct
13 Correct 634 ms 88320 KB Output is correct
14 Correct 593 ms 88952 KB Output is correct
15 Correct 3 ms 5716 KB Output is correct
16 Correct 3 ms 5716 KB Output is correct
17 Correct 3 ms 5828 KB Output is correct
18 Correct 3 ms 5716 KB Output is correct
19 Correct 5 ms 5828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 822 ms 95224 KB Output is correct
3 Correct 925 ms 92388 KB Output is correct
4 Correct 730 ms 93824 KB Output is correct
5 Correct 702 ms 88600 KB Output is correct
6 Correct 447 ms 88904 KB Output is correct
7 Correct 422 ms 88388 KB Output is correct
8 Correct 298 ms 88708 KB Output is correct
9 Correct 813 ms 97692 KB Output is correct
10 Correct 1014 ms 96308 KB Output is correct
11 Correct 753 ms 89312 KB Output is correct
12 Correct 850 ms 87792 KB Output is correct
13 Correct 629 ms 88504 KB Output is correct
14 Correct 617 ms 89028 KB Output is correct
15 Correct 3 ms 5716 KB Output is correct
16 Correct 3 ms 5812 KB Output is correct
17 Correct 3 ms 5716 KB Output is correct
18 Correct 3 ms 5828 KB Output is correct
19 Correct 3 ms 5716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 4 ms 5716 KB Output is correct
4 Correct 4 ms 6216 KB Output is correct
5 Correct 5 ms 6216 KB Output is correct
6 Correct 4 ms 6100 KB Output is correct
7 Correct 4 ms 6220 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 3 ms 5716 KB Output is correct
10 Correct 3 ms 5844 KB Output is correct
11 Correct 4 ms 5716 KB Output is correct
12 Correct 4 ms 5716 KB Output is correct
13 Correct 3 ms 5716 KB Output is correct
14 Correct 3 ms 5828 KB Output is correct
15 Correct 3 ms 5716 KB Output is correct
16 Correct 3 ms 5828 KB Output is correct
17 Correct 4 ms 5828 KB Output is correct
18 Correct 4 ms 5844 KB Output is correct
19 Correct 4 ms 5716 KB Output is correct
20 Correct 4 ms 5716 KB Output is correct
21 Correct 4 ms 5824 KB Output is correct
22 Correct 3 ms 5716 KB Output is correct
23 Correct 4 ms 5716 KB Output is correct
24 Correct 4 ms 5820 KB Output is correct
25 Correct 3 ms 5716 KB Output is correct
26 Correct 4 ms 5716 KB Output is correct
27 Correct 3 ms 5716 KB Output is correct
28 Correct 4 ms 5716 KB Output is correct
29 Correct 3 ms 5716 KB Output is correct
30 Correct 709 ms 89784 KB Output is correct
31 Correct 428 ms 90224 KB Output is correct
32 Correct 576 ms 95800 KB Output is correct
33 Correct 595 ms 89928 KB Output is correct
34 Correct 421 ms 89420 KB Output is correct
35 Correct 395 ms 90164 KB Output is correct
36 Correct 305 ms 90704 KB Output is correct
37 Correct 749 ms 98460 KB Output is correct
38 Correct 478 ms 98336 KB Output is correct
39 Correct 811 ms 89620 KB Output is correct
40 Correct 402 ms 90164 KB Output is correct
41 Correct 281 ms 90428 KB Output is correct
42 Correct 259 ms 90976 KB Output is correct
43 Correct 286 ms 90316 KB Output is correct
44 Correct 303 ms 90836 KB Output is correct
45 Correct 312 ms 91332 KB Output is correct
46 Correct 3 ms 5828 KB Output is correct
47 Correct 3 ms 5716 KB Output is correct
48 Correct 3 ms 5844 KB Output is correct
49 Correct 4 ms 5716 KB Output is correct
50 Correct 3 ms 5844 KB Output is correct
51 Correct 3 ms 5716 KB Output is correct
52 Correct 694 ms 89732 KB Output is correct
53 Correct 424 ms 90184 KB Output is correct
54 Correct 582 ms 98552 KB Output is correct
55 Correct 555 ms 89968 KB Output is correct
56 Correct 503 ms 90000 KB Output is correct
57 Correct 357 ms 89804 KB Output is correct
58 Correct 321 ms 90840 KB Output is correct
59 Correct 712 ms 95948 KB Output is correct
60 Correct 463 ms 98436 KB Output is correct
61 Correct 709 ms 89744 KB Output is correct
62 Correct 408 ms 90252 KB Output is correct
63 Correct 4 ms 5716 KB Output is correct
64 Correct 5 ms 5844 KB Output is correct
65 Correct 3 ms 5716 KB Output is correct
66 Correct 3 ms 5844 KB Output is correct
67 Correct 3 ms 5844 KB Output is correct
68 Correct 3 ms 5824 KB Output is correct
69 Correct 3 ms 5716 KB Output is correct
70 Correct 5 ms 5716 KB Output is correct
71 Correct 3 ms 5716 KB Output is correct
72 Correct 3 ms 5716 KB Output is correct
73 Correct 3 ms 5716 KB Output is correct
74 Correct 3 ms 5820 KB Output is correct
75 Correct 3 ms 5844 KB Output is correct
76 Correct 4 ms 5828 KB Output is correct
77 Correct 3 ms 5716 KB Output is correct
78 Correct 3 ms 5716 KB Output is correct
79 Correct 774 ms 95512 KB Output is correct
80 Correct 1049 ms 94128 KB Output is correct
81 Correct 726 ms 94084 KB Output is correct
82 Correct 742 ms 86944 KB Output is correct
83 Correct 439 ms 87148 KB Output is correct
84 Correct 456 ms 87172 KB Output is correct
85 Correct 302 ms 87760 KB Output is correct
86 Correct 804 ms 93036 KB Output is correct
87 Correct 928 ms 95396 KB Output is correct
88 Correct 756 ms 86576 KB Output is correct
89 Correct 786 ms 87472 KB Output is correct
90 Correct 634 ms 88320 KB Output is correct
91 Correct 593 ms 88952 KB Output is correct
92 Correct 3 ms 5716 KB Output is correct
93 Correct 3 ms 5716 KB Output is correct
94 Correct 3 ms 5828 KB Output is correct
95 Correct 3 ms 5716 KB Output is correct
96 Correct 5 ms 5828 KB Output is correct
97 Correct 3 ms 5716 KB Output is correct
98 Correct 822 ms 95224 KB Output is correct
99 Correct 925 ms 92388 KB Output is correct
100 Correct 730 ms 93824 KB Output is correct
101 Correct 702 ms 88600 KB Output is correct
102 Correct 447 ms 88904 KB Output is correct
103 Correct 422 ms 88388 KB Output is correct
104 Correct 298 ms 88708 KB Output is correct
105 Correct 813 ms 97692 KB Output is correct
106 Correct 1014 ms 96308 KB Output is correct
107 Correct 753 ms 89312 KB Output is correct
108 Correct 850 ms 87792 KB Output is correct
109 Correct 629 ms 88504 KB Output is correct
110 Correct 617 ms 89028 KB Output is correct
111 Correct 3 ms 5716 KB Output is correct
112 Correct 3 ms 5812 KB Output is correct
113 Correct 3 ms 5716 KB Output is correct
114 Correct 3 ms 5828 KB Output is correct
115 Correct 3 ms 5716 KB Output is correct
116 Correct 743 ms 87708 KB Output is correct
117 Correct 865 ms 90364 KB Output is correct
118 Correct 726 ms 98484 KB Output is correct
119 Correct 697 ms 90060 KB Output is correct
120 Correct 487 ms 89600 KB Output is correct
121 Correct 479 ms 90324 KB Output is correct
122 Correct 321 ms 90696 KB Output is correct
123 Correct 861 ms 97004 KB Output is correct
124 Correct 981 ms 95628 KB Output is correct
125 Correct 768 ms 88928 KB Output is correct
126 Correct 881 ms 90140 KB Output is correct
127 Correct 913 ms 90752 KB Output is correct
128 Correct 755 ms 91408 KB Output is correct
129 Correct 742 ms 91840 KB Output is correct