# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
966717 |
2024-04-20T08:54:40 Z |
PM1 |
Sprinkler (JOI22_sprinkler) |
C++17 |
|
4000 ms |
101508 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#define ll long long
const int mxn=2e5+5;
int n,M,q,h[mxn],st[mxn],fn[mxn],cnt,dis[mxn],par[mxn];
int fnd[mxn][40][2];
vector<ll>v[mxn],d[mxn];
struct segment{
vector<ll>val;
void build(int sz){
while(__builtin_popcount(sz)!=1){
sz++;
}
sz*=2;
while(sz--)
val.push_back(1);
}
void add(int id,int L,int R,int l,int r,ll w){
if(L==l && R==r){
val[id]=(val[id]*w)%M;
return;
}
int mid=(L+R)/2;
if(l<mid)
add(id*2,L,mid,l,min(r,mid),w);
if(r>mid)
add(id*2+1,mid,R,max(l,mid),r,w);
}
ll get(int id,int L,int R,int l){
if(L+1==R)
return val[id];
int mid=(L+R)/2;
if(l<mid)
return (get(id*2,L,mid,l)*val[id])%M;
else
return (get(id*2+1,mid,R,l)*val[id])%M;
}
}seg[mxn];
void dfs(int z){
st[z]=++cnt;
d[dis[z]].push_back(st[z]);
for(auto i:v[z]){
if(i!=par[z]){
par[i]=z;
dis[i]=dis[z]+1;
dfs(i);
}
}
fn[z]=cnt;
}
void add(int x,int y,ll w){
if(d[x].size()==0)return;
int l=fnd[y][x-dis[y]][0];
int r=fnd[y][x-dis[y]][1];
r=min((int)d[x].size()-1,r);
if(l<r+1)
seg[x].add(1,0,d[x].size(),l,r+1,w);
}
void up(int x,int dd,int w){
for(;dd>=1 && x!=1;dd--){
int z=dis[x]+dd,zz=dis[x]+dd-1;
add(z,x,w);
add(zz,x,w);
x=par[x];
}
for(;dd>=0;dd--){
add(dis[x]+dd,x,w);
}
}
ll get(int z,int x){
int l=fnd[x][0][0];
return seg[z].get(1,0,d[z].size(),l);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>M;
for(int i=1;i<n;i++){
int x,y;
cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
for(int i=1;i<=n;i++)
cin>>h[i];
dfs(1);
for(int i=1;i<=n;i++){
for(int j=0;j<=40 && dis[i]+j<mxn;j++){
int dd=dis[i]+j;
if(d[dd].size()==0)break;
fnd[i][j][0]=lower_bound(d[dd].begin(),d[dd].end(),st[i])-d[dd].begin();
fnd[i][j][1]=upper_bound(d[dd].begin(),d[dd].end(),fn[i])-d[dd].begin()-1;
}
}
for(int i=0;i<=n;i++){
seg[i].build(d[i].size());
}
for(int i=1;i<=n;i++){
int l=fnd[i][0][0];
seg[dis[i]].add(1,0,d[dis[i]].size(),l,l+1,h[i]);
}
cin>>q;
while(q--){
int ty,x,dd,w;
cin>>ty;
if(ty==1){
cin>>x>>dd>>w;
up(x,dd,w);
}
else{
cin>>x;
cout<<get(dis[x],x)<<'\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
16984 KB |
Output is correct |
2 |
Correct |
4 ms |
16988 KB |
Output is correct |
3 |
Correct |
3 ms |
16988 KB |
Output is correct |
4 |
Correct |
5 ms |
16988 KB |
Output is correct |
5 |
Correct |
5 ms |
16988 KB |
Output is correct |
6 |
Correct |
6 ms |
17168 KB |
Output is correct |
7 |
Correct |
5 ms |
16988 KB |
Output is correct |
8 |
Correct |
4 ms |
16988 KB |
Output is correct |
9 |
Correct |
4 ms |
16988 KB |
Output is correct |
10 |
Correct |
4 ms |
16988 KB |
Output is correct |
11 |
Correct |
4 ms |
16988 KB |
Output is correct |
12 |
Correct |
4 ms |
16988 KB |
Output is correct |
13 |
Correct |
4 ms |
16988 KB |
Output is correct |
14 |
Correct |
4 ms |
17040 KB |
Output is correct |
15 |
Correct |
4 ms |
16988 KB |
Output is correct |
16 |
Correct |
4 ms |
17060 KB |
Output is correct |
17 |
Correct |
4 ms |
16988 KB |
Output is correct |
18 |
Correct |
4 ms |
16988 KB |
Output is correct |
19 |
Correct |
4 ms |
16988 KB |
Output is correct |
20 |
Correct |
4 ms |
17004 KB |
Output is correct |
21 |
Correct |
4 ms |
16988 KB |
Output is correct |
22 |
Correct |
5 ms |
16988 KB |
Output is correct |
23 |
Correct |
4 ms |
16984 KB |
Output is correct |
24 |
Correct |
4 ms |
16988 KB |
Output is correct |
25 |
Correct |
4 ms |
16988 KB |
Output is correct |
26 |
Correct |
4 ms |
16988 KB |
Output is correct |
27 |
Correct |
4 ms |
17236 KB |
Output is correct |
28 |
Correct |
5 ms |
16984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
16984 KB |
Output is correct |
2 |
Execution timed out |
4083 ms |
101508 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
16984 KB |
Output is correct |
2 |
Execution timed out |
4083 ms |
101508 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
16988 KB |
Output is correct |
2 |
Execution timed out |
4066 ms |
55184 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
16984 KB |
Output is correct |
2 |
Execution timed out |
4072 ms |
47208 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
16984 KB |
Output is correct |
2 |
Correct |
4 ms |
16988 KB |
Output is correct |
3 |
Correct |
3 ms |
16988 KB |
Output is correct |
4 |
Correct |
5 ms |
16988 KB |
Output is correct |
5 |
Correct |
5 ms |
16988 KB |
Output is correct |
6 |
Correct |
6 ms |
17168 KB |
Output is correct |
7 |
Correct |
5 ms |
16988 KB |
Output is correct |
8 |
Correct |
4 ms |
16988 KB |
Output is correct |
9 |
Correct |
4 ms |
16988 KB |
Output is correct |
10 |
Correct |
4 ms |
16988 KB |
Output is correct |
11 |
Correct |
4 ms |
16988 KB |
Output is correct |
12 |
Correct |
4 ms |
16988 KB |
Output is correct |
13 |
Correct |
4 ms |
16988 KB |
Output is correct |
14 |
Correct |
4 ms |
17040 KB |
Output is correct |
15 |
Correct |
4 ms |
16988 KB |
Output is correct |
16 |
Correct |
4 ms |
17060 KB |
Output is correct |
17 |
Correct |
4 ms |
16988 KB |
Output is correct |
18 |
Correct |
4 ms |
16988 KB |
Output is correct |
19 |
Correct |
4 ms |
16988 KB |
Output is correct |
20 |
Correct |
4 ms |
17004 KB |
Output is correct |
21 |
Correct |
4 ms |
16988 KB |
Output is correct |
22 |
Correct |
5 ms |
16988 KB |
Output is correct |
23 |
Correct |
4 ms |
16984 KB |
Output is correct |
24 |
Correct |
4 ms |
16988 KB |
Output is correct |
25 |
Correct |
4 ms |
16988 KB |
Output is correct |
26 |
Correct |
4 ms |
16988 KB |
Output is correct |
27 |
Correct |
4 ms |
17236 KB |
Output is correct |
28 |
Correct |
5 ms |
16984 KB |
Output is correct |
29 |
Correct |
4 ms |
16984 KB |
Output is correct |
30 |
Execution timed out |
4083 ms |
101508 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |