Submission #697994

# Submission time Handle Problem Language Result Execution time Memory
697994 2023-02-11T17:57:18 Z Cross_Ratio None (JOI16_ho_t5) C++14
100 / 100
684 ms 28804 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e18;
array<int, 3> A[200005];//0 is type ->, 1 is type up
struct SegTree {
    struct Node {
        int ma, p;
        Node():ma(-INF), p(0){}
        Node(int _m) : ma(_m), p(0) {}
    };
    vector<Node> seg;
    int MAX;
    SegTree(int N) {
        int i;
        for(i=1;i<2*N;i*=2) {}
        seg.resize(i);
        MAX = i;
    }
    void cons() {
        for(int i = MAX/2-1;i>=1;i--) {
            seg[i].ma = max(seg[2*i].ma, seg[2*i+1].ma);
        }
    }
    void prop(int n, int ns, int ne) {
        if(seg[n].p) {
            seg[n].ma += seg[n].p;
            if(n<MAX/2) {
                seg[2*n].p += seg[n].p;
                seg[2*n+1].p += seg[n].p;
            }
            seg[n].p = 0;
        }
    }
    void add(int s, int e, int k, int n, int ns, int ne) {
        prop(n,ns,ne);
        if(e<=ns||ne<=s) return;
        if(s<=ns&&ne<=e) {
            seg[n].p += k;
            prop(n,ns,ne);
            return;
        }
        int mid = ns + ne >> 1;
        add(s, e, k, 2*n, ns, mid);
        add(s, e, k, 2*n+1, mid, ne);
        if(n<MAX/2) seg[n].p = max(seg[2*n].p, seg[2*n+1].p);
    }
    int sum(int s, int e, int n, int ns, int ne) {
        prop(n,ns,ne);
        if(e<=ns||ne<=s) return -INF;
        if(s<=ns&&ne<=e) return seg[n].ma;
        int mid = ns + ne >> 1;
        return max(sum(s, e, 2*n, ns, mid), sum(s, e, 2*n+1, mid, ne));
    }
    int find_left(int L, int N) {
        if(sum(0, N, 1, 0, MAX/2) < L) return N;
        int s = 0, e = N;
        while(s+1<e) {
            int mid = (s+e)/2;
            if(sum(0, mid, 1, 0, MAX/2) < L) s = mid;
            else e = mid;
        }
        return s;
    }
    int find_right(int R, int N) {
        if(sum(0, N, 1, 0, MAX/2) < R) return -1;
        int s = 0, e = N;
        while(s+1<e) {
            int mid = (s+e)/2;
            if(sum(mid, N, 1, 0, MAX/2) < R) e = mid;
            else s = mid;
        }
        return s;
    }
};
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N, Q;
    cin >> N >> Q;
    int i, j;
    for(i=0;i<Q;i++) {
        int a, b, c;
        cin >> a >> b >> c;
        if(b==1) A[i] = {0, 4*c, -2*a};
        if(b==2) A[i] = {1, 2*a, 4*c};
    }
    reverse(A, A+Q);
    SegTree tx(N+3), ty(N+3);
    int MAX = tx.MAX;
    for(i=0;i<N;i++) {
        tx.seg[i+MAX/2].ma = 2*i+1;
        ty.seg[i+MAX/2].ma = -2*i-1;
    }
    tx.cons();
    ty.cons();
    //cout << "Start\n";
    for(j=0;j<Q;j++) {
        if(A[j][0]==0) {
            int pt = ty.find_right(A[j][2], N);
            tx.add(0, pt+1, -A[j][1], 1, 0, MAX/2);
        }
        else {
            int pt = tx.find_left(A[j][1], N);
            ty.add(pt, N, -A[j][2], 1, 0, MAX/2);
        }
    }
    for(i=0;i<N;i++) {
        int x = tx.sum(i, i+1, 1, 0, MAX/2);
        int y = ty.sum(i, i+1, 1, 0, MAX/2);
        cout << -(x+y)/4 << '\n';
    }
}

Compilation message

2016_ho_t5.cpp: In member function 'void SegTree::add(long long int, long long int, long long int, long long int, long long int, long long int)':
2016_ho_t5.cpp:43:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |         int mid = ns + ne >> 1;
      |                   ~~~^~~~
2016_ho_t5.cpp: In member function 'long long int SegTree::sum(long long int, long long int, long long int, long long int, long long int)':
2016_ho_t5.cpp:52:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |         int mid = ns + ne >> 1;
      |                   ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 5 ms 596 KB Output is correct
