Submission #548253

# Submission time Handle Problem Language Result Execution time Memory
548253 2022-04-12T19:34:58 Z duality Sprinkler (JOI22_sprinkler) C++17
41 / 100
4000 ms 156800 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 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;
}

Compilation message

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
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 4 ms 5016 KB Output is correct
4 Correct 6 ms 5716 KB Output is correct
5 Correct 6 ms 5692 KB Output is correct
6 Correct 5 ms 5668 KB Output is correct
7 Correct 5 ms 5688 KB Output is correct
8 Correct 4 ms 5724 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 4 ms 5020 KB Output is correct
14 Correct 3 ms 5028 KB Output is correct
15 Correct 4 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5076 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 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4988 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 568 ms 155332 KB Output is correct
3 Correct 828 ms 153332 KB Output is correct
4 Correct 663 ms 153008 KB Output is correct
5 Correct 649 ms 155324 KB Output is correct
6 Correct 653 ms 152672 KB Output is correct
7 Correct 664 ms 153512 KB Output is correct
8 Correct 853 ms 154912 KB Output is correct
9 Correct 562 ms 153792 KB Output is correct
10 Correct 810 ms 152780 KB Output is correct
11 Correct 546 ms 153936 KB Output is correct
12 Correct 787 ms 150716 KB Output is correct
13 Correct 951 ms 156724 KB Output is correct
14 Correct 972 ms 156032 KB Output is correct
15 Correct 1037 ms 146916 KB Output is correct
16 Correct 1136 ms 150140 KB Output is correct
17 Correct 1117 ms 150200 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 5 ms 5028 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 5 ms 5024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 568 ms 155332 KB Output is correct
3 Correct 828 ms 153332 KB Output is correct
4 Correct 663 ms 153008 KB Output is correct
5 Correct 649 ms 155324 KB Output is correct
6 Correct 653 ms 152672 KB Output is correct
7 Correct 664 ms 153512 KB Output is correct
8 Correct 853 ms 154912 KB Output is correct
9 Correct 562 ms 153792 KB Output is correct
10 Correct 810 ms 152780 KB Output is correct
11 Correct 546 ms 153936 KB Output is correct
12 Correct 787 ms 150716 KB Output is correct
13 Correct 951 ms 156724 KB Output is correct
14 Correct 972 ms 156032 KB Output is correct
15 Correct 1037 ms 146916 KB Output is correct
16 Correct 1136 ms 150140 KB Output is correct
17 Correct 1117 ms 150200 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 5 ms 5028 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 5 ms 5024 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 712 ms 155720 KB Output is correct
25 Correct 1285 ms 154940 KB Output is correct
26 Correct 893 ms 155796 KB Output is correct
27 Correct 883 ms 155096 KB Output is correct
28 Correct 885 ms 155840 KB Output is correct
29 Correct 921 ms 155616 KB Output is correct
30 Correct 1016 ms 156800 KB Output is correct
31 Correct 708 ms 155316 KB Output is correct
32 Correct 1227 ms 155216 KB Output is correct
33 Correct 798 ms 155388 KB Output is correct
34 Correct 1336 ms 155568 KB Output is correct
35 Correct 4 ms 4948 KB Output is correct
36 Correct 4 ms 4948 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 4 ms 5024 KB Output is correct
39 Correct 4 ms 5024 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 5020 KB Output is correct
42 Correct 4 ms 4948 KB Output is correct
43 Correct 4 ms 5068 KB Output is correct
44 Correct 4 ms 4948 KB Output is correct
45 Correct 3 ms 5028 KB Output is correct
46 Correct 4 ms 4948 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 4 ms 5020 KB Output is correct
49 Correct 4 ms 5020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 1566 ms 152040 KB Output is correct
3 Execution timed out 4046 ms 150504 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 1678 ms 154208 KB Output is correct
3 Execution timed out 4048 ms 150628 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 4 ms 5016 KB Output is correct
4 Correct 6 ms 5716 KB Output is correct
5 Correct 6 ms 5692 KB Output is correct
6 Correct 5 ms 5668 KB Output is correct
7 Correct 5 ms 5688 KB Output is correct
8 Correct 4 ms 5724 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 4 ms 5020 KB Output is correct
14 Correct 3 ms 5028 KB Output is correct
15 Correct 4 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5076 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 3 ms 4948 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 3 ms 4988 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 568 ms 155332 KB Output is correct
31 Correct 828 ms 153332 KB Output is correct
32 Correct 663 ms 153008 KB Output is correct
33 Correct 649 ms 155324 KB Output is correct
34 Correct 653 ms 152672 KB Output is correct
35 Correct 664 ms 153512 KB Output is correct
36 Correct 853 ms 154912 KB Output is correct
37 Correct 562 ms 153792 KB Output is correct
38 Correct 810 ms 152780 KB Output is correct
39 Correct 546 ms 153936 KB Output is correct
40 Correct 787 ms 150716 KB Output is correct
41 Correct 951 ms 156724 KB Output is correct
42 Correct 972 ms 156032 KB Output is correct
43 Correct 1037 ms 146916 KB Output is correct
44 Correct 1136 ms 150140 KB Output is correct
45 Correct 1117 ms 150200 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 4 ms 4948 KB Output is correct
48 Correct 5 ms 5028 KB Output is correct
49 Correct 4 ms 4948 KB Output is correct
50 Correct 5 ms 5024 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 712 ms 155720 KB Output is correct
53 Correct 1285 ms 154940 KB Output is correct
54 Correct 893 ms 155796 KB Output is correct
55 Correct 883 ms 155096 KB Output is correct
56 Correct 885 ms 155840 KB Output is correct
57 Correct 921 ms 155616 KB Output is correct
58 Correct 1016 ms 156800 KB Output is correct
59 Correct 708 ms 155316 KB Output is correct
60 Correct 1227 ms 155216 KB Output is correct
61 Correct 798 ms 155388 KB Output is correct
62 Correct 1336 ms 155568 KB Output is correct
63 Correct 4 ms 4948 KB Output is correct
64 Correct 4 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 4 ms 5024 KB Output is correct
67 Correct 4 ms 5024 KB Output is correct
68 Correct 3 ms 4948 KB Output is correct
69 Correct 3 ms 5020 KB Output is correct
70 Correct 4 ms 4948 KB Output is correct
71 Correct 4 ms 5068 KB Output is correct
72 Correct 4 ms 4948 KB Output is correct
73 Correct 3 ms 5028 KB Output is correct
74 Correct 4 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 4 ms 5020 KB Output is correct
77 Correct 4 ms 5020 KB Output is correct
78 Correct 3 ms 4948 KB Output is correct
79 Correct 1566 ms 152040 KB Output is correct
80 Execution timed out 4046 ms 150504 KB Time limit exceeded
81 Halted 0 ms 0 KB -