Submission #545675

# Submission time Handle Problem Language Result Execution time Memory
545675 2022-04-05T07:07:25 Z leaked Sprinkler (JOI22_sprinkler) C++14
100 / 100
674 ms 53924 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pb push_back
#define sz(x) (int)(x).size()
#define pw(x) (1LL<<(x))
#define fast_prep ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef pair<int,ll> pil;
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
int M;
const int N=2e5+41;
int par[N];
int mt[N][42];
vec<int> g[N];
int a[N];
int mult(int a,int b){
    return 1ll*a*b%M;
}
void dfs(int v,int p){
    for(auto &z : g[v]){
        if(z==p) continue;
        par[z]=v;
        dfs(z,v);
    }
}
signed main(){
    fast_prep;
    int n;
    cin>>n>>M;
    for(int i=1;i<n;i++){
        int v,u;
        cin>>v>>u;--v;--u;
        g[v].pb(u);g[u].pb(v);
    }
    g[n].pb(0);g[0].pb(n);
    for(int i=n+1;i<n+40;i++){
        g[i].pb(i-1);g[i-1].pb(i);
    }
    n+=40;
    dfs(n-1,n-1);
    for(int i=0;i<n;i++)
        fill(mt[i],mt[i]+42,1);
    for(int i=0;i<n-40;i++) cin>>a[i];
    int q;
    cin>>q;
    while(q--){
        int type;
        cin>>type;
        if(type==1){
            int v,d,w;
            cin>>v>>d>>w;--v;
            while(d>=0){

//                cout<<"UPD "<<v<<' '<<d<<' '<<w<<endl;
//                cout<<"HEY "<<mt[v][d]<<' '<<mult(mt[v][d],w)<<endl;
                mt[v][d]=mult(mt[v][d],w);

                --d;v=par[v];
            }
        }
        else{
            int v;
            cin>>v;--v;
            int ans=a[v];
            for(int i=0;i<=40;i++){
                ans=mult(ans,mt[v][i]);
                ans=mult(ans,mt[v][i+1]);
                v=par[v];
            }
            cout<<ans<<'\n';
        }
    }
    return 0;
}
/*

*/
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 4 ms 5260 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 4 ms 5204 KB Output is correct
7 Correct 4 ms 5204 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 573 ms 49352 KB Output is correct
3 Correct 399 ms 46184 KB Output is correct
4 Correct 516 ms 50716 KB Output is correct
5 Correct 437 ms 47776 KB Output is correct
6 Correct 411 ms 47664 KB Output is correct
7 Correct 406 ms 48072 KB Output is correct
8 Correct 342 ms 48444 KB Output is correct
9 Correct 633 ms 53924 KB Output is correct
10 Correct 368 ms 50432 KB Output is correct
11 Correct 582 ms 49428 KB Output is correct
12 Correct 345 ms 46284 KB Output is correct
13 Correct 267 ms 46804 KB Output is correct
14 Correct 256 ms 46820 KB Output is correct
15 Correct 309 ms 46820 KB Output is correct
16 Correct 261 ms 46732 KB Output is correct
17 Correct 262 ms 47224 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 573 ms 49352 KB Output is correct
3 Correct 399 ms 46184 KB Output is correct
4 Correct 516 ms 50716 KB Output is correct
5 Correct 437 ms 47776 KB Output is correct
6 Correct 411 ms 47664 KB Output is correct
7 Correct 406 ms 48072 KB Output is correct
8 Correct 342 ms 48444 KB Output is correct
9 Correct 633 ms 53924 KB Output is correct
10 Correct 368 ms 50432 KB Output is correct
11 Correct 582 ms 49428 KB Output is correct
12 Correct 345 ms 46284 KB Output is correct
13 Correct 267 ms 46804 KB Output is correct
14 Correct 256 ms 46820 KB Output is correct
15 Correct 309 ms 46820 KB Output is correct
16 Correct 261 ms 46732 KB Output is correct
17 Correct 262 ms 47224 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 2 ms 4948 KB Output is correct
24 Correct 582 ms 49368 KB Output is correct
25 Correct 343 ms 46120 KB Output is correct
26 Correct 524 ms 52180 KB Output is correct
27 Correct 452 ms 47724 KB Output is correct
28 Correct 389 ms 48004 KB Output is correct
29 Correct 389 ms 47772 KB Output is correct
30 Correct 352 ms 48476 KB Output is correct
31 Correct 639 ms 52492 KB Output is correct
32 Correct 354 ms 50520 KB Output is correct
33 Correct 540 ms 49364 KB Output is correct
34 Correct 389 ms 46092 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 4 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 5 ms 4948 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 4 ms 4948 KB Output is correct
43 Correct 3 ms 4996 KB Output is correct
44 Correct 4 ms 4948 KB Output is correct
45 Correct 4 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 673 ms 51320 KB Output is correct
3 Correct 669 ms 49328 KB Output is correct
4 Correct 519 ms 49804 KB Output is correct
5 Correct 525 ms 46156 KB Output is correct
6 Correct 369 ms 46328 KB Output is correct
7 Correct 411 ms 46472 KB Output is correct
8 Correct 328 ms 46848 KB Output is correct
9 Correct 618 ms 49884 KB Output is correct
10 Correct 589 ms 50000 KB Output is correct
11 Correct 517 ms 46544 KB Output is correct
12 Correct 531 ms 45920 KB Output is correct
13 Correct 385 ms 46768 KB Output is correct
14 Correct 358 ms 47232 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 626 ms 52264 KB Output is correct
3 Correct 574 ms 48716 KB Output is correct
4 Correct 576 ms 50380 KB Output is correct
5 Correct 447 ms 47672 KB Output is correct
6 Correct 448 ms 47976 KB Output is correct
7 Correct 418 ms 47852 KB Output is correct
8 Correct 343 ms 48192 KB Output is correct
9 Correct 664 ms 53788 KB Output is correct
10 Correct 603 ms 50416 KB Output is correct
11 Correct 553 ms 49176 KB Output is correct
12 Correct 498 ms 46164 KB Output is correct
13 Correct 378 ms 46964 KB Output is correct
14 Correct 369 ms 47332 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 4 ms 5260 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 4 ms 5204 KB Output is correct
7 Correct 4 ms 5204 KB Output is correct
8 Correct 4 ms 5204 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 4 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 2 ms 4948 KB Output is correct
30 Correct 573 ms 49352 KB Output is correct
31 Correct 399 ms 46184 KB Output is correct
32 Correct 516 ms 50716 KB Output is correct
33 Correct 437 ms 47776 KB Output is correct
34 Correct 411 ms 47664 KB Output is correct
35 Correct 406 ms 48072 KB Output is correct
36 Correct 342 ms 48444 KB Output is correct
37 Correct 633 ms 53924 KB Output is correct
38 Correct 368 ms 50432 KB Output is correct
39 Correct 582 ms 49428 KB Output is correct
40 Correct 345 ms 46284 KB Output is correct
41 Correct 267 ms 46804 KB Output is correct
42 Correct 256 ms 46820 KB Output is correct
43 Correct 309 ms 46820 KB Output is correct
44 Correct 261 ms 46732 KB Output is correct
45 Correct 262 ms 47224 KB Output is correct
46 Correct 4 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 4 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 2 ms 4948 KB Output is correct
52 Correct 582 ms 49368 KB Output is correct
53 Correct 343 ms 46120 KB Output is correct
54 Correct 524 ms 52180 KB Output is correct
55 Correct 452 ms 47724 KB Output is correct
56 Correct 389 ms 48004 KB Output is correct
57 Correct 389 ms 47772 KB Output is correct
58 Correct 352 ms 48476 KB Output is correct
59 Correct 639 ms 52492 KB Output is correct
60 Correct 354 ms 50520 KB Output is correct
61 Correct 540 ms 49364 KB Output is correct
62 Correct 389 ms 46092 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 4 ms 4948 KB Output is correct
66 Correct 3 ms 4948 KB Output is correct
67 Correct 3 ms 4948 KB Output is correct
68 Correct 5 ms 4948 KB Output is correct
69 Correct 3 ms 4948 KB Output is correct
70 Correct 4 ms 4948 KB Output is correct
71 Correct 3 ms 4996 KB Output is correct
72 Correct 4 ms 4948 KB Output is correct
73 Correct 4 ms 4948 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 3 ms 4948 KB Output is correct
77 Correct 3 ms 4948 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 673 ms 51320 KB Output is correct
80 Correct 669 ms 49328 KB Output is correct
81 Correct 519 ms 49804 KB Output is correct
82 Correct 525 ms 46156 KB Output is correct
83 Correct 369 ms 46328 KB Output is correct
84 Correct 411 ms 46472 KB Output is correct
85 Correct 328 ms 46848 KB Output is correct
86 Correct 618 ms 49884 KB Output is correct
87 Correct 589 ms 50000 KB Output is correct
88 Correct 517 ms 46544 KB Output is correct
89 Correct 531 ms 45920 KB Output is correct
90 Correct 385 ms 46768 KB Output is correct
91 Correct 358 ms 47232 KB Output is correct
92 Correct 3 ms 4948 KB Output is correct
93 Correct 3 ms 4948 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 4948 KB Output is correct
96 Correct 3 ms 5048 KB Output is correct
97 Correct 2 ms 4948 KB Output is correct
98 Correct 626 ms 52264 KB Output is correct
99 Correct 574 ms 48716 KB Output is correct
100 Correct 576 ms 50380 KB Output is correct
101 Correct 447 ms 47672 KB Output is correct
102 Correct 448 ms 47976 KB Output is correct
103 Correct 418 ms 47852 KB Output is correct
104 Correct 343 ms 48192 KB Output is correct
105 Correct 664 ms 53788 KB Output is correct
106 Correct 603 ms 50416 KB Output is correct
107 Correct 553 ms 49176 KB Output is correct
108 Correct 498 ms 46164 KB Output is correct
109 Correct 378 ms 46964 KB Output is correct
110 Correct 369 ms 47332 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 4 ms 4948 KB Output is correct
113 Correct 3 ms 4948 KB Output is correct
114 Correct 3 ms 4948 KB Output is correct
115 Correct 3 ms 4948 KB Output is correct
116 Correct 561 ms 47292 KB Output is correct
117 Correct 514 ms 45868 KB Output is correct
118 Correct 563 ms 52044 KB Output is correct
119 Correct 509 ms 47660 KB Output is correct
120 Correct 443 ms 47720 KB Output is correct
121 Correct 470 ms 48092 KB Output is correct
122 Correct 396 ms 48404 KB Output is correct
123 Correct 674 ms 53008 KB Output is correct
124 Correct 613 ms 49160 KB Output is correct
125 Correct 551 ms 48764 KB Output is correct
126 Correct 563 ms 45928 KB Output is correct
127 Correct 529 ms 46012 KB Output is correct
128 Correct 388 ms 46908 KB Output is correct
129 Correct 411 ms 47220 KB Output is correct