Submission #548255

# Submission time Handle Problem Language Result Execution time Memory
548255 2022-04-12T19:40:49 Z duality Sprinkler (JOI22_sprinkler) C++17
100 / 100
3849 ms 156392 KB
#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

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
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 5 ms 5768 KB Output is correct
5 Correct 5 ms 5716 KB Output is correct
6 Correct 5 ms 5716 KB Output is correct
7 Correct 5 ms 5684 KB Output is correct
8 Correct 4 ms 5660 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5068 KB Output is correct
13 Correct 4 ms 4948 KB Output is correct
14 Correct 3 ms 5016 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5012 KB Output is correct
19 Correct 3 ms 5012 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 5 ms 4948 KB Output is correct
22 Correct 5 ms 5016 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5004 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 576 ms 150784 KB Output is correct
3 Correct 726 ms 147476 KB Output is correct
4 Correct 638 ms 149224 KB Output is correct
5 Correct 584 ms 149128 KB Output is correct
6 Correct 617 ms 149364 KB Output is correct
7 Correct 650 ms 149768 KB Output is correct
8 Correct 867 ms 150908 KB Output is correct
9 Correct 584 ms 150808 KB Output is correct
10 Correct 704 ms 147448 KB Output is correct
11 Correct 518 ms 150948 KB Output is correct
12 Correct 703 ms 147792 KB Output is correct
13 Correct 910 ms 148812 KB Output is correct
14 Correct 914 ms 148656 KB Output is correct
15 Correct 838 ms 146216 KB Output is correct
16 Correct 818 ms 148344 KB Output is correct
17 Correct 850 ms 148904 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 576 ms 150784 KB Output is correct
3 Correct 726 ms 147476 KB Output is correct
4 Correct 638 ms 149224 KB Output is correct
5 Correct 584 ms 149128 KB Output is correct
6 Correct 617 ms 149364 KB Output is correct
7 Correct 650 ms 149768 KB Output is correct
8 Correct 867 ms 150908 KB Output is correct
9 Correct 584 ms 150808 KB Output is correct
10 Correct 704 ms 147448 KB Output is correct
11 Correct 518 ms 150948 KB Output is correct
12 Correct 703 ms 147792 KB Output is correct
13 Correct 910 ms 148812 KB Output is correct
14 Correct 914 ms 148656 KB Output is correct
15 Correct 838 ms 146216 KB Output is correct
16 Correct 818 ms 148344 KB Output is correct
17 Correct 850 ms 148904 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 3 ms 5012 KB Output is correct
24 Correct 591 ms 150428 KB Output is correct
25 Correct 792 ms 146608 KB Output is correct
26 Correct 649 ms 147988 KB Output is correct
27 Correct 735 ms 147716 KB Output is correct
28 Correct 718 ms 147756 KB Output is correct
29 Correct 652 ms 147060 KB Output is correct
30 Correct 896 ms 148136 KB Output is correct
31 Correct 606 ms 148400 KB Output is correct
32 Correct 792 ms 144776 KB Output is correct
33 Correct 563 ms 148432 KB Output is correct
34 Correct 775 ms 144736 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5020 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 5076 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 5 ms 5020 KB Output is correct
41 Correct 4 ms 4948 KB Output is correct
42 Correct 4 ms 4948 KB Output is correct
43 Correct 4 ms 4948 KB Output is correct
44 Correct 4 ms 5072 KB Output is correct
45 Correct 3 ms 5016 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 5016 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 923 ms 145596 KB Output is correct
3 Correct 3632 ms 146628 KB Output is correct
4 Correct 1491 ms 151760 KB Output is correct
5 Correct 1502 ms 152136 KB Output is correct
6 Correct 1095 ms 152104 KB Output is correct
7 Correct 888 ms 152312 KB Output is correct
8 Correct 898 ms 153008 KB Output is correct
9 Correct 1006 ms 152132 KB Output is correct
10 Correct 3721 ms 152348 KB Output is correct
11 Correct 945 ms 151904 KB Output is correct
12 Correct 3849 ms 152276 KB Output is correct
13 Correct 3089 ms 152956 KB Output is correct
14 Correct 3293 ms 154040 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5020 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4996 KB Output is correct
2 Correct 988 ms 147124 KB Output is correct
3 Correct 3551 ms 146344 KB Output is correct
4 Correct 1488 ms 153304 KB Output is correct
5 Correct 1542 ms 153608 KB Output is correct
6 Correct 1027 ms 153964 KB Output is correct
7 Correct 933 ms 153720 KB Output is correct
8 Correct 919 ms 154720 KB Output is correct
9 Correct 985 ms 154600 KB Output is correct
10 Correct 3704 ms 152348 KB Output is correct
11 Correct 927 ms 154296 KB Output is correct
12 Correct 3612 ms 152704 KB Output is correct
13 Correct 2986 ms 153872 KB Output is correct
14 Correct 3289 ms 154236 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5016 KB Output is correct
17 Correct 3 ms 5016 KB Output is correct
18 Correct 4 ms 5012 KB Output is correct
19 Correct 3 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 5 ms 5768 KB Output is correct
5 Correct 5 ms 5716 KB Output is correct
6 Correct 5 ms 5716 KB Output is correct
7 Correct 5 ms 5684 KB Output is correct
8 Correct 4 ms 5660 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5068 KB Output is correct
13 Correct 4 ms 4948 KB Output is correct
14 Correct 3 ms 5016 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 4 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 5012 KB Output is correct
19 Correct 3 ms 5012 KB Output is correct
20 Correct 4 ms 4948 KB Output is correct
21 Correct 5 ms 4948 KB Output is correct
22 Correct 5 ms 5016 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 5004 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 576 ms 150784 KB Output is correct
31 Correct 726 ms 147476 KB Output is correct
32 Correct 638 ms 149224 KB Output is correct
33 Correct 584 ms 149128 KB Output is correct
34 Correct 617 ms 149364 KB Output is correct
35 Correct 650 ms 149768 KB Output is correct
36 Correct 867 ms 150908 KB Output is correct
37 Correct 584 ms 150808 KB Output is correct
38 Correct 704 ms 147448 KB Output is correct
39 Correct 518 ms 150948 KB Output is correct
40 Correct 703 ms 147792 KB Output is correct
41 Correct 910 ms 148812 KB Output is correct
42 Correct 914 ms 148656 KB Output is correct
43 Correct 838 ms 146216 KB Output is correct
44 Correct 818 ms 148344 KB Output is correct
45 Correct 850 ms 148904 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 4 ms 4948 KB Output is correct
51 Correct 3 ms 5012 KB Output is correct
52 Correct 591 ms 150428 KB Output is correct
53 Correct 792 ms 146608 KB Output is correct
54 Correct 649 ms 147988 KB Output is correct
55 Correct 735 ms 147716 KB Output is correct
56 Correct 718 ms 147756 KB Output is correct
57 Correct 652 ms 147060 KB Output is correct
58 Correct 896 ms 148136 KB Output is correct
59 Correct 606 ms 148400 KB Output is correct
60 Correct 792 ms 144776 KB Output is correct
61 Correct 563 ms 148432 KB Output is correct
62 Correct 775 ms 144736 KB Output is correct
63 Correct 3 ms 4948 KB Output is correct
64 Correct 3 ms 5020 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 ms 5076 KB Output is correct
67 Correct 3 ms 4948 KB Output is correct
68 Correct 5 ms 5020 KB Output is correct
69 Correct 4 ms 4948 KB Output is correct
70 Correct 4 ms 4948 KB Output is correct
71 Correct 4 ms 4948 KB Output is correct
72 Correct 4 ms 5072 KB Output is correct
73 Correct 3 ms 5016 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 3 ms 5016 KB Output is correct
77 Correct 3 ms 4948 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 923 ms 145596 KB Output is correct
80 Correct 3632 ms 146628 KB Output is correct
81 Correct 1491 ms 151760 KB Output is correct
82 Correct 1502 ms 152136 KB Output is correct
83 Correct 1095 ms 152104 KB Output is correct
84 Correct 888 ms 152312 KB Output is correct
85 Correct 898 ms 153008 KB Output is correct
86 Correct 1006 ms 152132 KB Output is correct
87 Correct 3721 ms 152348 KB Output is correct
88 Correct 945 ms 151904 KB Output is correct
89 Correct 3849 ms 152276 KB Output is correct
90 Correct 3089 ms 152956 KB Output is correct
91 Correct 3293 ms 154040 KB Output is correct
92 Correct 3 ms 4948 KB Output is correct
93 Correct 3 ms 5020 KB Output is correct
94 Correct 3 ms 4948 KB Output is correct
95 Correct 3 ms 4948 KB Output is correct
96 Correct 3 ms 5012 KB Output is correct
97 Correct 3 ms 4996 KB Output is correct
98 Correct 988 ms 147124 KB Output is correct
99 Correct 3551 ms 146344 KB Output is correct
100 Correct 1488 ms 153304 KB Output is correct
101 Correct 1542 ms 153608 KB Output is correct
102 Correct 1027 ms 153964 KB Output is correct
103 Correct 933 ms 153720 KB Output is correct
104 Correct 919 ms 154720 KB Output is correct
105 Correct 985 ms 154600 KB Output is correct
106 Correct 3704 ms 152348 KB Output is correct
107 Correct 927 ms 154296 KB Output is correct
108 Correct 3612 ms 152704 KB Output is correct
109 Correct 2986 ms 153872 KB Output is correct
110 Correct 3289 ms 154236 KB Output is correct
111 Correct 3 ms 4948 KB Output is correct
112 Correct 3 ms 5016 KB Output is correct
113 Correct 3 ms 5016 KB Output is correct
114 Correct 4 ms 5012 KB Output is correct
115 Correct 3 ms 5076 KB Output is correct
116 Correct 910 ms 152788 KB Output is correct
117 Correct 3471 ms 155508 KB Output is correct
118 Correct 1422 ms 154320 KB Output is correct
119 Correct 1401 ms 154944 KB Output is correct
120 Correct 1095 ms 154652 KB Output is correct
121 Correct 1085 ms 155660 KB Output is correct
122 Correct 924 ms 156392 KB Output is correct
123 Correct 901 ms 154964 KB Output is correct
124 Correct 3355 ms 154796 KB Output is correct
125 Correct 849 ms 153548 KB Output is correct
126 Correct 3285 ms 155348 KB Output is correct
127 Correct 3468 ms 155776 KB Output is correct
128 Correct 3097 ms 153112 KB Output is correct
129 Correct 3248 ms 145172 KB Output is correct