답안 #312629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
312629 2020-10-13T21:56:26 Z giorgikob Interval Collection (CCO20_day2problem2) C++14
7 / 25
2700 ms 283472 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].rbegin(); 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;
        }
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 95096 KB Output is correct
2 Correct 64 ms 94840 KB Output is correct
3 Correct 63 ms 94712 KB Output is correct
4 Correct 64 ms 94840 KB Output is correct
5 Correct 63 ms 95096 KB Output is correct
6 Correct 64 ms 94840 KB Output is correct
7 Correct 63 ms 94840 KB Output is correct
8 Correct 64 ms 94840 KB Output is correct
9 Correct 64 ms 95224 KB Output is correct
10 Correct 65 ms 95096 KB Output is correct
11 Correct 64 ms 95096 KB Output is correct
12 Correct 65 ms 95052 KB Output is correct
13 Correct 65 ms 95224 KB Output is correct
14 Correct 66 ms 95352 KB Output is correct
15 Correct 65 ms 95352 KB Output is correct
16 Correct 65 ms 95224 KB Output is correct
17 Correct 64 ms 94968 KB Output is correct
18 Correct 64 ms 94852 KB Output is correct
19 Correct 63 ms 94716 KB Output is correct
20 Correct 63 ms 94840 KB Output is correct
21 Correct 64 ms 94968 KB Output is correct
22 Correct 64 ms 94812 KB Output is correct
23 Correct 64 ms 94712 KB Output is correct
24 Correct 63 ms 94840 KB Output is correct
25 Correct 64 ms 95100 KB Output is correct
26 Correct 65 ms 95100 KB Output is correct
27 Correct 63 ms 95096 KB Output is correct
28 Correct 63 ms 95232 KB Output is correct
29 Correct 66 ms 95224 KB Output is correct
30 Correct 64 ms 95224 KB Output is correct
31 Correct 64 ms 95224 KB Output is correct
32 Correct 64 ms 95224 KB Output is correct
33 Correct 65 ms 94712 KB Output is correct
34 Correct 64 ms 94712 KB Output is correct
35 Correct 65 ms 94840 KB Output is correct
36 Correct 63 ms 94712 KB Output is correct
37 Correct 63 ms 94840 KB Output is correct
38 Correct 64 ms 94840 KB Output is correct
39 Correct 63 ms 94712 KB Output is correct
40 Correct 65 ms 94840 KB Output is correct
41 Correct 64 ms 94968 KB Output is correct
42 Correct 64 ms 94840 KB Output is correct
43 Correct 63 ms 94712 KB Output is correct
44 Correct 65 ms 94840 KB Output is correct
45 Correct 64 ms 94840 KB Output is correct
46 Correct 63 ms 94840 KB Output is correct
47 Correct 64 ms 94968 KB Output is correct
48 Correct 63 ms 94764 KB Output is correct
49 Correct 64 ms 94712 KB Output is correct
50 Correct 63 ms 94584 KB Output is correct
51 Correct 64 ms 94588 KB Output is correct
52 Correct 63 ms 94588 KB Output is correct
53 Correct 64 ms 94584 KB Output is correct
54 Correct 63 ms 94588 KB Output is correct
55 Correct 67 ms 94584 KB Output is correct
56 Correct 63 ms 94584 KB Output is correct
57 Correct 65 ms 94712 KB Output is correct
58 Correct 64 ms 94584 KB Output is correct
59 Correct 64 ms 94840 KB Output is correct
60 Correct 64 ms 94840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 95096 KB Output is correct
2 Correct 64 ms 94840 KB Output is correct
3 Correct 63 ms 94712 KB Output is correct
4 Correct 64 ms 94840 KB Output is correct
5 Correct 63 ms 95096 KB Output is correct
6 Correct 64 ms 94840 KB Output is correct
7 Correct 63 ms 94840 KB Output is correct
8 Correct 64 ms 94840 KB Output is correct
9 Correct 64 ms 95224 KB Output is correct
10 Correct 65 ms 95096 KB Output is correct
11 Correct 64 ms 95096 KB Output is correct
12 Correct 65 ms 95052 KB Output is correct
13 Correct 65 ms 95224 KB Output is correct
14 Correct 66 ms 95352 KB Output is correct
15 Correct 65 ms 95352 KB Output is correct
16 Correct 65 ms 95224 KB Output is correct
17 Correct 64 ms 94968 KB Output is correct
18 Correct 64 ms 94852 KB Output is correct
19 Correct 63 ms 94716 KB Output is correct
20 Correct 63 ms 94840 KB Output is correct
21 Correct 64 ms 94968 KB Output is correct
22 Correct 64 ms 94812 KB Output is correct
23 Correct 64 ms 94712 KB Output is correct
24 Correct 63 ms 94840 KB Output is correct
25 Correct 64 ms 95100 KB Output is correct
26 Correct 65 ms 95100 KB Output is correct
27 Correct 63 ms 95096 KB Output is correct
28 Correct 63 ms 95232 KB Output is correct
29 Correct 66 ms 95224 KB Output is correct
30 Correct 64 ms 95224 KB Output is correct
31 Correct 64 ms 95224 KB Output is correct
32 Correct 64 ms 95224 KB Output is correct
33 Correct 65 ms 94712 KB Output is correct
34 Correct 64 ms 94712 KB Output is correct
35 Correct 65 ms 94840 KB Output is correct
36 Correct 63 ms 94712 KB Output is correct
37 Correct 63 ms 94840 KB Output is correct
38 Correct 64 ms 94840 KB Output is correct
39 Correct 63 ms 94712 KB Output is correct
40 Correct 65 ms 94840 KB Output is correct
41 Correct 64 ms 94968 KB Output is correct
42 Correct 64 ms 94840 KB Output is correct
43 Correct 63 ms 94712 KB Output is correct
44 Correct 65 ms 94840 KB Output is correct
45 Correct 64 ms 94840 KB Output is correct
46 Correct 63 ms 94840 KB Output is correct
47 Correct 64 ms 94968 KB Output is correct
48 Correct 63 ms 94764 KB Output is correct
49 Correct 64 ms 94712 KB Output is correct
50 Correct 63 ms 94584 KB Output is correct
51 Correct 64 ms 94588 KB Output is correct
52 Correct 63 ms 94588 KB Output is correct
53 Correct 64 ms 94584 KB Output is correct
54 Correct 63 ms 94588 KB Output is correct
55 Correct 67 ms 94584 KB Output is correct
56 Correct 63 ms 94584 KB Output is correct
57 Correct 65 ms 94712 KB Output is correct
58 Correct 64 ms 94584 KB Output is correct
59 Correct 64 ms 94840 KB Output is correct
60 Correct 64 ms 94840 KB Output is correct
61 Correct 60 ms 94200 KB Output is correct
62 Correct 61 ms 94200 KB Output is correct
63 Correct 64 ms 94328 KB Output is correct
64 Correct 142 ms 105464 KB Output is correct
65 Correct 130 ms 102392 KB Output is correct
66 Correct 125 ms 101880 KB Output is correct
67 Correct 117 ms 101628 KB Output is correct
68 Correct 139 ms 105336 KB Output is correct
69 Correct 129 ms 102396 KB Output is correct
70 Correct 127 ms 101796 KB Output is correct
71 Correct 121 ms 101624 KB Output is correct
72 Correct 144 ms 107512 KB Output is correct
73 Correct 148 ms 106396 KB Output is correct
74 Correct 140 ms 106172 KB Output is correct
75 Correct 141 ms 105976 KB Output is correct
76 Correct 149 ms 108792 KB Output is correct
77 Correct 150 ms 108920 KB Output is correct
78 Correct 150 ms 108792 KB Output is correct
79 Correct 147 ms 108792 KB Output is correct
80 Correct 139 ms 104800 KB Output is correct
81 Correct 128 ms 101928 KB Output is correct
82 Correct 122 ms 101496 KB Output is correct
83 Correct 117 ms 101624 KB Output is correct
84 Correct 141 ms 105056 KB Output is correct
85 Correct 131 ms 102136 KB Output is correct
86 Correct 122 ms 101496 KB Output is correct
87 Correct 120 ms 101368 KB Output is correct
88 Correct 147 ms 107000 KB Output is correct
89 Correct 142 ms 105976 KB Output is correct
90 Correct 142 ms 105592 KB Output is correct
91 Correct 140 ms 105596 KB Output is correct
92 Correct 151 ms 108280 KB Output is correct
93 Correct 149 ms 108280 KB Output is correct
94 Correct 146 ms 108152 KB Output is correct
95 Correct 151 ms 108408 KB Output is correct
96 Correct 116 ms 101624 KB Output is correct
97 Correct 118 ms 101624 KB Output is correct
98 Correct 119 ms 101584 KB Output is correct
99 Correct 117 ms 101624 KB Output is correct
100 Correct 124 ms 101624 KB Output is correct
101 Incorrect 119 ms 101624 KB Output isn't correct
102 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 95096 KB Output is correct
2 Correct 64 ms 94840 KB Output is correct
3 Correct 63 ms 94712 KB Output is correct
4 Correct 64 ms 94840 KB Output is correct
5 Correct 63 ms 95096 KB Output is correct
6 Correct 64 ms 94840 KB Output is correct
7 Correct 63 ms 94840 KB Output is correct
8 Correct 64 ms 94840 KB Output is correct
9 Correct 64 ms 95224 KB Output is correct
10 Correct 65 ms 95096 KB Output is correct
11 Correct 64 ms 95096 KB Output is correct
12 Correct 65 ms 95052 KB Output is correct
13 Correct 65 ms 95224 KB Output is correct
14 Correct 66 ms 95352 KB Output is correct
15 Correct 65 ms 95352 KB Output is correct
16 Correct 65 ms 95224 KB Output is correct
17 Correct 64 ms 94968 KB Output is correct
18 Correct 64 ms 94852 KB Output is correct
19 Correct 63 ms 94716 KB Output is correct
20 Correct 63 ms 94840 KB Output is correct
21 Correct 64 ms 94968 KB Output is correct
22 Correct 64 ms 94812 KB Output is correct
23 Correct 64 ms 94712 KB Output is correct
24 Correct 63 ms 94840 KB Output is correct
25 Correct 64 ms 95100 KB Output is correct
26 Correct 65 ms 95100 KB Output is correct
27 Correct 63 ms 95096 KB Output is correct
28 Correct 63 ms 95232 KB Output is correct
29 Correct 66 ms 95224 KB Output is correct
30 Correct 64 ms 95224 KB Output is correct
31 Correct 64 ms 95224 KB Output is correct
32 Correct 64 ms 95224 KB Output is correct
33 Correct 65 ms 94712 KB Output is correct
34 Correct 64 ms 94712 KB Output is correct
35 Correct 65 ms 94840 KB Output is correct
36 Correct 63 ms 94712 KB Output is correct
37 Correct 63 ms 94840 KB Output is correct
38 Correct 64 ms 94840 KB Output is correct
39 Correct 63 ms 94712 KB Output is correct
40 Correct 65 ms 94840 KB Output is correct
41 Correct 64 ms 94968 KB Output is correct
42 Correct 64 ms 94840 KB Output is correct
43 Correct 63 ms 94712 KB Output is correct
44 Correct 65 ms 94840 KB Output is correct
45 Correct 64 ms 94840 KB Output is correct
46 Correct 63 ms 94840 KB Output is correct
47 Correct 64 ms 94968 KB Output is correct
48 Correct 63 ms 94764 KB Output is correct
49 Correct 64 ms 94712 KB Output is correct
50 Correct 63 ms 94584 KB Output is correct
51 Correct 64 ms 94588 KB Output is correct
52 Correct 63 ms 94588 KB Output is correct
53 Correct 64 ms 94584 KB Output is correct
54 Correct 63 ms 94588 KB Output is correct
55 Correct 67 ms 94584 KB Output is correct
56 Correct 63 ms 94584 KB Output is correct
57 Correct 65 ms 94712 KB Output is correct
58 Correct 64 ms 94584 KB Output is correct
59 Correct 64 ms 94840 KB Output is correct
60 Correct 64 ms 94840 KB Output is correct
61 Correct 60 ms 94200 KB Output is correct
62 Correct 61 ms 94200 KB Output is correct
63 Correct 64 ms 94328 KB Output is correct
64 Correct 142 ms 105464 KB Output is correct
65 Correct 130 ms 102392 KB Output is correct
66 Correct 125 ms 101880 KB Output is correct
67 Correct 117 ms 101628 KB Output is correct
68 Correct 139 ms 105336 KB Output is correct
69 Correct 129 ms 102396 KB Output is correct
70 Correct 127 ms 101796 KB Output is correct
71 Correct 121 ms 101624 KB Output is correct
72 Correct 144 ms 107512 KB Output is correct
73 Correct 148 ms 106396 KB Output is correct
74 Correct 140 ms 106172 KB Output is correct
75 Correct 141 ms 105976 KB Output is correct
76 Correct 149 ms 108792 KB Output is correct
77 Correct 150 ms 108920 KB Output is correct
78 Correct 150 ms 108792 KB Output is correct
79 Correct 147 ms 108792 KB Output is correct
80 Correct 139 ms 104800 KB Output is correct
81 Correct 128 ms 101928 KB Output is correct
82 Correct 122 ms 101496 KB Output is correct
83 Correct 117 ms 101624 KB Output is correct
84 Correct 141 ms 105056 KB Output is correct
85 Correct 131 ms 102136 KB Output is correct
86 Correct 122 ms 101496 KB Output is correct
87 Correct 120 ms 101368 KB Output is correct
88 Correct 147 ms 107000 KB Output is correct
89 Correct 142 ms 105976 KB Output is correct
90 Correct 142 ms 105592 KB Output is correct
91 Correct 140 ms 105596 KB Output is correct
92 Correct 151 ms 108280 KB Output is correct
93 Correct 149 ms 108280 KB Output is correct
94 Correct 146 ms 108152 KB Output is correct
95 Correct 151 ms 108408 KB Output is correct
96 Correct 116 ms 101624 KB Output is correct
97 Correct 118 ms 101624 KB Output is correct
98 Correct 119 ms 101584 KB Output is correct
99 Correct 117 ms 101624 KB Output is correct
100 Correct 124 ms 101624 KB Output is correct
101 Incorrect 119 ms 101624 KB Output isn't correct
102 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1004 ms 199000 KB Output is correct
2 Correct 1014 ms 199204 KB Output is correct
3 Correct 1839 ms 245476 KB Output is correct
4 Correct 1888 ms 245496 KB Output is correct
5 Correct 2331 ms 283472 KB Output is correct
6 Correct 2361 ms 283388 KB Output is correct
7 Correct 2521 ms 107000 KB Output is correct
8 Correct 2028 ms 97732 KB Output is correct
9 Correct 1979 ms 97148 KB Output is correct
10 Correct 2650 ms 112760 KB Output is correct
11 Correct 2024 ms 97792 KB Output is correct
12 Correct 1997 ms 97272 KB Output is correct
13 Correct 2700 ms 115704 KB Output is correct
14 Correct 2044 ms 97820 KB Output is correct
15 Correct 1993 ms 97316 KB Output is correct
16 Correct 2040 ms 143832 KB Output is correct
17 Correct 2048 ms 143608 KB Output is correct
18 Correct 2008 ms 143936 KB Output is correct
19 Correct 2041 ms 144632 KB Output is correct
20 Correct 2033 ms 143828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 95096 KB Output is correct
2 Correct 64 ms 94840 KB Output is correct
3 Correct 63 ms 94712 KB Output is correct
4 Correct 64 ms 94840 KB Output is correct
5 Correct 63 ms 95096 KB Output is correct
6 Correct 64 ms 94840 KB Output is correct
7 Correct 63 ms 94840 KB Output is correct
8 Correct 64 ms 94840 KB Output is correct
9 Correct 64 ms 95224 KB Output is correct
10 Correct 65 ms 95096 KB Output is correct
11 Correct 64 ms 95096 KB Output is correct
12 Correct 65 ms 95052 KB Output is correct
13 Correct 65 ms 95224 KB Output is correct
14 Correct 66 ms 95352 KB Output is correct
15 Correct 65 ms 95352 KB Output is correct
16 Correct 65 ms 95224 KB Output is correct
17 Correct 64 ms 94968 KB Output is correct
18 Correct 64 ms 94852 KB Output is correct
19 Correct 63 ms 94716 KB Output is correct
20 Correct 63 ms 94840 KB Output is correct
21 Correct 64 ms 94968 KB Output is correct
22 Correct 64 ms 94812 KB Output is correct
23 Correct 64 ms 94712 KB Output is correct
24 Correct 63 ms 94840 KB Output is correct
25 Correct 64 ms 95100 KB Output is correct
26 Correct 65 ms 95100 KB Output is correct
27 Correct 63 ms 95096 KB Output is correct
28 Correct 63 ms 95232 KB Output is correct
29 Correct 66 ms 95224 KB Output is correct
30 Correct 64 ms 95224 KB Output is correct
31 Correct 64 ms 95224 KB Output is correct
32 Correct 64 ms 95224 KB Output is correct
33 Correct 65 ms 94712 KB Output is correct
34 Correct 64 ms 94712 KB Output is correct
35 Correct 65 ms 94840 KB Output is correct
36 Correct 63 ms 94712 KB Output is correct
37 Correct 63 ms 94840 KB Output is correct
38 Correct 64 ms 94840 KB Output is correct
39 Correct 63 ms 94712 KB Output is correct
40 Correct 65 ms 94840 KB Output is correct
41 Correct 64 ms 94968 KB Output is correct
42 Correct 64 ms 94840 KB Output is correct
43 Correct 63 ms 94712 KB Output is correct
44 Correct 65 ms 94840 KB Output is correct
45 Correct 64 ms 94840 KB Output is correct
46 Correct 63 ms 94840 KB Output is correct
47 Correct 64 ms 94968 KB Output is correct
48 Correct 63 ms 94764 KB Output is correct
49 Correct 64 ms 94712 KB Output is correct
50 Correct 63 ms 94584 KB Output is correct
51 Correct 64 ms 94588 KB Output is correct
52 Correct 63 ms 94588 KB Output is correct
53 Correct 64 ms 94584 KB Output is correct
54 Correct 63 ms 94588 KB Output is correct
55 Correct 67 ms 94584 KB Output is correct
56 Correct 63 ms 94584 KB Output is correct
57 Correct 65 ms 94712 KB Output is correct
58 Correct 64 ms 94584 KB Output is correct
59 Correct 64 ms 94840 KB Output is correct
60 Correct 64 ms 94840 KB Output is correct
61 Correct 60 ms 94200 KB Output is correct
62 Correct 61 ms 94200 KB Output is correct
63 Correct 64 ms 94328 KB Output is correct
64 Correct 142 ms 105464 KB Output is correct
65 Correct 130 ms 102392 KB Output is correct
66 Correct 125 ms 101880 KB Output is correct
67 Correct 117 ms 101628 KB Output is correct
68 Correct 139 ms 105336 KB Output is correct
69 Correct 129 ms 102396 KB Output is correct
70 Correct 127 ms 101796 KB Output is correct
71 Correct 121 ms 101624 KB Output is correct
72 Correct 144 ms 107512 KB Output is correct
73 Correct 148 ms 106396 KB Output is correct
74 Correct 140 ms 106172 KB Output is correct
75 Correct 141 ms 105976 KB Output is correct
76 Correct 149 ms 108792 KB Output is correct
77 Correct 150 ms 108920 KB Output is correct
78 Correct 150 ms 108792 KB Output is correct
79 Correct 147 ms 108792 KB Output is correct
80 Correct 139 ms 104800 KB Output is correct
81 Correct 128 ms 101928 KB Output is correct
82 Correct 122 ms 101496 KB Output is correct
83 Correct 117 ms 101624 KB Output is correct
84 Correct 141 ms 105056 KB Output is correct
85 Correct 131 ms 102136 KB Output is correct
86 Correct 122 ms 101496 KB Output is correct
87 Correct 120 ms 101368 KB Output is correct
88 Correct 147 ms 107000 KB Output is correct
89 Correct 142 ms 105976 KB Output is correct
90 Correct 142 ms 105592 KB Output is correct
91 Correct 140 ms 105596 KB Output is correct
92 Correct 151 ms 108280 KB Output is correct
93 Correct 149 ms 108280 KB Output is correct
94 Correct 146 ms 108152 KB Output is correct
95 Correct 151 ms 108408 KB Output is correct
96 Correct 116 ms 101624 KB Output is correct
97 Correct 118 ms 101624 KB Output is correct
98 Correct 119 ms 101584 KB Output is correct
99 Correct 117 ms 101624 KB Output is correct
100 Correct 124 ms 101624 KB Output is correct
101 Incorrect 119 ms 101624 KB Output isn't correct
102 Halted 0 ms 0 KB -