Submission #556021

# Submission time Handle Problem Language Result Execution time Memory
556021 2022-05-02T07:50:10 Z 600Mihnea Sprinkler (JOI22_sprinkler) C++17
100 / 100
2375 ms 62572 KB
#include <bits/stdc++.h>

bool home = 1;

using namespace std;

typedef long long ll;
const int N=200000+7;
const int K=20;
int n;
int q;
int mod;
int h[N];
vector<int> g[N];
int par[N];
int dep[N];

void build(int a,int p=-1){
  par[a]=p;
  for(auto&b:g[a]){
    if(b==p) continue;
    dep[b]=1+dep[a];
    build(b,a);
  }

}


const int MX=40;

int mlt[N][MX+1];

void mulup(int &a,int b){
  a=a*(ll)b%mod;
}

signed main() {
#ifdef ONLINE_JUDGE
  home = 0;
#endif

  for(int i=0;i<N;i++){
    for(int j=0;j<=MX;j++){
      mlt[i][j]=1;
    }
  }

  home=0;

  if (home) {
    freopen("I_am_iron_man", "r", stdin);
  }
  else {
    ios::sync_with_stdio(0); cin.tie(0);
  }

  cin>>n>>mod;

  for (int i=1;i<n;i++) {
    int a, b;
    cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  build(1);

  for (int i=1;i<=n;i++) {
    cin>>h[i];
  }
  cin>>q;
  while(q--){
    int type;
    cin>>type;
    if(type==1){
      int x,d,w;
      cin>>x>>d>>w;

      vector<pair<int, int>> prs;

      int vertex=x;

      while (vertex>=1&&d>=0) {
        prs.push_back({vertex, d});
        vertex=par[vertex];
        d--;
      }

      reverse(prs.begin(),prs.end());

      int maxdep=-1;

      for (auto &it:prs){
        vertex=it.first;
        d=it.second;
        for(int h=dep[vertex];h<=dep[vertex]+d;h++){
          if(h>maxdep){
            maxdep=h;
            mulup(mlt[vertex][h-dep[vertex]],w);
          }
        }
      }

    }else{
      int x,xinit;
      cin>>x;
      int sol=h[x];
      int cur_dist=0;
      while (x>=1&&cur_dist<=MX){
        sol=sol*(ll)mlt[x][cur_dist]%mod;
        x=par[x];
        cur_dist++;
      }

      cout<<sol<<"\n";
    }
  }


}

Compilation message

sprinkler.cpp: In function 'int main()':
sprinkler.cpp:105:13: warning: unused variable 'xinit' [-Wunused-variable]
  105 |       int x,xinit;
      |             ^~~~~
sprinkler.cpp:51:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     freopen("I_am_iron_man", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37076 KB Output is correct
2 Correct 20 ms 37020 KB Output is correct
3 Correct 20 ms 37108 KB Output is correct
4 Correct 21 ms 37172 KB Output is correct
5 Correct 21 ms 37092 KB Output is correct
6 Correct 21 ms 37204 KB Output is correct
7 Correct 21 ms 37144 KB Output is correct
8 Correct 20 ms 37092 KB Output is correct
9 Correct 22 ms 37136 KB Output is correct
10 Correct 19 ms 37040 KB Output is correct
11 Correct 24 ms 37076 KB Output is correct
12 Correct 21 ms 37032 KB Output is correct
13 Correct 21 ms 37092 KB Output is correct
14 Correct 21 ms 37132 KB Output is correct
15 Correct 20 ms 37076 KB Output is correct
16 Correct 21 ms 37040 KB Output is correct
17 Correct 20 ms 37132 KB Output is correct
18 Correct 21 ms 37112 KB Output is correct
19 Correct 20 ms 37076 KB Output is correct
20 Correct 21 ms 37100 KB Output is correct
21 Correct 20 ms 37076 KB Output is correct
22 Correct 20 ms 37124 KB Output is correct
23 Correct 20 ms 37112 KB Output is correct
24 Correct 21 ms 37064 KB Output is correct
25 Correct 22 ms 37076 KB Output is correct
26 Correct 20 ms 37084 KB Output is correct
27 Correct 21 ms 37076 KB Output is correct
28 Correct 20 ms 37048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37076 KB Output is correct
2 Correct 617 ms 52196 KB Output is correct
3 Correct 399 ms 47524 KB Output is correct
4 Correct 473 ms 56936 KB Output is correct
5 Correct 461 ms 49144 KB Output is correct
6 Correct 341 ms 48880 KB Output is correct
7 Correct 366 ms 49424 KB Output is correct
8 Correct 267 ms 49800 KB Output is correct
9 Correct 634 ms 62572 KB Output is correct
10 Correct 419 ms 58596 KB Output is correct
11 Correct 540 ms 50708 KB Output is correct
12 Correct 381 ms 47500 KB Output is correct
13 Correct 272 ms 48152 KB Output is correct
14 Correct 278 ms 48068 KB Output is correct
15 Correct 275 ms 48020 KB Output is correct
16 Correct 260 ms 47968 KB Output is correct
17 Correct 280 ms 48464 KB Output is correct
18 Correct 20 ms 37036 KB Output is correct
19 Correct 24 ms 37060 KB Output is correct
20 Correct 21 ms 37064 KB Output is correct
21 Correct 21 ms 37080 KB Output is correct
22 Correct 22 ms 37120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37076 KB Output is correct
2 Correct 617 ms 52196 KB Output is correct
3 Correct 399 ms 47524 KB Output is correct
4 Correct 473 ms 56936 KB Output is correct
5 Correct 461 ms 49144 KB Output is correct
6 Correct 341 ms 48880 KB Output is correct
7 Correct 366 ms 49424 KB Output is correct
8 Correct 267 ms 49800 KB Output is correct
9 Correct 634 ms 62572 KB Output is correct
10 Correct 419 ms 58596 KB Output is correct
11 Correct 540 ms 50708 KB Output is correct
12 Correct 381 ms 47500 KB Output is correct
13 Correct 272 ms 48152 KB Output is correct
14 Correct 278 ms 48068 KB Output is correct
15 Correct 275 ms 48020 KB Output is correct
16 Correct 260 ms 47968 KB Output is correct
17 Correct 280 ms 48464 KB Output is correct
18 Correct 20 ms 37036 KB Output is correct
19 Correct 24 ms 37060 KB Output is correct
20 Correct 21 ms 37064 KB Output is correct
21 Correct 21 ms 37080 KB Output is correct
22 Correct 22 ms 37120 KB Output is correct
23 Correct 22 ms 37076 KB Output is correct
24 Correct 563 ms 50560 KB Output is correct
25 Correct 422 ms 47420 KB Output is correct
26 Correct 545 ms 60480 KB Output is correct
27 Correct 542 ms 49040 KB Output is correct
28 Correct 341 ms 49100 KB Output is correct
29 Correct 379 ms 49112 KB Output is correct
30 Correct 276 ms 49584 KB Output is correct
31 Correct 562 ms 58848 KB Output is correct
32 Correct 447 ms 58440 KB Output is correct
33 Correct 521 ms 50492 KB Output is correct
34 Correct 386 ms 47168 KB Output is correct
35 Correct 20 ms 37120 KB Output is correct
36 Correct 20 ms 37048 KB Output is correct
37 Correct 21 ms 37008 KB Output is correct
38 Correct 24 ms 37108 KB Output is correct
39 Correct 20 ms 37112 KB Output is correct
40 Correct 22 ms 37044 KB Output is correct
41 Correct 22 ms 37072 KB Output is correct
42 Correct 21 ms 37108 KB Output is correct
43 Correct 21 ms 37096 KB Output is correct
44 Correct 20 ms 37104 KB Output is correct
45 Correct 21 ms 37044 KB Output is correct
46 Correct 20 ms 37100 KB Output is correct
47 Correct 20 ms 37044 KB Output is correct
48 Correct 22 ms 37096 KB Output is correct
49 Correct 21 ms 37052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 37028 KB Output is correct
2 Correct 810 ms 59912 KB Output is correct
3 Correct 2187 ms 56272 KB Output is correct
4 Correct 885 ms 57088 KB Output is correct
5 Correct 821 ms 47444 KB Output is correct
6 Correct 506 ms 47760 KB Output is correct
7 Correct 477 ms 47760 KB Output is correct
8 Correct 303 ms 48248 KB Output is correct
9 Correct 781 ms 56484 KB Output is correct
10 Correct 2202 ms 58140 KB Output is correct
11 Correct 669 ms 47756 KB Output is correct
12 Correct 1601 ms 47392 KB Output is correct
13 Correct 951 ms 48184 KB Output is correct
14 Correct 1085 ms 48492 KB Output is correct
15 Correct 21 ms 37068 KB Output is correct
16 Correct 21 ms 37072 KB Output is correct
17 Correct 21 ms 37012 KB Output is correct
18 Correct 22 ms 37040 KB Output is correct
19 Correct 21 ms 37076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 37076 KB Output is correct
2 Correct 836 ms 59336 KB Output is correct
3 Correct 2178 ms 53392 KB Output is correct
4 Correct 935 ms 55880 KB Output is correct
5 Correct 870 ms 48740 KB Output is correct
6 Correct 526 ms 48780 KB Output is correct
7 Correct 474 ms 48736 KB Output is correct
8 Correct 299 ms 49012 KB Output is correct
9 Correct 796 ms 61252 KB Output is correct
10 Correct 2221 ms 58292 KB Output is correct
11 Correct 763 ms 49972 KB Output is correct
12 Correct 1656 ms 46964 KB Output is correct
13 Correct 1016 ms 47680 KB Output is correct
14 Correct 1084 ms 48028 KB Output is correct
15 Correct 22 ms 37076 KB Output is correct
16 Correct 25 ms 37128 KB Output is correct
17 Correct 21 ms 37076 KB Output is correct
18 Correct 21 ms 37056 KB Output is correct
19 Correct 21 ms 37044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 37076 KB Output is correct
2 Correct 20 ms 37020 KB Output is correct
3 Correct 20 ms 37108 KB Output is correct
4 Correct 21 ms 37172 KB Output is correct
5 Correct 21 ms 37092 KB Output is correct
6 Correct 21 ms 37204 KB Output is correct
7 Correct 21 ms 37144 KB Output is correct
8 Correct 20 ms 37092 KB Output is correct
9 Correct 22 ms 37136 KB Output is correct
10 Correct 19 ms 37040 KB Output is correct
11 Correct 24 ms 37076 KB Output is correct
12 Correct 21 ms 37032 KB Output is correct
13 Correct 21 ms 37092 KB Output is correct
14 Correct 21 ms 37132 KB Output is correct
15 Correct 20 ms 37076 KB Output is correct
16 Correct 21 ms 37040 KB Output is correct
17 Correct 20 ms 37132 KB Output is correct
18 Correct 21 ms 37112 KB Output is correct
19 Correct 20 ms 37076 KB Output is correct
20 Correct 21 ms 37100 KB Output is correct
21 Correct 20 ms 37076 KB Output is correct
22 Correct 20 ms 37124 KB Output is correct
23 Correct 20 ms 37112 KB Output is correct
24 Correct 21 ms 37064 KB Output is correct
25 Correct 22 ms 37076 KB Output is correct
26 Correct 20 ms 37084 KB Output is correct
27 Correct 21 ms 37076 KB Output is correct
28 Correct 20 ms 37048 KB Output is correct
29 Correct 19 ms 37076 KB Output is correct
30 Correct 617 ms 52196 KB Output is correct
31 Correct 399 ms 47524 KB Output is correct
32 Correct 473 ms 56936 KB Output is correct
33 Correct 461 ms 49144 KB Output is correct
34 Correct 341 ms 48880 KB Output is correct
35 Correct 366 ms 49424 KB Output is correct
36 Correct 267 ms 49800 KB Output is correct
37 Correct 634 ms 62572 KB Output is correct
38 Correct 419 ms 58596 KB Output is correct
39 Correct 540 ms 50708 KB Output is correct
40 Correct 381 ms 47500 KB Output is correct
41 Correct 272 ms 48152 KB Output is correct
42 Correct 278 ms 48068 KB Output is correct
43 Correct 275 ms 48020 KB Output is correct
44 Correct 260 ms 47968 KB Output is correct
45 Correct 280 ms 48464 KB Output is correct
46 Correct 20 ms 37036 KB Output is correct
47 Correct 24 ms 37060 KB Output is correct
48 Correct 21 ms 37064 KB Output is correct
49 Correct 21 ms 37080 KB Output is correct
50 Correct 22 ms 37120 KB Output is correct
51 Correct 22 ms 37076 KB Output is correct
52 Correct 563 ms 50560 KB Output is correct
53 Correct 422 ms 47420 KB Output is correct
54 Correct 545 ms 60480 KB Output is correct
55 Correct 542 ms 49040 KB Output is correct
56 Correct 341 ms 49100 KB Output is correct
57 Correct 379 ms 49112 KB Output is correct
58 Correct 276 ms 49584 KB Output is correct
59 Correct 562 ms 58848 KB Output is correct
60 Correct 447 ms 58440 KB Output is correct
61 Correct 521 ms 50492 KB Output is correct
62 Correct 386 ms 47168 KB Output is correct
63 Correct 20 ms 37120 KB Output is correct
64 Correct 20 ms 37048 KB Output is correct
65 Correct 21 ms 37008 KB Output is correct
66 Correct 24 ms 37108 KB Output is correct
67 Correct 20 ms 37112 KB Output is correct
68 Correct 22 ms 37044 KB Output is correct
69 Correct 22 ms 37072 KB Output is correct
70 Correct 21 ms 37108 KB Output is correct
71 Correct 21 ms 37096 KB Output is correct
72 Correct 20 ms 37104 KB Output is correct
73 Correct 21 ms 37044 KB Output is correct
74 Correct 20 ms 37100 KB Output is correct
75 Correct 20 ms 37044 KB Output is correct
76 Correct 22 ms 37096 KB Output is correct
77 Correct 21 ms 37052 KB Output is correct
78 Correct 20 ms 37028 KB Output is correct
79 Correct 810 ms 59912 KB Output is correct
80 Correct 2187 ms 56272 KB Output is correct
81 Correct 885 ms 57088 KB Output is correct
82 Correct 821 ms 47444 KB Output is correct
83 Correct 506 ms 47760 KB Output is correct
84 Correct 477 ms 47760 KB Output is correct
85 Correct 303 ms 48248 KB Output is correct
86 Correct 781 ms 56484 KB Output is correct
87 Correct 2202 ms 58140 KB Output is correct
88 Correct 669 ms 47756 KB Output is correct
89 Correct 1601 ms 47392 KB Output is correct
90 Correct 951 ms 48184 KB Output is correct
91 Correct 1085 ms 48492 KB Output is correct
92 Correct 21 ms 37068 KB Output is correct
93 Correct 21 ms 37072 KB Output is correct
94 Correct 21 ms 37012 KB Output is correct
95 Correct 22 ms 37040 KB Output is correct
96 Correct 21 ms 37076 KB Output is correct
97 Correct 21 ms 37076 KB Output is correct
98 Correct 836 ms 59336 KB Output is correct
99 Correct 2178 ms 53392 KB Output is correct
100 Correct 935 ms 55880 KB Output is correct
101 Correct 870 ms 48740 KB Output is correct
102 Correct 526 ms 48780 KB Output is correct
103 Correct 474 ms 48736 KB Output is correct
104 Correct 299 ms 49012 KB Output is correct
105 Correct 796 ms 61252 KB Output is correct
106 Correct 2221 ms 58292 KB Output is correct
107 Correct 763 ms 49972 KB Output is correct
108 Correct 1656 ms 46964 KB Output is correct
109 Correct 1016 ms 47680 KB Output is correct
110 Correct 1084 ms 48028 KB Output is correct
111 Correct 22 ms 37076 KB Output is correct
112 Correct 25 ms 37128 KB Output is correct
113 Correct 21 ms 37076 KB Output is correct
114 Correct 21 ms 37056 KB Output is correct
115 Correct 21 ms 37044 KB Output is correct
116 Correct 681 ms 48016 KB Output is correct
117 Correct 1728 ms 46656 KB Output is correct
118 Correct 918 ms 59724 KB Output is correct
119 Correct 790 ms 48296 KB Output is correct
120 Correct 579 ms 48208 KB Output is correct
121 Correct 509 ms 48556 KB Output is correct
122 Correct 349 ms 48808 KB Output is correct
123 Correct 816 ms 59260 KB Output is correct
124 Correct 2375 ms 53832 KB Output is correct
125 Correct 677 ms 49024 KB Output is correct
126 Correct 1823 ms 46416 KB Output is correct
127 Correct 1934 ms 46416 KB Output is correct
128 Correct 1120 ms 47288 KB Output is correct
129 Correct 1228 ms 47640 KB Output is correct