답안 #312625

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
312625 2020-10-13T21:48:14 Z giorgikob Interval Collection (CCO20_day2problem2) C++14
7 / 25
2660 ms 291148 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);
    }
    if(x == -2 || y == -2){
        answer = 1e9;
        return ;
    }
    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 66 ms 95096 KB Output is correct
2 Correct 64 ms 94840 KB Output is correct
3 Correct 64 ms 94840 KB Output is correct
4 Correct 64 ms 94840 KB Output is correct
5 Correct 64 ms 95096 KB Output is correct
6 Correct 65 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 63 ms 95096 KB Output is correct
11 Correct 65 ms 95096 KB Output is correct
12 Correct 66 ms 95064 KB Output is correct
13 Correct 65 ms 95224 KB Output is correct
14 Correct 65 ms 95352 KB Output is correct
15 Correct 64 ms 95352 KB Output is correct
16 Correct 65 ms 95352 KB Output is correct
17 Correct 64 ms 94968 KB Output is correct
18 Correct 63 ms 94840 KB Output is correct
19 Correct 65 ms 94712 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 94840 KB Output is correct
23 Correct 63 ms 94712 KB Output is correct
24 Correct 66 ms 94840 KB Output is correct
25 Correct 66 ms 95228 KB Output is correct
26 Correct 64 ms 95096 KB Output is correct
27 Correct 64 ms 95100 KB Output is correct
28 Correct 67 ms 95096 KB Output is correct
29 Correct 65 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 64 ms 95228 KB Output is correct
33 Correct 64 ms 94840 KB Output is correct
34 Correct 63 ms 94840 KB Output is correct
35 Correct 70 ms 94840 KB Output is correct
36 Correct 64 ms 94840 KB Output is correct
37 Correct 64 ms 94840 KB Output is correct
38 Correct 65 ms 94792 KB Output is correct
39 Correct 66 ms 94840 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 94956 KB Output is correct
43 Correct 64 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 66 ms 94840 KB Output is correct
48 Correct 64 ms 94840 KB Output is correct
49 Correct 63 ms 94524 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 94584 KB Output is correct
53 Correct 62 ms 94584 KB Output is correct
54 Correct 64 ms 94584 KB Output is correct
55 Correct 66 ms 94584 KB Output is correct
56 Correct 71 ms 94588 KB Output is correct
57 Correct 63 ms 94584 KB Output is correct
58 Correct 62 ms 94584 KB Output is correct
59 Correct 63 ms 94840 KB Output is correct
60 Correct 64 ms 94840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 95096 KB Output is correct
2 Correct 64 ms 94840 KB Output is correct
3 Correct 64 ms 94840 KB Output is correct
4 Correct 64 ms 94840 KB Output is correct
5 Correct 64 ms 95096 KB Output is correct
6 Correct 65 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 63 ms 95096 KB Output is correct
11 Correct 65 ms 95096 KB Output is correct
12 Correct 66 ms 95064 KB Output is correct
13 Correct 65 ms 95224 KB Output is correct
14 Correct 65 ms 95352 KB Output is correct
15 Correct 64 ms 95352 KB Output is correct
16 Correct 65 ms 95352 KB Output is correct
17 Correct 64 ms 94968 KB Output is correct
18 Correct 63 ms 94840 KB Output is correct
19 Correct 65 ms 94712 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 94840 KB Output is correct
23 Correct 63 ms 94712 KB Output is correct
24 Correct 66 ms 94840 KB Output is correct
25 Correct 66 ms 95228 KB Output is correct
26 Correct 64 ms 95096 KB Output is correct
27 Correct 64 ms 95100 KB Output is correct
28 Correct 67 ms 95096 KB Output is correct
29 Correct 65 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 64 ms 95228 KB Output is correct
33 Correct 64 ms 94840 KB Output is correct
34 Correct 63 ms 94840 KB Output is correct
35 Correct 70 ms 94840 KB Output is correct
36 Correct 64 ms 94840 KB Output is correct
37 Correct 64 ms 94840 KB Output is correct
38 Correct 65 ms 94792 KB Output is correct
39 Correct 66 ms 94840 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 94956 KB Output is correct
43 Correct 64 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 66 ms 94840 KB Output is correct
48 Correct 64 ms 94840 KB Output is correct
49 Correct 63 ms 94524 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 94584 KB Output is correct
53 Correct 62 ms 94584 KB Output is correct
54 Correct 64 ms 94584 KB Output is correct
55 Correct 66 ms 94584 KB Output is correct
56 Correct 71 ms 94588 KB Output is correct
57 Correct 63 ms 94584 KB Output is correct
58 Correct 62 ms 94584 KB Output is correct
59 Correct 63 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 63 ms 94204 KB Output is correct
63 Correct 60 ms 94328 KB Output is correct
64 Correct 139 ms 105464 KB Output is correct
65 Correct 127 ms 102572 KB Output is correct
66 Correct 122 ms 101804 KB Output is correct
67 Correct 114 ms 101880 KB Output is correct
68 Correct 144 ms 105592 KB Output is correct
69 Correct 129 ms 102648 KB Output is correct
70 Correct 123 ms 102000 KB Output is correct
71 Correct 121 ms 101872 KB Output is correct
72 Correct 146 ms 107672 KB Output is correct
73 Correct 144 ms 106488 KB Output is correct
74 Correct 143 ms 106488 KB Output is correct
75 Correct 142 ms 106232 KB Output is correct
76 Correct 150 ms 109048 KB Output is correct
77 Correct 149 ms 109048 KB Output is correct
78 Correct 149 ms 109048 KB Output is correct
79 Correct 146 ms 109048 KB Output is correct
80 Correct 138 ms 105080 KB Output is correct
81 Correct 128 ms 102248 KB Output is correct
82 Correct 123 ms 101620 KB Output is correct
83 Correct 117 ms 101752 KB Output is correct
84 Correct 138 ms 105236 KB Output is correct
85 Correct 138 ms 102284 KB Output is correct
86 Correct 125 ms 101624 KB Output is correct
87 Correct 120 ms 101496 KB Output is correct
88 Correct 145 ms 107256 KB Output is correct
89 Correct 167 ms 106232 KB Output is correct
90 Correct 143 ms 105720 KB Output is correct
91 Correct 147 ms 105916 KB Output is correct
92 Correct 146 ms 108536 KB Output is correct
93 Correct 150 ms 108536 KB Output is correct
94 Correct 149 ms 108280 KB Output is correct
95 Correct 147 ms 108664 KB Output is correct
96 Correct 115 ms 101752 KB Output is correct
97 Correct 118 ms 101740 KB Output is correct
98 Correct 114 ms 101752 KB Output is correct
99 Correct 114 ms 101752 KB Output is correct
100 Correct 121 ms 101880 KB Output is correct
101 Incorrect 120 ms 101752 KB Output isn't correct
102 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 95096 KB Output is correct
2 Correct 64 ms 94840 KB Output is correct
3 Correct 64 ms 94840 KB Output is correct
4 Correct 64 ms 94840 KB Output is correct
5 Correct 64 ms 95096 KB Output is correct
6 Correct 65 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 63 ms 95096 KB Output is correct
11 Correct 65 ms 95096 KB Output is correct
12 Correct 66 ms 95064 KB Output is correct
13 Correct 65 ms 95224 KB Output is correct
14 Correct 65 ms 95352 KB Output is correct
15 Correct 64 ms 95352 KB Output is correct
16 Correct 65 ms 95352 KB Output is correct
17 Correct 64 ms 94968 KB Output is correct
18 Correct 63 ms 94840 KB Output is correct
19 Correct 65 ms 94712 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 94840 KB Output is correct
23 Correct 63 ms 94712 KB Output is correct
24 Correct 66 ms 94840 KB Output is correct
25 Correct 66 ms 95228 KB Output is correct
26 Correct 64 ms 95096 KB Output is correct
27 Correct 64 ms 95100 KB Output is correct
28 Correct 67 ms 95096 KB Output is correct
29 Correct 65 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 64 ms 95228 KB Output is correct
33 Correct 64 ms 94840 KB Output is correct
34 Correct 63 ms 94840 KB Output is correct
35 Correct 70 ms 94840 KB Output is correct
36 Correct 64 ms 94840 KB Output is correct
37 Correct 64 ms 94840 KB Output is correct
38 Correct 65 ms 94792 KB Output is correct
39 Correct 66 ms 94840 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 94956 KB Output is correct
43 Correct 64 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 66 ms 94840 KB Output is correct
48 Correct 64 ms 94840 KB Output is correct
49 Correct 63 ms 94524 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 94584 KB Output is correct
53 Correct 62 ms 94584 KB Output is correct
54 Correct 64 ms 94584 KB Output is correct
55 Correct 66 ms 94584 KB Output is correct
56 Correct 71 ms 94588 KB Output is correct
57 Correct 63 ms 94584 KB Output is correct
58 Correct 62 ms 94584 KB Output is correct
59 Correct 63 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 63 ms 94204 KB Output is correct
63 Correct 60 ms 94328 KB Output is correct
64 Correct 139 ms 105464 KB Output is correct
65 Correct 127 ms 102572 KB Output is correct
66 Correct 122 ms 101804 KB Output is correct
67 Correct 114 ms 101880 KB Output is correct
68 Correct 144 ms 105592 KB Output is correct
69 Correct 129 ms 102648 KB Output is correct
70 Correct 123 ms 102000 KB Output is correct
71 Correct 121 ms 101872 KB Output is correct
72 Correct 146 ms 107672 KB Output is correct
73 Correct 144 ms 106488 KB Output is correct
74 Correct 143 ms 106488 KB Output is correct
75 Correct 142 ms 106232 KB Output is correct
76 Correct 150 ms 109048 KB Output is correct
77 Correct 149 ms 109048 KB Output is correct
78 Correct 149 ms 109048 KB Output is correct
79 Correct 146 ms 109048 KB Output is correct
80 Correct 138 ms 105080 KB Output is correct
81 Correct 128 ms 102248 KB Output is correct
82 Correct 123 ms 101620 KB Output is correct
83 Correct 117 ms 101752 KB Output is correct
84 Correct 138 ms 105236 KB Output is correct
85 Correct 138 ms 102284 KB Output is correct
86 Correct 125 ms 101624 KB Output is correct
87 Correct 120 ms 101496 KB Output is correct
88 Correct 145 ms 107256 KB Output is correct
89 Correct 167 ms 106232 KB Output is correct
90 Correct 143 ms 105720 KB Output is correct
91 Correct 147 ms 105916 KB Output is correct
92 Correct 146 ms 108536 KB Output is correct
93 Correct 150 ms 108536 KB Output is correct
94 Correct 149 ms 108280 KB Output is correct
95 Correct 147 ms 108664 KB Output is correct
96 Correct 115 ms 101752 KB Output is correct
97 Correct 118 ms 101740 KB Output is correct
98 Correct 114 ms 101752 KB Output is correct
99 Correct 114 ms 101752 KB Output is correct
100 Correct 121 ms 101880 KB Output is correct
101 Incorrect 120 ms 101752 KB Output isn't correct
102 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 999 ms 199032 KB Output is correct
2 Correct 1008 ms 199032 KB Output is correct
3 Correct 1834 ms 245624 KB Output is correct
4 Correct 1912 ms 245556 KB Output is correct
5 Correct 2291 ms 283804 KB Output is correct
6 Correct 2353 ms 291148 KB Output is correct
7 Correct 2503 ms 113964 KB Output is correct
8 Correct 1968 ms 103544 KB Output is correct
9 Correct 1937 ms 102988 KB Output is correct
10 Correct 2614 ms 119528 KB Output is correct
11 Correct 2001 ms 103800 KB Output is correct
12 Correct 1951 ms 103160 KB Output is correct
13 Correct 2660 ms 122260 KB Output is correct
14 Correct 1991 ms 103928 KB Output is correct
15 Correct 1940 ms 103048 KB Output is correct
16 Correct 2008 ms 150648 KB Output is correct
17 Correct 2017 ms 150528 KB Output is correct
18 Correct 2017 ms 150520 KB Output is correct
19 Correct 2025 ms 151132 KB Output is correct
20 Correct 2012 ms 150520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 95096 KB Output is correct
2 Correct 64 ms 94840 KB Output is correct
3 Correct 64 ms 94840 KB Output is correct
4 Correct 64 ms 94840 KB Output is correct
5 Correct 64 ms 95096 KB Output is correct
6 Correct 65 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 63 ms 95096 KB Output is correct
11 Correct 65 ms 95096 KB Output is correct
12 Correct 66 ms 95064 KB Output is correct
13 Correct 65 ms 95224 KB Output is correct
14 Correct 65 ms 95352 KB Output is correct
15 Correct 64 ms 95352 KB Output is correct
16 Correct 65 ms 95352 KB Output is correct
17 Correct 64 ms 94968 KB Output is correct
18 Correct 63 ms 94840 KB Output is correct
19 Correct 65 ms 94712 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 94840 KB Output is correct
23 Correct 63 ms 94712 KB Output is correct
24 Correct 66 ms 94840 KB Output is correct
25 Correct 66 ms 95228 KB Output is correct
26 Correct 64 ms 95096 KB Output is correct
27 Correct 64 ms 95100 KB Output is correct
28 Correct 67 ms 95096 KB Output is correct
29 Correct 65 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 64 ms 95228 KB Output is correct
33 Correct 64 ms 94840 KB Output is correct
34 Correct 63 ms 94840 KB Output is correct
35 Correct 70 ms 94840 KB Output is correct
36 Correct 64 ms 94840 KB Output is correct
37 Correct 64 ms 94840 KB Output is correct
38 Correct 65 ms 94792 KB Output is correct
39 Correct 66 ms 94840 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 94956 KB Output is correct
43 Correct 64 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 66 ms 94840 KB Output is correct
48 Correct 64 ms 94840 KB Output is correct
49 Correct 63 ms 94524 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 94584 KB Output is correct
53 Correct 62 ms 94584 KB Output is correct
54 Correct 64 ms 94584 KB Output is correct
55 Correct 66 ms 94584 KB Output is correct
56 Correct 71 ms 94588 KB Output is correct
57 Correct 63 ms 94584 KB Output is correct
58 Correct 62 ms 94584 KB Output is correct
59 Correct 63 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 63 ms 94204 KB Output is correct
63 Correct 60 ms 94328 KB Output is correct
64 Correct 139 ms 105464 KB Output is correct
65 Correct 127 ms 102572 KB Output is correct
66 Correct 122 ms 101804 KB Output is correct
67 Correct 114 ms 101880 KB Output is correct
68 Correct 144 ms 105592 KB Output is correct
69 Correct 129 ms 102648 KB Output is correct
70 Correct 123 ms 102000 KB Output is correct
71 Correct 121 ms 101872 KB Output is correct
72 Correct 146 ms 107672 KB Output is correct
73 Correct 144 ms 106488 KB Output is correct
74 Correct 143 ms 106488 KB Output is correct
75 Correct 142 ms 106232 KB Output is correct
76 Correct 150 ms 109048 KB Output is correct
77 Correct 149 ms 109048 KB Output is correct
78 Correct 149 ms 109048 KB Output is correct
79 Correct 146 ms 109048 KB Output is correct
80 Correct 138 ms 105080 KB Output is correct
81 Correct 128 ms 102248 KB Output is correct
82 Correct 123 ms 101620 KB Output is correct
83 Correct 117 ms 101752 KB Output is correct
84 Correct 138 ms 105236 KB Output is correct
85 Correct 138 ms 102284 KB Output is correct
86 Correct 125 ms 101624 KB Output is correct
87 Correct 120 ms 101496 KB Output is correct
88 Correct 145 ms 107256 KB Output is correct
89 Correct 167 ms 106232 KB Output is correct
90 Correct 143 ms 105720 KB Output is correct
91 Correct 147 ms 105916 KB Output is correct
92 Correct 146 ms 108536 KB Output is correct
93 Correct 150 ms 108536 KB Output is correct
94 Correct 149 ms 108280 KB Output is correct
95 Correct 147 ms 108664 KB Output is correct
96 Correct 115 ms 101752 KB Output is correct
97 Correct 118 ms 101740 KB Output is correct
98 Correct 114 ms 101752 KB Output is correct
99 Correct 114 ms 101752 KB Output is correct
100 Correct 121 ms 101880 KB Output is correct
101 Incorrect 120 ms 101752 KB Output isn't correct
102 Halted 0 ms 0 KB -