This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
int L;
vi adjList[200000];
int H[200000];
int parent[200000],depth[200000],disc[200000],order[200000];
queue<int> QQ;
int l[200000][81],r[200000][81];
int tree[400000];
int update(int s,int e,int N,int num) {
s += N,e += N+1;
while (s < e) {
if (s & 1) tree[s] = ((LLI) tree[s]*num) % L,s++;
if (e & 1) e--,tree[e] = ((LLI) tree[e]*num) % L;
s >>= 1,e >>= 1;
}
return 0;
}
int query(int i,int N) {
LLI ans = 1;
i += N;
while (i > 0) ans = (ans*tree[i]) % L,i >>= 1;
return ans;
}
int main() {
int i;
int N,A,B,Q;
int T,X,D,W;
scanf("%d %d",&N,&L);
for (i = 0; i < N-1; i++) {
scanf("%d %d",&A,&B);
A--,B--;
adjList[A].pb(B);
adjList[B].pb(A);
}
for (i = 0; i < N; i++) scanf("%d",&H[i]);
int num = 0;
for (i = 0; i < N; i++) depth[i] = -1;
depth[0] = 0,QQ.push(0),parent[0] = 0;
while (!QQ.empty()) {
int u = QQ.front();
QQ.pop();
disc[u] = num++,order[num-1] = u;
for (int v: adjList[u]) {
if (depth[v] == -1) parent[v] = u,depth[v] = depth[u]+1,QQ.push(v);
}
}
int j;
for (i = N-1; i >= 0; i--) {
int u = order[i];
for (j = 0; j <= 80; j++) {
if (j == 0) l[u][j] = r[u][j] = i;
else {
l[u][j] = 1e9,r[u][j] = -1e9;
for (int v: adjList[u]) {
if (depth[v] == depth[u]+1) l[u][j] = min(l[u][j],l[v][j-1]),r[u][j] = max(r[u][j],r[v][j-1]);
}
}
}
}
for (i = 0; i < N; i++) tree[i+N] = H[order[i]];
for (i = 1; i < N; i++) tree[i] = 1;
scanf("%d",&Q);
for (i = 0; i < Q; i++) {
scanf("%d",&T);
if (T == 1) {
scanf("%d %d %d",&X,&D,&W),X--;
vi par;
par.pb(X);
while (par.size() <= D) par.pb(parent[par.back()]);
for (j = max(depth[X]-D,0); j <= depth[X]+D; j++) {
int d = (max(depth[X]+j-D,0)+1)/2;
int u = par[depth[X]-d];
if (l[u][j-depth[u]] <= r[u][j-depth[u]]) update(l[u][j-depth[u]],r[u][j-depth[u]],N,W);
}
}
else {
scanf("%d",&X),X--;
printf("%d\n",query(disc[X],N));
}
}
return 0;
}
Compilation message (stderr)
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:128:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
128 | while (par.size() <= D) par.pb(parent[par.back()]);
| ~~~~~~~~~~~^~~~
sprinkler.cpp:84:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | scanf("%d %d",&N,&L);
| ~~~~~^~~~~~~~~~~~~~~
sprinkler.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | scanf("%d %d",&A,&B);
| ~~~~~^~~~~~~~~~~~~~~
sprinkler.cpp:91:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | for (i = 0; i < N; i++) scanf("%d",&H[i]);
| ~~~~~^~~~~~~~~~~~
sprinkler.cpp:121:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
121 | scanf("%d",&Q);
| ~~~~~^~~~~~~~~
sprinkler.cpp:123:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
123 | scanf("%d",&T);
| ~~~~~^~~~~~~~~
sprinkler.cpp:125:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
125 | scanf("%d %d %d",&X,&D,&W),X--;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:136:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
136 | scanf("%d",&X),X--;
| ~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |