Submission #312631

# Submission time Handle Problem Language Result Execution time Memory
312631 2020-10-13T22:12:54 Z giorgikob Interval Collection (CCO20_day2problem2) C++14
7 / 25
2705 ms 283388 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;

const int N = 1e6+5;

struct bla{
    bla *left = NULL, *right = NULL;
    int answer = 1e9;
    int l = -1;
    int r = -1;
};


multiset<int>b[N],e[N],L,R;

inline void go(int x,int y,int &l,int &r,int &answer){
    if(x != -1){
        if(x == -2) l = -1; else
        if(l == -1) l = x; else l = max(l, x);
    }
    if(y != -1){
        if(y == -2) r = -1; else
        if(r == -1) r = y; else r = min(r, y);
    }
    answer = 1e9;
    if(l != -1 && r != -1){
        answer = r - l;
    }
}

inline int mn(int x,int y){
    if(x == -1) return y;
    if(y == -1) return x;
    return min(x,y);
}

inline int mx(int x,int y){
    if(x == -1) return y;
    if(y == -1) return x;
    return max(x,y);
}

inline int get(int y,int x){
    if(x == -1 || y == -1){
        return 1e9;
    }
    return y - x;
}

inline void upd(bla* &node,int tl,int tr,int pos,int x,int y){

    if(tl == tr){
        go(x,y,node->l,node->r,node->answer);
        return ;
    }

    int mid = tl + tr; mid >>= 1;

    if(node->left == NULL)node->left = new bla();
    if(node->right == NULL)node->right = new bla();

    if(pos <= mid){
        upd(node->left,tl,mid,pos,x,y);
    } else {
        upd(node->right,mid+1,tr,pos,x,y);
    }

    node->l = mx(node->left->l,node->right->l);
    node->r = mn(node->left->r,node->right->r);

    node->answer = get(node->right->r, node->left->l);
    node->answer = min(node->answer, min(node->left->answer, node->right->answer));
}

