Submission #637966

# Submission time Handle Problem Language Result Execution time Memory
637966 2022-09-03T18:35:04 Z victor_gao Sprinkler (JOI22_sprinkler) C++17
38 / 100
4000 ms 191524 KB
#pragma GCC optimize("Ofast,unroll-loops,O3")
#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define N 200002
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
int n,L,loc[N],sz[N],fa[N],h[N];
vector<int>g[N];
struct BIT_2D{
    vector<int>bit[6];
    int n=0,m=4;
    void init(int _n){
        n=_n;
        for (int i=0;i<=m;i++)
            bit[i].resize(n+2,1);
    }
    void modify(int x,int y,int c){
        x=m-x;
       // cout<<"modify : "<<x<<' '<<y<<" "<<c<<'\n';
        while (x<=m){
            int ty=y;
            while (ty<=n){
                bit[x][ty]=bit[x][ty]*c%L;
                ty+=ty&(-ty);
            }
            x+=x&(-x);
        }
    }
    int query(int x,int y){
        int ans=1;
        x=m-x;
      //  cout<<"query : "<<x<<' '<<y<<'\n';
        while (x>0){
            int ty=y;
            while (ty>0){
                ans=ans*bit[x][ty]%L;
                ty-=ty&(-ty);
            }
            x-=x&(-x);
        }
        return ans;
    }
}cntl[N],cntr[N];
void dfs(int p,int lp){
    fa[p]=lp;
    for (auto i:g[p]){
        if (i!=lp){
            dfs(i,p);
            sz[p]++;
            loc[i]=sz[p];
        }
    }
}
signed main(){
    fast
    cin>>n>>L;
    for (int i=1;i<n;i++){
        int a,b; cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (int i=1;i<=n;i++)
        cin>>h[i];
    dfs(1,0);
    loc[1]=1; sz[0]=1;
    for (int i=0;i<=n;i++){
        sz[i]++;
        cntl[i].init(sz[i]);
        cntr[i].init(sz[i]);
    }
    int q; cin>>q;
    while (q--){
        int type,x,d,w; cin>>type;
        if (type==1){
            cin>>x>>d>>w;
            cntl[x].modify(d,1,w);
            for (int i=0;i<d;i++){
                if (x==0) break;
                int pos=loc[x];
              //  cout<<x<<" "<<fa[x]<<' '<<pos<<" "<<d-i+1<<'\n';
                cntl[fa[x]].modify(d-i-1,pos+1,w);
                cntr[fa[x]].modify(d-i-1,sz[fa[x]]-pos+1,w);
               // cout<<"dis : "<<d-i+1<<" OK\n";
                x=fa[x];
            }
        }
        else {
            cin>>x;
            int ans=h[x];
            int tans1=cntl[x].query(0,sz[x]),tans2;
            ans=(ans*tans1)%L;
         //   cout<<" -> "<<tans1<<'\n';
            for (int i=1;i<=3;i++){
                if (x==0) break;
                int pos=loc[x];
                tans1=cntl[fa[x]].query(i,pos);
                tans2=cntr[fa[x]].query(i,sz[fa[x]]-pos);
              //  cout<<" -> "<<tans1<<' '<<tans2<<'\n';
                ans=(ans*tans1%L*tans2)%L;
                x=fa[x];
            }
            cout<<ans<<'\n';
        }
    }
}

Compilation message

sprinkler.cpp:2:88: warning: bad option '-favx' to pragma 'optimize' [-Wpragmas]
    2 | #pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
      |                                                                                        ^
sprinkler.cpp:2:88: warning: bad option '-favx2' to pragma 'optimize' [-Wpragmas]
sprinkler.cpp:2:88: warning: bad option '-fsse' to pragma 'optimize' [-Wpragmas]
sprinkler.cpp:2:88: warning: bad option '-fsse2' to pragma 'optimize' [-Wpragmas]
sprinkler.cpp:2:88: warning: bad option '-fsse3' to pragma 'optimize' [-Wpragmas]
sprinkler.cpp:2:88: warning: bad option '-fssse3' to pragma 'optimize' [-Wpragmas]
sprinkler.cpp:2:88: warning: bad option '-fsse4' to pragma 'optimize' [-Wpragmas]
sprinkler.cpp:2:88: warning: bad option '-fpopcnt' to pragma 'optimize' [-Wpragmas]
sprinkler.cpp:2:88: warning: bad option '-fabm' to pragma 'optimize' [-Wpragmas]
sprinkler.cpp:2:88: warning: bad option '-fmmx' to pragma 'optimize' [-Wpragmas]
sprinkler.cpp:2:88: warning: bad option '-ffma' to pragma 'optimize' [-Wpragmas]
sprinkler.cpp:2:88: warning: bad option '-ftune=native' to pragma 'optimize' [-Wpragmas]
sprinkler.cpp:22:21: warning: bad option '-favx' to attribute 'optimize' [-Wattributes]
   22 |     void init(int _n){
      |                     ^
sprinkler.cpp:22:21: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:22:21: warning: bad option '-fsse' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:22:21: warning: bad option '-fsse2' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:22:21: warning: bad option '-fsse3' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:22:21: warning: bad option '-fssse3' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:22:21: warning: bad option '-fsse4' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:22:21: warning: bad option '-fpopcnt' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:22:21: warning: bad option '-fabm' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:22:21: warning: bad option '-fmmx' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:22:21: warning: bad option '-ffma' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:22:21: warning: bad option '-ftune=native' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:27:34: warning: bad option '-favx' to attribute 'optimize' [-Wattributes]
   27 |     void modify(int x,int y,int c){
      |                                  ^
sprinkler.cpp:27:34: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:27:34: warning: bad option '-fsse' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:27:34: warning: bad option '-fsse2' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:27:34: warning: bad option '-fsse3' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:27:34: warning: bad option '-fssse3' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:27:34: warning: bad option '-fsse4' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:27:34: warning: bad option '-fpopcnt' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:27:34: warning: bad option '-fabm' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:27:34: warning: bad option '-fmmx' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:27:34: warning: bad option '-ffma' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:27:34: warning: bad option '-ftune=native' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:39:26: warning: bad option '-favx' to attribute 'optimize' [-Wattributes]
   39 |     int query(int x,int y){
      |                          ^
sprinkler.cpp:39:26: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:39:26: warning: bad option '-fsse' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:39:26: warning: bad option '-fsse2' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:39:26: warning: bad option '-fsse3' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:39:26: warning: bad option '-fssse3' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:39:26: warning: bad option '-fsse4' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:39:26: warning: bad option '-fpopcnt' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:39:26: warning: bad option '-fabm' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:39:26: warning: bad option '-fmmx' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:39:26: warning: bad option '-ffma' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:39:26: warning: bad option '-ftune=native' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:54:22: warning: bad option '-favx' to attribute 'optimize' [-Wattributes]
   54 | void dfs(int p,int lp){
      |                      ^
sprinkler.cpp:54:22: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:54:22: warning: bad option '-fsse' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:54:22: warning: bad option '-fsse2' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:54:22: warning: bad option '-fsse3' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:54:22: warning: bad option '-fssse3' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:54:22: warning: bad option '-fsse4' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:54:22: warning: bad option '-fpopcnt' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:54:22: warning: bad option '-fabm' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:54:22: warning: bad option '-fmmx' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:54:22: warning: bad option '-ffma' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:54:22: warning: bad option '-ftune=native' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:64:13: warning: bad option '-favx' to attribute 'optimize' [-Wattributes]
   64 | signed main(){
      |             ^
sprinkler.cpp:64:13: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:64:13: warning: bad option '-fsse' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:64:13: warning: bad option '-fsse2' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:64:13: warning: bad option '-fsse3' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:64:13: warning: bad option '-fssse3' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:64:13: warning: bad option '-fsse4' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:64:13: warning: bad option '-fpopcnt' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:64:13: warning: bad option '-fabm' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:64:13: warning: bad option '-fmmx' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:64:13: warning: bad option '-ffma' to attribute 'optimize' [-Wattributes]
sprinkler.cpp:64:13: warning: bad option '-ftune=native' to attribute 'optimize' [-Wattributes]
# Verdict Execution time Memory Grader output
1 Execution timed out 4062 ms 67620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 67660 KB Output is correct
2 Correct 682 ms 173896 KB Output is correct
3 Correct 644 ms 170620 KB Output is correct
4 Correct 660 ms 184024 KB Output is correct
5 Correct 702 ms 172416 KB Output is correct
6 Correct 645 ms 170916 KB Output is correct
7 Correct 636 ms 170140 KB Output is correct
8 Correct 563 ms 166232 KB Output is correct
9 Correct 753 ms 187504 KB Output is correct
10 Correct 674 ms 183752 KB Output is correct
11 Correct 718 ms 173956 KB Output is correct
12 Correct 666 ms 178420 KB Output is correct
13 Correct 520 ms 173328 KB Output is correct
14 Correct 546 ms 173688 KB Output is correct
15 Correct 516 ms 173348 KB Output is correct
16 Correct 512 ms 173512 KB Output is correct
17 Correct 559 ms 174064 KB Output is correct
18 Correct 39 ms 67596 KB Output is correct
19 Correct 39 ms 67660 KB Output is correct
20 Correct 41 ms 67692 KB Output is correct
21 Correct 39 ms 67648 KB Output is correct
22 Correct 39 ms 67664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 67660 KB Output is correct
2 Correct 682 ms 173896 KB Output is correct
3 Correct 644 ms 170620 KB Output is correct
4 Correct 660 ms 184024 KB Output is correct
5 Correct 702 ms 172416 KB Output is correct
6 Correct 645 ms 170916 KB Output is correct
7 Correct 636 ms 170140 KB Output is correct
8 Correct 563 ms 166232 KB Output is correct
9 Correct 753 ms 187504 KB Output is correct
10 Correct 674 ms 183752 KB Output is correct
11 Correct 718 ms 173956 KB Output is correct
12 Correct 666 ms 178420 KB Output is correct
13 Correct 520 ms 173328 KB Output is correct
14 Correct 546 ms 173688 KB Output is correct
15 Correct 516 ms 173348 KB Output is correct
16 Correct 512 ms 173512 KB Output is correct
17 Correct 559 ms 174064 KB Output is correct
18 Correct 39 ms 67596 KB Output is correct
19 Correct 39 ms 67660 KB Output is correct
20 Correct 41 ms 67692 KB Output is correct
21 Correct 39 ms 67648 KB Output is correct
22 Correct 39 ms 67664 KB Output is correct
23 Correct 37 ms 67652 KB Output is correct
24 Correct 699 ms 178076 KB Output is correct
25 Correct 787 ms 178524 KB Output is correct
26 Correct 669 ms 191524 KB Output is correct
27 Correct 674 ms 178056 KB Output is correct
28 Correct 710 ms 176864 KB Output is correct
29 Correct 662 ms 175464 KB Output is correct
30 Correct 571 ms 172088 KB Output is correct
31 Correct 692 ms 189876 KB Output is correct
32 Correct 767 ms 191452 KB Output is correct
33 Correct 676 ms 177840 KB Output is correct
34 Correct 790 ms 178484 KB Output is correct
35 Correct 38 ms 67672 KB Output is correct
36 Correct 39 ms 67660 KB Output is correct
37 Correct 37 ms 67584 KB Output is correct
38 Correct 38 ms 67648 KB Output is correct
39 Correct 38 ms 67668 KB Output is correct
40 Correct 37 ms 67660 KB Output is correct
41 Correct 37 ms 67632 KB Output is correct
42 Correct 37 ms 67640 KB Output is correct
43 Correct 37 ms 67652 KB Output is correct
44 Correct 40 ms 67672 KB Output is correct
45 Correct 38 ms 67780 KB Output is correct
46 Correct 41 ms 67684 KB Output is correct
47 Correct 39 ms 67636 KB Output is correct
48 Correct 40 ms 67636 KB Output is correct
49 Correct 37 ms 67660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 67668 KB Output is correct
2 Execution timed out 4073 ms 180856 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4090 ms 67532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4062 ms 67620 KB Time limit exceeded
2 Halted 0 ms 0 KB -