29 Correct 4 ms 592 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 4 ms 644 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 5 ms 596 KB Output is correct
34 Correct 4 ms 596 KB Output is correct
35 Correct 4 ms 596 KB Output is correct
36 Correct 5 ms 596 KB Output is correct
37 Correct 5 ms 724 KB Output is correct
38 Correct 4 ms 724 KB Output is correct
39 Correct 4 ms 688 KB Output is correct
40 Correct 4 ms 640 KB Output is correct
41 Correct 4 ms 720 KB Output is correct
42 Correct 4 ms 720 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 3 ms 728 KB Output is correct
47 Correct 4 ms 724 KB Output is correct
48 Correct 6 ms 724 KB Output is correct
49 Correct 8 ms 704 KB Output is correct
50 Correct 5 ms 596 KB Output is correct
51 Correct 5 ms 596 KB Output is correct
52 Correct 6 ms 724 KB Output is correct
53 Correct 6 ms 596 KB Output is correct
54 Correct 6 ms 724 KB Output is correct
55 Correct 6 ms 636 KB Output is correct
56 Correct 6 ms 724 KB Output is correct
57 Correct 6 ms 596 KB Output is correct
58 Correct 7 ms 724 KB Output is correct
59 Correct 5 ms 596 KB Output is correct
60 Correct 6 ms 724 KB Output is correct
61 Correct 6 ms 592 KB Output is correct
62 Correct 4 ms 728 KB Output is correct
63 Correct 6 ms 596 KB Output is correct
64 Correct 6 ms 724 KB Output is correct
65 Correct 7 ms 596 KB Output is correct
66 Correct 6 ms 720 KB Output is correct
67 Correct 6 ms 700 KB Output is correct
68 Correct 6 ms 724 KB Output is correct
69 Correct 6 ms 596 KB Output is correct
70 Correct 1 ms 596 KB Output is correct
71 Correct 1 ms 596 KB Output is correct
72 Correct 1 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 5 ms 596 KB Output is correct
29 Correct 4 ms 592 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 4 ms 644 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 5 ms 596 KB Output is correct
34 Correct 4 ms 596 KB Output is correct
35 Correct 4 ms 596 KB Output is correct
36 Correct 5 ms 596 KB Output is correct
37 Correct 5 ms 724 KB Output is correct
38 Correct 4 ms 724 KB Output is correct
39 Correct 4 ms 688 KB Output is correct
40 Correct 4 ms 640 KB Output is correct
41 Correct 4 ms 720 KB Output is correct
42 Correct 4 ms 720 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 3 ms 728 KB Output is correct
47 Correct 4 ms 724 KB Output is correct
48 Correct 6 ms 724 KB Output is correct
49 Correct 8 ms 704 KB Output is correct
50 Correct 5 ms 596 KB Output is correct
51 Correct 5 ms 596 KB Output is correct
52 Correct 6 ms 724 KB Output is correct
53 Correct 6 ms 596 KB Output is correct
54 Correct 6 ms 724 KB Output is correct
55 Correct 6 ms 636 KB Output is correct
56 Correct 6 ms 724 KB Output is correct
57 Correct 6 ms 596 KB Output is correct
58 Correct 7 ms 724 KB Output is correct
59 Correct 5 ms 596 KB Output is correct
60 Correct 6 ms 724 KB Output is correct
61 Correct 6 ms 592 KB Output is correct
62 Correct 4 ms 728 KB Output is correct
63 Correct 6 ms 596 KB Output is correct
64 Correct 6 ms 724 KB Output is correct
65 Correct 7 ms 596 KB Output is correct
66 Correct 6 ms 720 KB Output is correct
67 Correct 6 ms 700 KB Output is correct
68 Correct 6 ms 724 KB Output is correct
69 Correct 6 ms 596 KB Output is correct
70 Correct 1 ms 596 KB Output is correct
71 Correct 1 ms 596 KB Output is correct
72 Correct 1 ms 580 KB Output is correct
73 Correct 626 ms 23612 KB Output is correct
74 Correct 615 ms 24732 KB Output is correct
75 Correct 595 ms 25036 KB Output is correct
76 Correct 594 ms 25016 KB Output is correct
77 Correct 537 ms 24864 KB Output is correct
78 Correct 508 ms 24860 KB Output is correct
79 Correct 462 ms 24976 KB Output is correct
80 Correct 351 ms 25284 KB Output is correct
81 Correct 347 ms 25536 KB Output is correct
82 Correct 339 ms 25620 KB Output is correct
83 Correct 378 ms 26396 KB Output is correct
84 Correct 369 ms 26384 KB Output is correct
85 Correct 358 ms 26392 KB Output is correct
86 Correct 248 ms 26868 KB Output is correct
87 Correct 216 ms 27564 KB Output is correct
88 Correct 275 ms 28688 KB Output is correct
89 Correct 286 ms 28804 KB Output is correct
90 Correct 459 ms 27240 KB Output is correct
91 Correct 440 ms 23920 KB Output is correct
92 Correct 476 ms 24116 KB Output is correct
93 Correct 681 ms 27484 KB Output is correct
94 Correct 671 ms 24764 KB Output is correct
95 Correct 494 ms 26748 KB Output is correct
96 Correct 484 ms 24760 KB Output is correct
97 Correct 623 ms 25792 KB Output is correct
98 Correct 656 ms 24576 KB Output is correct
99 Correct 623 ms 26600 KB Output is correct
100 Correct 609 ms 24636 KB Output is correct
101 Correct 640 ms 26032 KB Output is correct
102 Correct 667 ms 24760 KB Output is correct
103 Correct 580 ms 26656 KB Output is correct
104 Correct 582 ms 24636 KB Output is correct
105 Correct 587 ms 26244 KB Output is correct
106 Correct 594 ms 24732 KB Output is correct
107 Correct 427 ms 26648 KB Output is correct
108 Correct 614 ms 24668 KB Output is correct
109 Correct 610 ms 26156 KB Output is correct
110 Correct 594 ms 24876 KB Output is correct
111 Correct 684 ms 27808 KB Output is correct
112 Correct 635 ms 24892 KB Output is correct
113 Correct 634 ms 28120 KB Output is correct
114 Correct 632 ms 24876 KB Output is correct
115 Correct 629 ms 25256 KB Output is correct
116 Correct 638 ms 24876 KB Output is correct
117 Correct 645 ms 28072 KB Output is correct
118 Correct 633 ms 25148 KB Output is correct
119 Correct 69 ms 18892 KB Output is correct
120 Correct 64 ms 17068 KB Output is correct