Submission #785504

# Submission time Handle Problem Language Result Execution time Memory
785504 2023-07-17T09:42:46 Z devariaota Sprinkler (JOI22_sprinkler) C++17
0 / 100
172 ms 28164 KB
#include <bits/stdc++.h>
using namespace std;

# define int long long
# define fir first
# define sec second
# define pb push_back
# define endl "\n"

const int cnst = 2e5+5;
bool mutipletestcase = 0;
//bool debug = false;


int F[cnst];
int inv[cnst];

int A(int a, int b, int mod) {return ((a%mod)+(b%mod)%mod);}
int S(int a, int b, int mod) {return ((a%mod)-(b%mod)+mod)%mod;}
int M(int a, int b, int mod) {return ((a%mod)*(b%mod)%mod);}

int E(int b, int p, int mod) {
    if(!p) return 1;
    return (p%2 ? M(E(M(b, b, mod), p/2, mod), b, mod) : E(M(b, b, mod), p/2, mod));
}

int C(int n, int r, int mod) {return M(M(F[n], inv[n-r], mod), inv[r], mod);}

void prefac(int maxn, int mod) {
    F[0] = 1;
    for(int i = 1; i<=maxn; i++) F[i] = M(F[i-1], i, mod);
    inv[maxn] = E(F[maxn], mod-2, mod);
    for(int i = maxn-1; i>=0; i--) inv[i] = M(inv[i+1], i+1, mod);
}

int gcd(int a, int b) {return b ? gcd(b, a%b): a;}
int lcm(int a, int b) {return a/gcd(a, b)*b;}

int par[cnst];
int val[cnst];
vector<int> vec[cnst];

int dfs(int x) {
    for(auto v: vec[x]) {
        if(v == par[x]) continue;
        par[v] = x;
        dfs(v);
    }
}

void solve() {
    int n, l; cin >> n >> l;

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

    for(int i = 1; i<=n; i++) cin >> val[i];

    int q; cin >> q;
    
    bool yes = 1;
    tuple<int, int, int, int> quer[q+5];

    for(int i = 1; i<=q; i++) {
        int id; cin >> id;
        int a, b = -1, c = -1;
        if(id == 1) cin >> a >> b >> c;
        else cin >> a;

        quer[i] = {id, a, b, c};
        if(id == 1 && c > 1) yes = 0; 
    }

    if(yes) {
        for(int i = 1; i<=q; i++) {
            auto[a, x, d, k] = quer[i];
            if(a == 1) {
                val[x] = M(val[x], k, l);
                if(d == 0) continue;
                for(auto v: vec[x]) val[v] = M(val[v], k, l);
            }
            else cout << val[x] << endl;
        }
    }

    
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t = 1;
    if(mutipletestcase) cin >> t; 
    while(t--) solve();
}

Compilation message

sprinkler.cpp: In function 'long long int dfs(long long int)':
sprinkler.cpp:49:1: warning: no return statement in function returning non-void [-Wreturn-type]
   49 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 172 ms 28164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -