답안 #627079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627079 2022-08-12T06:41:50 Z slime Sprinkler (JOI22_sprinkler) C++14
100 / 100
1584 ms 104820 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
#define ll __int128
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
ll read() { int x; cin >> x; return (ll)x; }
long long bm(long long b, long long p) {
  if(p==0) return 1 % MOD;
  long long r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
long long inv(long long b) { 
  return bm(b, MOD-2);
}
long long f[MAXN];
long long nCr(int n, int r) { 
  long long ans = f[n]; ans *= inv(f[r]); ans %= MOD;
  ans *= inv(f[n-r]); ans %= MOD; return ans;
}
long long fib[MAXN], lucas[MAXN];
void precomp() { 
  for(int i=0; i<MAXN; i++) f[i] = (i == 0 ? 1 % MOD : (f[i-1] * i) % MOD); 
  lucas[0] = 2;
  lucas[1] = 1;
  for(int i=2; i<MAXN; i++) lucas[i] = (lucas[i-2] + lucas[i-1]) % MOD;
  fib[0] = 0;
  fib[1] = 1;
  for(int i=2; i<MAXN; i++) fib[i] = (fib[i-2] + fib[i-1]) % MOD;
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void gay(int i) { cout << "Case #" << i << ": "; }
int csb(int l, int r, int k) { // count number of [l, r] such that i & 2^k > 0
  if(l > r) return 0;
  if(l == 0) {
    int s = r / (1ll << (k+1)); // number of complete cycles
    int t = r % (1ll << (k+1));
    int ans = s * (1ll << k);
    ans += (t >= (1ll << k) ? t - (1ll << k) + 1 : 0);
    return ans;
  }
  else return csb(0, r, k) - csb(0, l - 1, k);
}
int lis(vector<int> a) {
  int n = a.size();
  int bucket[n+1];
  for(int i=1; i<=n; i++) bucket[i] = 1e18;
  int ans = 1;
  for(int x: a) {
    auto it = lower_bound(bucket + 1, bucket +n +1, x);
    int d = distance(bucket, it);
    ans = max(ans, d);
    bucket[d] = min(bucket[d], x);
  }
  return ans;
}
vector<int> adj[MAXN];
int par[MAXN];
int dep[MAXN];
void dfs(int node, int prv) {
  par[node] = prv;
  dep[node] = (prv== -1? 0: dep[prv]+1);
  for(int x: adj[node]) if(x != prv) dfs(x, node);
}
void solve(int tc) {
  int n, l;
  cin >> n >> l;
  for(int i=1; i<n; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1, -1);
  int h[n+1];
  for(int i=1; i<=n; i++) cin >> h[i];
  int dlt[n+1][41];
  for(int i=1; i<=n; i++) for(int j=0; j<41; j++) dlt[i][j] = 1;
  int q;
  cin >> q;
  while(q--) {
    int t;
    cin >> t;
    if(t == 1) {
      int x, d, w;
      cin >> x >> d >> w;
      vector<int> v;
      for(int i=0; i<=d; i++) {
        v.push_back(x);
        x = par[x];
        if(x == -1) break;
      }
      int maxdepthdone = -1;
      for(int i=v.size()-1; i>=0; i--) {
        int allow = d - i + dep[v[i]];
        int mini = dep[v[i]];
        for(int j = max(maxdepthdone + 1, mini); j <= allow; j++) {
          dlt[v[i]][j - dep[v[i]]] = (dlt[v[i]][j - dep[v[i]]] * w) % l;
        }
        maxdepthdone = allow;
      }
    }
    else {
      int x;
      cin >> x;
      int cur = h[x];
      for(int i=0; i<=40; i++) {
        cur = (cur * dlt[x][i]) % l;
        x = par[x];
        if(x == -1) break;
      }
      cout << cur << "\n";
    }
  }
} 
int32_t main() {
  precomp();
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
// I don't know geometry.
// Teaming is unfair.
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 14388 KB Output is correct
2 Correct 13 ms 14360 KB Output is correct
3 Correct 13 ms 14420 KB Output is correct
4 Correct 13 ms 14816 KB Output is correct
5 Correct 13 ms 14804 KB Output is correct
6 Correct 13 ms 14836 KB Output is correct
7 Correct 12 ms 14816 KB Output is correct
8 Correct 12 ms 14760 KB Output is correct
9 Correct 12 ms 14412 KB Output is correct
10 Correct 12 ms 14420 KB Output is correct
11 Correct 12 ms 14420 KB Output is correct
12 Correct 12 ms 14420 KB Output is correct
13 Correct 12 ms 14424 KB Output is correct
14 Correct 12 ms 14420 KB Output is correct
15 Correct 13 ms 14420 KB Output is correct
16 Correct 13 ms 14548 KB Output is correct
17 Correct 13 ms 14420 KB Output is correct
18 Correct 13 ms 14356 KB Output is correct
19 Correct 13 ms 14332 KB Output is correct
20 Correct 12 ms 14416 KB Output is correct
21 Correct 12 ms 14396 KB Output is correct
22 Correct 12 ms 14424 KB Output is correct
23 Correct 12 ms 14420 KB Output is correct
24 Correct 12 ms 14420 KB Output is correct
25 Correct 12 ms 14420 KB Output is correct
26 Correct 12 ms 14420 KB Output is correct
27 Correct 11 ms 14420 KB Output is correct
28 Correct 14 ms 14424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14420 KB Output is correct
2 Correct 649 ms 102348 KB Output is correct
3 Correct 478 ms 102896 KB Output is correct
4 Correct 737 ms 101392 KB Output is correct
5 Correct 620 ms 102680 KB Output is correct
6 Correct 491 ms 102128 KB Output is correct
7 Correct 421 ms 103000 KB Output is correct
8 Correct 334 ms 103212 KB Output is correct
9 Correct 738 ms 101084 KB Output is correct
10 Correct 469 ms 101704 KB Output is correct
11 Correct 737 ms 102256 KB Output is correct
12 Correct 484 ms 102748 KB Output is correct
13 Correct 297 ms 102872 KB Output is correct
14 Correct 295 ms 103348 KB Output is correct
15 Correct 284 ms 102628 KB Output is correct
16 Correct 295 ms 103236 KB Output is correct
17 Correct 300 ms 103668 KB Output is correct
18 Correct 13 ms 14440 KB Output is correct
19 Correct 13 ms 14424 KB Output is correct
20 Correct 13 ms 14420 KB Output is correct
21 Correct 12 ms 14424 KB Output is correct
22 Correct 12 ms 14424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14420 KB Output is correct
2 Correct 649 ms 102348 KB Output is correct
3 Correct 478 ms 102896 KB Output is correct
4 Correct 737 ms 101392 KB Output is correct
5 Correct 620 ms 102680 KB Output is correct
6 Correct 491 ms 102128 KB Output is correct
7 Correct 421 ms 103000 KB Output is correct
8 Correct 334 ms 103212 KB Output is correct
9 Correct 738 ms 101084 KB Output is correct
10 Correct 469 ms 101704 KB Output is correct
11 Correct 737 ms 102256 KB Output is correct
12 Correct 484 ms 102748 KB Output is correct
13 Correct 297 ms 102872 KB Output is correct
14 Correct 295 ms 103348 KB Output is correct
15 Correct 284 ms 102628 KB Output is correct
16 Correct 295 ms 103236 KB Output is correct
17 Correct 300 ms 103668 KB Output is correct
18 Correct 13 ms 14440 KB Output is correct
19 Correct 13 ms 14424 KB Output is correct
20 Correct 13 ms 14420 KB Output is correct
21 Correct 12 ms 14424 KB Output is correct
22 Correct 12 ms 14424 KB Output is correct
23 Correct 12 ms 14412 KB Output is correct
24 Correct 620 ms 102360 KB Output is correct
25 Correct 533 ms 102772 KB Output is correct
26 Correct 633 ms 101500 KB Output is correct
27 Correct 591 ms 102544 KB Output is correct
28 Correct 410 ms 102820 KB Output is correct
29 Correct 390 ms 102436 KB Output is correct
30 Correct 330 ms 103352 KB Output is correct
31 Correct 675 ms 101260 KB Output is correct
32 Correct 495 ms 101688 KB Output is correct
33 Correct 650 ms 102304 KB Output is correct
34 Correct 503 ms 102824 KB Output is correct
35 Correct 12 ms 14420 KB Output is correct
36 Correct 13 ms 14440 KB Output is correct
37 Correct 12 ms 14420 KB Output is correct
38 Correct 12 ms 14420 KB Output is correct
39 Correct 13 ms 14440 KB Output is correct
40 Correct 12 ms 14420 KB Output is correct
41 Correct 13 ms 14356 KB Output is correct
42 Correct 12 ms 14420 KB Output is correct
43 Correct 13 ms 14400 KB Output is correct
44 Correct 12 ms 14424 KB Output is correct
45 Correct 11 ms 14432 KB Output is correct
46 Correct 11 ms 14420 KB Output is correct
47 Correct 12 ms 14420 KB Output is correct
48 Correct 12 ms 14420 KB Output is correct
49 Correct 12 ms 14432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14416 KB Output is correct
2 Correct 811 ms 98360 KB Output is correct
3 Correct 1515 ms 99016 KB Output is correct
4 Correct 861 ms 98548 KB Output is correct
5 Correct 835 ms 99632 KB Output is correct
6 Correct 534 ms 99828 KB Output is correct
7 Correct 448 ms 100020 KB Output is correct
8 Correct 316 ms 100164 KB Output is correct
9 Correct 866 ms 98368 KB Output is correct
10 Correct 1410 ms 99044 KB Output is correct
11 Correct 762 ms 99352 KB Output is correct
12 Correct 1291 ms 100200 KB Output is correct
13 Correct 813 ms 101064 KB Output is correct
14 Correct 869 ms 101908 KB Output is correct
15 Correct 13 ms 14420 KB Output is correct
16 Correct 12 ms 14420 KB Output is correct
17 Correct 13 ms 14316 KB Output is correct
18 Correct 13 ms 14428 KB Output is correct
19 Correct 12 ms 14548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 14420 KB Output is correct
2 Correct 841 ms 101304 KB Output is correct
3 Correct 1527 ms 99364 KB Output is correct
4 Correct 886 ms 100144 KB Output is correct
5 Correct 801 ms 101340 KB Output is correct
6 Correct 484 ms 101344 KB Output is correct
7 Correct 454 ms 101156 KB Output is correct
8 Correct 314 ms 101372 KB Output is correct
9 Correct 806 ms 101016 KB Output is correct
10 Correct 1326 ms 99384 KB Output is correct
11 Correct 778 ms 101992 KB Output is correct
12 Correct 1237 ms 100416 KB Output is correct
13 Correct 784 ms 101108 KB Output is correct
14 Correct 846 ms 102072 KB Output is correct
15 Correct 14 ms 14424 KB Output is correct
16 Correct 14 ms 14436 KB Output is correct
17 Correct 13 ms 14416 KB Output is correct
18 Correct 12 ms 14420 KB Output is correct
19 Correct 12 ms 14364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 14388 KB Output is correct
2 Correct 13 ms 14360 KB Output is correct
3 Correct 13 ms 14420 KB Output is correct
4 Correct 13 ms 14816 KB Output is correct
5 Correct 13 ms 14804 KB Output is correct
6 Correct 13 ms 14836 KB Output is correct
7 Correct 12 ms 14816 KB Output is correct
8 Correct 12 ms 14760 KB Output is correct
9 Correct 12 ms 14412 KB Output is correct
10 Correct 12 ms 14420 KB Output is correct
11 Correct 12 ms 14420 KB Output is correct
12 Correct 12 ms 14420 KB Output is correct
13 Correct 12 ms 14424 KB Output is correct
14 Correct 12 ms 14420 KB Output is correct
15 Correct 13 ms 14420 KB Output is correct
16 Correct 13 ms 14548 KB Output is correct
17 Correct 13 ms 14420 KB Output is correct
18 Correct 13 ms 14356 KB Output is correct
19 Correct 13 ms 14332 KB Output is correct
20 Correct 12 ms 14416 KB Output is correct
21 Correct 12 ms 14396 KB Output is correct
22 Correct 12 ms 14424 KB Output is correct
23 Correct 12 ms 14420 KB Output is correct
24 Correct 12 ms 14420 KB Output is correct
25 Correct 12 ms 14420 KB Output is correct
26 Correct 12 ms 14420 KB Output is correct
27 Correct 11 ms 14420 KB Output is correct
28 Correct 14 ms 14424 KB Output is correct
29 Correct 13 ms 14420 KB Output is correct
30 Correct 649 ms 102348 KB Output is correct
31 Correct 478 ms 102896 KB Output is correct
32 Correct 737 ms 101392 KB Output is correct
33 Correct 620 ms 102680 KB Output is correct
34 Correct 491 ms 102128 KB Output is correct
35 Correct 421 ms 103000 KB Output is correct
36 Correct 334 ms 103212 KB Output is correct
37 Correct 738 ms 101084 KB Output is correct
38 Correct 469 ms 101704 KB Output is correct
39 Correct 737 ms 102256 KB Output is correct
40 Correct 484 ms 102748 KB Output is correct
41 Correct 297 ms 102872 KB Output is correct
42 Correct 295 ms 103348 KB Output is correct
43 Correct 284 ms 102628 KB Output is correct
44 Correct 295 ms 103236 KB Output is correct
45 Correct 300 ms 103668 KB Output is correct
46 Correct 13 ms 14440 KB Output is correct
47 Correct 13 ms 14424 KB Output is correct
48 Correct 13 ms 14420 KB Output is correct
49 Correct 12 ms 14424 KB Output is correct
50 Correct 12 ms 14424 KB Output is correct
51 Correct 12 ms 14412 KB Output is correct
52 Correct 620 ms 102360 KB Output is correct
53 Correct 533 ms 102772 KB Output is correct
54 Correct 633 ms 101500 KB Output is correct
55 Correct 591 ms 102544 KB Output is correct
56 Correct 410 ms 102820 KB Output is correct
57 Correct 390 ms 102436 KB Output is correct
58 Correct 330 ms 103352 KB Output is correct
59 Correct 675 ms 101260 KB Output is correct
60 Correct 495 ms 101688 KB Output is correct
61 Correct 650 ms 102304 KB Output is correct
62 Correct 503 ms 102824 KB Output is correct
63 Correct 12 ms 14420 KB Output is correct
64 Correct 13 ms 14440 KB Output is correct
65 Correct 12 ms 14420 KB Output is correct
66 Correct 12 ms 14420 KB Output is correct
67 Correct 13 ms 14440 KB Output is correct
68 Correct 12 ms 14420 KB Output is correct
69 Correct 13 ms 14356 KB Output is correct
70 Correct 12 ms 14420 KB Output is correct
71 Correct 13 ms 14400 KB Output is correct
72 Correct 12 ms 14424 KB Output is correct
73 Correct 11 ms 14432 KB Output is correct
74 Correct 11 ms 14420 KB Output is correct
75 Correct 12 ms 14420 KB Output is correct
76 Correct 12 ms 14420 KB Output is correct
77 Correct 12 ms 14432 KB Output is correct
78 Correct 11 ms 14416 KB Output is correct
79 Correct 811 ms 98360 KB Output is correct
80 Correct 1515 ms 99016 KB Output is correct
81 Correct 861 ms 98548 KB Output is correct
82 Correct 835 ms 99632 KB Output is correct
83 Correct 534 ms 99828 KB Output is correct
84 Correct 448 ms 100020 KB Output is correct
85 Correct 316 ms 100164 KB Output is correct
86 Correct 866 ms 98368 KB Output is correct
87 Correct 1410 ms 99044 KB Output is correct
88 Correct 762 ms 99352 KB Output is correct
89 Correct 1291 ms 100200 KB Output is correct
90 Correct 813 ms 101064 KB Output is correct
91 Correct 869 ms 101908 KB Output is correct
92 Correct 13 ms 14420 KB Output is correct
93 Correct 12 ms 14420 KB Output is correct
94 Correct 13 ms 14316 KB Output is correct
95 Correct 13 ms 14428 KB Output is correct
96 Correct 12 ms 14548 KB Output is correct
97 Correct 12 ms 14420 KB Output is correct
98 Correct 841 ms 101304 KB Output is correct
99 Correct 1527 ms 99364 KB Output is correct
100 Correct 886 ms 100144 KB Output is correct
101 Correct 801 ms 101340 KB Output is correct
102 Correct 484 ms 101344 KB Output is correct
103 Correct 454 ms 101156 KB Output is correct
104 Correct 314 ms 101372 KB Output is correct
105 Correct 806 ms 101016 KB Output is correct
106 Correct 1326 ms 99384 KB Output is correct
107 Correct 778 ms 101992 KB Output is correct
108 Correct 1237 ms 100416 KB Output is correct
109 Correct 784 ms 101108 KB Output is correct
110 Correct 846 ms 102072 KB Output is correct
111 Correct 14 ms 14424 KB Output is correct
112 Correct 14 ms 14436 KB Output is correct
113 Correct 13 ms 14416 KB Output is correct
114 Correct 12 ms 14420 KB Output is correct
115 Correct 12 ms 14364 KB Output is correct
116 Correct 870 ms 100348 KB Output is correct
117 Correct 1584 ms 102940 KB Output is correct
118 Correct 1117 ms 101480 KB Output is correct
119 Correct 886 ms 102572 KB Output is correct
120 Correct 572 ms 102332 KB Output is correct
121 Correct 574 ms 103132 KB Output is correct
122 Correct 384 ms 103164 KB Output is correct
123 Correct 1046 ms 101392 KB Output is correct
124 Correct 1569 ms 101612 KB Output is correct
125 Correct 806 ms 101444 KB Output is correct
126 Correct 1476 ms 102852 KB Output is correct
127 Correct 1549 ms 103236 KB Output is correct
128 Correct 896 ms 104128 KB Output is correct
129 Correct 991 ms 104820 KB Output is correct