Submission #1025239

# Submission time Handle Problem Language Result Execution time Memory
1025239 2024-07-16T18:13:05 Z underwaterkillerwhale Sprinkler (JOI22_sprinkler) C++17
0 / 100
791 ms 89532 KB
#include <bits/stdc++.h>
#define se              second
#define fs              first
#define pb              push_back
#define ll              long long
#define ii              pair<ll,ll>
#define ld              long double
#define SZ(v)           (int)v.size()
#define ALL(v)          v.begin(), v.end()
#define bit(msk, i)     ((msk >> i) & 1)
#define iter(id, v)     for(auto id : v)
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }

const int N = 2e5 + 7;
int Mod = 1e9 + 7;
const int szBL = 916;
const ll INF = 1e9;
const int BASE = 137;

int n, Q;
int a[N];
ll val[N][41], par[N];
vector<int> ke[N];

void dfs (int u, int p){
    par[u] = p;
    iter (&v, ke[u]) {
        if (v != p) dfs (v, u);
    }
}
void update (int u, int d, ll w, int h = 0) {
    if (h > d) return;
    (val[u][d - h] *= w) %= Mod;
    update (par[u], d, w, h + 1);
}

ll get (int x, int de) {
    if (de == 41) return 1;
    if (x == 1) {
        return val[1][de];
    }
    return val[x][de] * val[x][de + 1] % Mod * get (par[x], de + 1) % Mod;
}

void solution () {
    cin >> n >> Mod;
    rep (i, 1, n - 1) {
        int u, v;
        cin >> u >> v;
        ke[u].push_back(v);
        ke[v].push_back(u);
    }
    rep (i, 1, n) rep (j, 1, 41) val[i][j] = 1;
    rep (i, 1, n) cin >> a[i], val[i][0] = a[i];
    dfs (1, 0);
    par[1] = 1;
    cin >> Q;
    rep (i, 1, Q) {
        int typ; cin >> typ;
        if (typ == 1) {
            ll x, d, w;
            cin >>x >> d >> w;
            update (x, d, w);
        }
        else {
            ll x;
            cin >> x;
            cout << get (x, 0) <<"\n";
        }
    }
}

#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);

int main () {
//    file("c");
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll num_Test = 1;
//    cin >> num_Test;
    while(num_Test--)
        solution();
}
/*

*/

Compilation message

sprinkler.cpp: In function 'void solution()':
sprinkler.cpp:59:44: warning: iteration 40 invokes undefined behavior [-Waggressive-loop-optimizations]
   59 |     rep (i, 1, n) rep (j, 1, 41) val[i][j] = 1;
      |                                  ~~~~~~~~~~^~~
sprinkler.cpp:12:41: note: within this loop
   12 | #define rep(i,m,n)      for(int i=(m); i<=(n); i++)
      |                                         ^
sprinkler.cpp:59:19: note: in expansion of macro 'rep'
   59 |     rep (i, 1, n) rep (j, 1, 41) val[i][j] = 1;
      |                   ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Incorrect 3 ms 5468 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Incorrect 581 ms 89532 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Incorrect 581 ms 89532 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4952 KB Output is correct
2 Incorrect 774 ms 84492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Incorrect 791 ms 89212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Incorrect 3 ms 5468 KB Output isn't correct
5 Halted 0 ms 0 KB -