이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 lazy[1 << 19];
int build(int s,int e,int i) {
if (s == e) {
lazy[i] = H[order[s]];
return 0;
}
int mid = (s+e) / 2;
build(s,mid,2*i+1),build(mid+1,e,2*i+2);
lazy[i] = 1;
return 0;
}
int update(int s,int e,int as,int ae,int i,int num) {
if ((s > ae) || (e < as)) return 0;
else if ((s >= as) && (e <= ae)) {
lazy[i] = ((LLI) lazy[i]*num) % L;
return 0;
}
int mid = (s+e) / 2;
update(s,mid,as,ae,2*i+1,num),update(mid+1,e,as,ae,2*i+2,num);
return 0;
}
int query(int s,int e,int q,int i) {
if (s == e) return lazy[i];
int mid = (s+e) / 2;
if (q <= mid) return ((LLI) lazy[i]*query(s,mid,q,2*i+1)) % L;
else return ((LLI) lazy[i]*query(mid+1,e,q,2*i+2)) % L;
}
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]);
}
}
}
}
build(0,N-1,0);
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(0,N-1,l[u][j-depth[u]],r[u][j-depth[u]],0,W);
}
}
else {
scanf("%d",&X),X--;
printf("%d\n",query(0,N-1,disc[X],0));
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:141:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
141 | while (par.size() <= D) par.pb(parent[par.back()]);
| ~~~~~~~~~~~^~~~
sprinkler.cpp:98:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | scanf("%d %d",&N,&L);
| ~~~~~^~~~~~~~~~~~~~~
sprinkler.cpp:100:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | scanf("%d %d",&A,&B);
| ~~~~~^~~~~~~~~~~~~~~
sprinkler.cpp:105:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | for (i = 0; i < N; i++) scanf("%d",&H[i]);
| ~~~~~^~~~~~~~~~~~
sprinkler.cpp:134:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
134 | scanf("%d",&Q);
| ~~~~~^~~~~~~~~
sprinkler.cpp:136:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
136 | scanf("%d",&T);
| ~~~~~^~~~~~~~~
sprinkler.cpp:138:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
138 | scanf("%d %d %d",&X,&D,&W),X--;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:149:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
149 | 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... |