int main(){
    ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

    bla* root = new bla();

    int q;
    cin >> q;
    while(q--){
        char c;
        int l,r;
        cin >> c >> l >> r;
        if(c == 'A'){
            b[l].insert(r);
            e[r].insert(l);
            L.insert(l);
            R.insert(r);
        } else {
            b[l].erase(b[l].find(r));
            e[r].erase(e[r].find(l));
            L.erase(L.find(l));
            R.erase(R.find(r));
        }

        int val;
        if(b[l].size()) val = *b[l].begin(); else val = -2;
        upd(root,1,N-1,l,-1,val); //cout << val << endl;

        if(e[r].size()) val = *e[r].rbegin(); else val = -2;
        upd(root,1,N-1,r,val,-1); //cout << val << endl;

        if(L.size() == 0){
            cout << 0 << endl;
            continue;
        }

        int x = *L.rbegin();
        int y = *R.begin();
        if(x <= y){
            cout << (*b[x].begin() - *e[y].rbegin()) << endl;
        } else {
            //cout << "second : ";
            cout << root->answer << endl;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 65 ms 95096 KB Output is correct
2 Correct 63 ms 94840 KB Output is correct
3 Correct 63 ms 94976 KB Output is correct
4 Correct 65 ms 94840 KB Output is correct
5 Correct 63 ms 95096 KB Output is correct
6 Correct 66 ms 94840 KB Output is correct
7 Correct 63 ms 94840 KB Output is correct
8 Correct 63 ms 94840 KB Output is correct
9 Correct 64 ms 95224 KB Output is correct
10 Correct 64 ms 95096 KB Output is correct
11 Correct 65 ms 95096 KB Output is correct
12 Correct 64 ms 95096 KB Output is correct
13 Correct 65 ms 95288 KB Output is correct
14 Correct 64 ms 95352 KB Output is correct
15 Correct 65 ms 95352 KB Output is correct
16 Correct 64 ms 95224 KB Output is correct
17 Correct 65 ms 94968 KB Output is correct
18 Correct 66 ms 95096 KB Output is correct
19 Correct 63 ms 94712 KB Output is correct
20 Correct 63 ms 94712 KB Output is correct
21 Correct 66 ms 94968 KB Output is correct
22 Correct 65 ms 94872 KB Output is correct
23 Correct 65 ms 94840 KB Output is correct
24 Correct 66 ms 94840 KB Output is correct
25 Correct 64 ms 95196 KB Output is correct
26 Correct 65 ms 95100 KB Output is correct
27 Correct 64 ms 95096 KB Output is correct
28 Correct 65 ms 95096 KB Output is correct
29 Correct 64 ms 95224 KB Output is correct
30 Correct 65 ms 95224 KB Output is correct
31 Correct 65 ms 95224 KB Output is correct
32 Correct 66 ms 95224 KB Output is correct
33 Correct 63 ms 94712 KB Output is correct
34 Correct 63 ms 94712 KB Output is correct
35 Correct 63 ms 94840 KB Output is correct
36 Correct 63 ms 94712 KB Output is correct
37 Correct 65 ms 94840 KB Output is correct
38 Correct 63 ms 94840 KB Output is correct
39 Correct 63 ms 94712 KB Output is correct
40 Correct 64 ms 94840 KB Output is correct
41 Correct 64 ms 94968 KB Output is correct
42 Correct 63 ms 94840 KB Output is correct
43 Correct 64 ms 94840 KB Output is correct
44 Correct 63 ms 94712 KB Output is correct
45 Correct 64 ms 94840 KB Output is correct
46 Correct 64 ms 94840 KB Output is correct
47 Correct 63 ms 94840 KB Output is correct
48 Correct 63 ms 94744 KB Output is correct
49 Correct 63 ms 94584 KB Output is correct
50 Correct 63 ms 94584 KB Output is correct
51 Correct 63 ms 94584 KB Output is correct
52 Correct 63 ms 94576 KB Output is correct
53 Correct 64 ms 94584 KB Output is correct
54 Correct 62 ms 94588 KB Output is correct
55 Correct 62 ms 94584 KB Output is correct
56 Correct 62 ms 94584 KB Output is correct
57 Correct 64 ms 94584 KB Output is correct
58 Correct 64 ms 94584 KB Output is correct
59 Correct 64 ms 94840 KB Output is correct
60 Correct 62 ms 94840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 95096 KB Output is correct
2 Correct 63 ms 94840 KB Output is correct
3 Correct 63 ms 94976 KB Output is correct
4 Correct 65 ms 94840 KB Output is correct
5 Correct 63 ms 95096 KB Output is correct
6 Correct 66 ms 94840 KB Output is correct
7 Correct 63 ms 94840 KB Output is correct
8 Correct 63 ms 94840 KB Output is correct
9 Correct 64 ms 95224 KB Output is correct
10 Correct 64 ms 95096 KB Output is correct
11 Correct 65 ms 95096 KB Output is correct
12 Correct 64 ms 95096 KB Output is correct
13 Correct 65 ms 95288 KB Output is correct
14 Correct 64 ms 95352 KB Output is correct
15 Correct 65 ms 95352 KB Output is correct
16 Correct 64 ms 95224 KB Output is correct
17 Correct 65 ms 94968 KB Output is correct
18 Correct 66 ms 95096 KB Output is correct
19 Correct 63 ms 94712 KB Output is correct
20 Correct 63 ms 94712 KB Output is correct
21 Correct 66 ms 94968 KB Output is correct
22 Correct 65 ms 94872 KB Output is correct
23 Correct 65 ms 94840 KB Output is correct
24 Correct 66 ms 94840 KB Output is correct
25 Correct 64 ms 95196 KB Output is correct
26 Correct 65 ms 95100 KB Output is correct
27 Correct 64 ms 95096 KB Output is correct
28 Correct 65 ms 95096 KB Output is correct
29 Correct 64 ms 95224 KB Output is correct
30 Correct 65 ms 95224 KB Output is correct
31 Correct 65 ms 95224 KB Output is correct
32 Correct 66 ms 95224 KB Output is correct
33 Correct 63 ms 94712 KB Output is correct
34 Correct 63 ms 94712 KB Output is correct
35 Correct 63 ms 94840 KB Output is correct
36 Correct 63 ms 94712 KB Output is correct
37 Correct 65 ms 94840 KB Output is correct
38 Correct 63 ms 94840 KB Output is correct
39 Correct 63 ms 94712 KB Output is correct
40 Correct 64 ms 94840 KB Output is correct
41 Correct 64 ms 94968 KB Output is correct
42 Correct 63 ms 94840 KB Output is correct
43 Correct 64 ms 94840 KB Output is correct
44 Correct 63 ms 94712 KB Output is correct
45 Correct 64 ms 94840 KB Output is correct
46 Correct 64 ms 94840 KB Output is correct
47 Correct 63 ms 94840 KB Output is correct
48 Correct 63 ms 94744 KB Output is correct
49 Correct 63 ms 94584 KB Output is correct
50 Correct 63 ms 94584 KB Output is correct
51 Correct 63 ms 94584 KB Output is correct
52 Correct 63 ms 94576 KB Output is correct
53 Correct 64 ms 94584 KB Output is correct
54 Correct 62 ms 94588 KB Output is correct
55 Correct 62 ms 94584 KB Output is correct
56 Correct 62 ms 94584 KB Output is correct
57 Correct 64 ms 94584 KB Output is correct
58 Correct 64 ms 94584 KB Output is correct
59 Correct 64 ms 94840 KB Output is correct
60 Correct 62 ms 94840 KB Output is correct
61 Correct 60 ms 94200 KB Output is correct
62 Correct 62 ms 94200 KB Output is correct
63 Correct 63 ms 94200 KB Output is correct
64 Correct 139 ms 105276 KB Output is correct
65 Correct 129 ms 102400 KB Output is correct
66 Correct 127 ms 101496 KB Output is correct
67 Correct 115 ms 101624 KB Output is correct
68 Correct 141 ms 105320 KB Output is correct
69 Correct 132 ms 102392 KB Output is correct
70 Correct 124 ms 101752 KB Output is correct
71 Correct 120 ms 101624 KB Output is correct
72 Correct 143 ms 107512 KB Output is correct
73 Correct 143 ms 106360 KB Output is correct
74 Correct 140 ms 106232 KB Output is correct
75 Correct 142 ms 106076 KB Output is correct
76 Correct 150 ms 108792 KB Output is correct
77 Correct 148 ms 108792 KB Output is correct
78 Correct 149 ms 108920 KB Output is correct
79 Correct 149 ms 108792 KB Output is correct
80 Correct 145 ms 104824 KB Output is correct
81 Correct 130 ms 102012 KB Output is correct
82 Correct 124 ms 101400 KB Output is correct
83 Correct 115 ms 101624 KB Output is correct
84 Correct 138 ms 105032 KB Output is correct
85 Correct 128 ms 102136 KB Output is correct
86 Correct 122 ms 101496 KB Output is correct
87 Correct 122 ms 101372 KB Output is correct
88 Correct 142 ms 107004 KB Output is correct
89 Correct 140 ms 105976 KB Output is correct
90 Correct 139 ms 105500 KB Output is correct
91 Correct 141 ms 105592 KB Output is correct
92 Correct 151 ms 108280 KB Output is correct
93 Correct 152 ms 108280 KB Output is correct
94 Correct 147 ms 108120 KB Output is correct
95 Correct 148 ms 108408 KB Output is correct
96 Correct 116 ms 101624 KB Output is correct
97 Correct 116 ms 101624 KB Output is correct
98 Correct 116 ms 101496 KB Output is correct
99 Correct 114 ms 101500 KB Output is correct
100 Correct 122 ms 101624 KB Output is correct
101 Incorrect 118 ms 101624 KB Output isn't correct
102 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 65 ms 95096 KB Output is correct
2 Correct 63 ms 94840 KB Output is correct
3 Correct 63 ms 94976 KB Output is correct
4 Correct 65 ms 94840 KB Output is correct
5 Correct 63 ms 95096 KB Output is correct
6 Correct 66 ms 94840 KB Output is correct
7 Correct 63 ms 94840 KB Output is correct
8 Correct 63 ms 94840 KB Output is correct
9 Correct 64 ms 95224 KB Output is correct
10 Correct 64 ms 95096 KB Output is correct
11 Correct 65 ms 95096 KB Output is correct
12 Correct 64 ms 95096 KB Output is correct
13 Correct 65 ms 95288 KB Output is correct
14 Correct 64 ms 95352 KB Output is correct
15 Correct 65 ms 95352 KB Output is correct
16 Correct 64 ms 95224 KB Output is correct
17 Correct 65 ms 94968 KB Output is correct
18 Correct 66 ms 95096 KB Output is correct
19 Correct 63 ms 94712 KB Output is correct
20 Correct 63 ms 94712 KB Output is correct
21 Correct 66 ms 94968 KB Output is correct
22 Correct 65 ms 94872 KB Output is correct
23 Correct 65 ms 94840 KB Output is correct
24 Correct 66 ms 94840 KB Output is correct
25 Correct 64 ms 95196 KB Output is correct
26 Correct 65 ms 95100 KB Output is correct
27 Correct 64 ms 95096 KB Output is correct
28 Correct 65 ms 95096 KB Output is correct
29 Correct 64 ms 95224 KB Output is correct
30 Correct 65 ms 95224 KB Output is correct
31 Correct 65 ms 95224 KB Output is correct
32 Correct 66 ms 95224 KB Output is correct
33 Correct 63 ms 94712 KB Output is correct
34 Correct 63 ms 94712 KB Output is correct
35 Correct 63 ms 94840 KB Output is correct
36 Correct 63 ms 94712 KB Output is correct
37 Correct 65 ms 94840 KB Output is correct
38 Correct 63 ms 94840 KB Output is correct
39 Correct 63 ms 94712 KB Output is correct
40 Correct 64 ms 94840 KB Output is correct
41 Correct 64 ms 94968 KB Output is correct
42 Correct 63 ms 94840 KB Output is correct
43 Correct 64 ms 94840 KB Output is correct
44 Correct 63 ms 94712 KB Output is correct
45 Correct 64 ms 94840 KB Output is correct
46 Correct 64 ms 94840 KB Output is correct
47 Correct 63 ms 94840 KB Output is correct
48 Correct 63 ms 94744 KB Output is correct
49 Correct 63 ms 94584 KB Output is correct
50 Correct 63 ms 94584 KB Output is correct
51 Correct 63 ms 94584 KB Output is correct
52 Correct 63 ms 94576 KB Output is correct
53 Correct 64 ms 94584 KB Output is correct
54 Correct 62 ms 94588 KB Output is correct
55 Correct 62 ms 94584 KB Output is correct
56 Correct 62 ms 94584 KB Output is correct
57 Correct 64 ms 94584 KB Output is correct
58 Correct 64 ms 94584 KB Output is correct
59 Correct 64 ms 94840 KB Output is correct
60 Correct 62 ms 94840 KB Output is correct
61 Correct 60 ms 94200 KB Output is correct
62 Correct 62 ms 94200 KB Output is correct
63 Correct 63 ms 94200 KB Output is correct
64 Correct 139 ms 105276 KB Output is correct
65 Correct 129 ms 102400 KB Output is correct
66 Correct 127 ms 101496 KB Output is correct
67 Correct 115 ms 101624 KB Output is correct
68 Correct 141 ms 105320 KB Output is correct
69 Correct 132 ms 102392 KB Output is correct
70 Correct 124 ms 101752 KB Output is correct
71 Correct 120 ms 101624 KB Output is correct
72 Correct 143 ms 107512 KB Output is correct
73 Correct 143 ms 106360 KB Output is correct
74 Correct 140 ms 106232 KB Output is correct
75 Correct 142 ms 106076 KB Output is correct
76 Correct 150 ms 108792 KB Output is correct
77 Correct 148 ms 108792 KB Output is correct
78 Correct 149 ms 108920 KB Output is correct
79 Correct 149 ms 108792 KB Output is correct
80 Correct 145 ms 104824 KB Output is correct
81 Correct 130 ms 102012 KB Output is correct
82 Correct 124 ms 101400 KB Output is correct
83 Correct 115 ms 101624 KB Output is correct
84 Correct 138 ms 105032 KB Output is correct
85 Correct 128 ms 102136 KB Output is correct
86 Correct 122 ms 101496 KB Output is correct
87 Correct 122 ms 101372 KB Output is correct
88 Correct 142 ms 107004 KB Output is correct
89 Correct 140 ms 105976 KB Output is correct
90 Correct 139 ms 105500 KB Output is correct
91 Correct 141 ms 105592 KB Output is correct
92 Correct 151 ms 108280 KB Output is correct
93 Correct 152 ms 108280 KB Output is correct
94 Correct 147 ms 108120 KB Output is correct
95 Correct 148 ms 108408 KB Output is correct
96 Correct 116 ms 101624 KB Output is correct
97 Correct 116 ms 101624 KB Output is correct
98 Correct 116 ms 101496 KB Output is correct
99 Correct 114 ms 101500 KB Output is correct
100 Correct 122 ms 101624 KB Output is correct
101 Incorrect 118 ms 101624 KB Output isn't correct
102 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 994 ms 199116 KB Output is correct
2 Correct 1012 ms 199032 KB Output is correct
3 Correct 1868 ms 245496 KB Output is correct
4 Correct 1901 ms 245440 KB Output is correct
5 Correct 2313 ms 283388 KB Output is correct
6 Correct 2358 ms 283128 KB Output is correct
7 Correct 2557 ms 107000 KB Output is correct
8 Correct 2009 ms 97784 KB Output is correct
9 Correct 1981 ms 97144 KB Output is correct
10 Correct 2625 ms 112760 KB Output is correct
11 Correct 2017 ms 97912 KB Output is correct
12 Correct 1959 ms 97144 KB Output is correct
13 Correct 2705 ms 115320 KB Output is correct
14 Correct 2047 ms 97836 KB Output is correct
15 Correct 1959 ms 97248 KB Output is correct
16 Correct 2021 ms 143736 KB Output is correct
17 Correct 2021 ms 143864 KB Output is correct
18 Correct 2024 ms 143864 KB Output is correct
19 Correct 2037 ms 144504 KB Output is correct
20 Correct 2021 ms 143864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 95096 KB Output is correct
2 Correct 63 ms 94840 KB Output is correct
3 Correct 63 ms 94976 KB Output is correct
4 Correct 65 ms 94840 KB Output is correct
5 Correct 63 ms 95096 KB Output is correct
6 Correct 66 ms 94840 KB Output is correct
7 Correct 63 ms 94840 KB Output is correct
8 Correct 63 ms 94840 KB Output is correct
9 Correct 64 ms 95224 KB Output is correct
10 Correct 64 ms 95096 KB Output is correct
11 Correct 65 ms 95096 KB Output is correct
12 Correct 64 ms 95096 KB Output is correct
13 Correct 65 ms 95288 KB Output is correct
14 Correct 64 ms 95352 KB Output is correct
15 Correct 65 ms 95352 KB Output is correct
16 Correct 64 ms 95224 KB Output is correct
17 Correct 65 ms 94968 KB Output is correct
18 Correct 66 ms 95096 KB Output is correct
19 Correct 63 ms 94712 KB Output is correct
20 Correct 63 ms 94712 KB Output is correct
21 Correct 66 ms 94968 KB Output is correct
22 Correct 65 ms 94872 KB Output is correct
23 Correct 65 ms 94840 KB Output is correct
24 Correct 66 ms 94840 KB Output is correct
25 Correct 64 ms 95196 KB Output is correct
26 Correct 65 ms 95100 KB Output is correct
27 Correct 64 ms 95096 KB Output is correct
28 Correct 65 ms 95096 KB Output is correct
29 Correct 64 ms 95224 KB Output is correct
30 Correct 65 ms 95224 KB Output is correct
31 Correct 65 ms 95224 KB Output is correct
32 Correct 66 ms 95224 KB Output is correct
33 Correct 63 ms 94712 KB Output is correct
34 Correct 63 ms 94712 KB Output is correct
35 Correct 63 ms 94840 KB Output is correct
36 Correct 63 ms 94712 KB Output is correct
37 Correct 65 ms 94840 KB Output is correct
38 Correct 63 ms 94840 KB Output is correct
39 Correct 63 ms 94712 KB Output is correct
40 Correct 64 ms 94840 KB Output is correct
41 Correct 64 ms 94968 KB Output is correct
42 Correct 63 ms 94840 KB Output is correct
43 Correct 64 ms 94840 KB Output is correct
44 Correct 63 ms 94712 KB Output is correct
45 Correct 64 ms 94840 KB Output is correct
46 Correct 64 ms 94840 KB Output is correct
47 Correct 63 ms 94840 KB Output is correct
48 Correct 63 ms 94744 KB Output is correct
49 Correct 63 ms 94584 KB Output is correct
50 Correct 63 ms 94584 KB Output is correct
51 Correct 63 ms 94584 KB Output is correct
52 Correct 63 ms 94576 KB Output is correct
53 Correct 64 ms 94584 KB Output is correct
54 Correct 62 ms 94588 KB Output is correct
55 Correct 62 ms 94584 KB Output is correct
56 Correct 62 ms 94584 KB Output is correct
57 Correct 64 ms 94584 KB Output is correct
58 Correct 64 ms 94584 KB Output is correct
59 Correct 64 ms 94840 KB Output is correct
60 Correct 62 ms 94840 KB Output is correct
61 Correct 60 ms 94200 KB Output is correct
62 Correct 62 ms 94200 KB Output is correct
63 Correct 63 ms 94200 KB Output is correct
64 Correct 139 ms 105276 KB Output is correct
65 Correct 129 ms 102400 KB Output is correct
66 Correct 127 ms 101496 KB Output is correct
67 Correct 115 ms 101624 KB Output is correct
68 Correct 141 ms 105320 KB Output is correct
69 Correct 132 ms 102392 KB Output is correct
70 Correct 124 ms 101752 KB Output is correct
71 Correct 120 ms 101624 KB Output is correct
72 Correct 143 ms 107512 KB Output is correct
73 Correct 143 ms 106360 KB Output is correct
74 Correct 140 ms 106232 KB Output is correct
75 Correct 142 ms 106076 KB Output is correct
76 Correct 150 ms 108792 KB Output is correct
77 Correct 148 ms 108792 KB Output is correct
78 Correct 149 ms 108920 KB Output is correct
79 Correct 149 ms 108792 KB Output is correct
80 Correct 145 ms 104824 KB Output is correct
81 Correct 130 ms 102012 KB Output is correct
82 Correct 124 ms 101400 KB Output is correct
83 Correct 115 ms 101624 KB Output is correct
84 Correct 138 ms 105032 KB Output is correct
85 Correct 128 ms 102136 KB Output is correct
86 Correct 122 ms 101496 KB Output is correct
87 Correct 122 ms 101372 KB Output is correct
88 Correct 142 ms 107004 KB Output is correct
89 Correct 140 ms 105976 KB Output is correct
90 Correct 139 ms 105500 KB Output is correct
91 Correct 141 ms 105592 KB Output is correct
92 Correct 151 ms 108280 KB Output is correct
93 Correct 152 ms 108280 KB Output is correct
94 Correct 147 ms 108120 KB Output is correct
95 Correct 148 ms 108408 KB Output is correct
96 Correct 116 ms 101624 KB Output is correct
97 Correct 116 ms 101624 KB Output is correct
98 Correct 116 ms 101496 KB Output is correct
99 Correct 114 ms 101500 KB Output is correct
100 Correct 122 ms 101624 KB Output is correct
101 Incorrect 118 ms 101624 KB Output isn't correct
102 Halted 0 ms 0 KB -