답안 #309236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309236 2020-10-02T23:23:27 Z nikatamliani Interval Collection (CCO20_day2problem2) C++14
3 / 25
7000 ms 111232 KB
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int N = 1e6 + 5, oo = 1e9;
multiset < int > ms[2][N];
int tree[4 * N];
void update(int l, int r, int x, int val, int p) {
    if(l > x || r < x) return;
    if(l == r) {
        tree[p] = val;
    } else {
        int m = l + r >> 1;
        update(l, m, x, val, p << 1);
        update(m + 1, r, x, val, p << 1 | 1);
        tree[p] = min(tree[p << 1], tree[p << 1 | 1]);
    }
}
int query(int l, int r, int L, int R, int p) {
    if(L > r || l > R) return oo;
    if(L <= l && R >= r) return tree[p];
    int m = l + r >> 1;
    return min(query(l, m, L, R, p << 1), query(m + 1, r, L, R, p << 1 | 1));
}
int main() {
    for(int i = 0; i < 4 * N; ++i) tree[i] = oo;
    int q;
    cin >> q;
    multiset < pair < int, int > > m;
    for(int i = 1; i <= q; ++i) {
        int l, r;
        char t;
        cin >> t >> l >> r;
        if(t == 'R') {
            m.erase(m.find({l, r}));
            ms[0][l].erase(ms[0][l].find(r));
            ms[1][r].erase(ms[1][r].find(l));
            int val = oo;
            if(!ms[0][l].empty()) {
                val = *ms[0][l].begin();
            }
            update(1, N - 1, l, val, 1);
        } else {
            m.insert({l, r});
            ms[0][l].insert(r);
            ms[1][r].insert(l);
            update(1, N - 1, l, *ms[0][l].begin(), 1);
        }
        int maxL = -1, minR = 1e9;
        for(auto [l, r] : m) {
            maxL = max(maxL, l);
            minR = min(minR, r);
        }
        if(minR <= maxL) {
            int best = 1e9;
            for(auto [l, r] : m) {
                best = min(best, query(1, N - 1, r, N - 1, 1) - l); 
            }
            cout << best << '\n';
        } else {
            int ansL = -1, ansR = 1e9;
            ansR = *ms[0][maxL].begin();
            ansL = *ms[1][minR].rbegin();
            // for(auto [l, r] : m) {
            //     if(l == maxL) {
            //         ansR = min(ansR, r); 
            //     }
            //     if(r == minR) {
            //         ansL = max(ansL, l);
            //     }
            // }
            cout << ansR - ansL << '\n';
        }
    }
}

Compilation message

Main.cpp: In function 'void update(int, int, int, int, int)':
Main.cpp:13:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |         int m = l + r >> 1;
      |                 ~~^~~
Main.cpp: In function 'int query(int, int, int, int, int)':
Main.cpp:22:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |     int m = l + r >> 1;
      |             ~~^~~
Main.cpp: In function 'int main()':
Main.cpp:50:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |         for(auto [l, r] : m) {
      |                  ^
Main.cpp:56:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   56 |             for(auto [l, r] : m) {
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 109944 KB Output is correct
2 Correct 81 ms 109944 KB Output is correct
3 Correct 77 ms 109916 KB Output is correct
4 Correct 74 ms 109944 KB Output is correct
5 Correct 101 ms 109924 KB Output is correct
6 Correct 81 ms 109944 KB Output is correct
7 Correct 76 ms 109948 KB Output is correct
8 Correct 80 ms 109944 KB Output is correct
9 Correct 108 ms 109948 KB Output is correct
10 Correct 100 ms 109944 KB Output is correct
11 Correct 97 ms 109944 KB Output is correct
12 Correct 98 ms 110072 KB Output is correct
13 Correct 112 ms 110072 KB Output is correct
14 Correct 112 ms 109944 KB Output is correct
15 Correct 121 ms 110072 KB Output is correct
16 Correct 113 ms 109944 KB Output is correct
17 Correct 101 ms 110072 KB Output is correct
18 Correct 82 ms 109944 KB Output is correct
19 Correct 76 ms 109944 KB Output is correct
20 Correct 75 ms 109848 KB Output is correct
21 Correct 101 ms 109944 KB Output is correct
22 Correct 82 ms 109944 KB Output is correct
23 Correct 77 ms 109944 KB Output is correct
24 Correct 76 ms 109944 KB Output is correct
25 Correct 106 ms 109944 KB Output is correct
26 Correct 98 ms 110072 KB Output is correct
27 Correct 96 ms 109944 KB Output is correct
28 Correct 97 ms 109944 KB Output is correct
29 Correct 114 ms 109944 KB Output is correct
30 Correct 116 ms 109980 KB Output is correct
31 Correct 111 ms 110072 KB Output is correct
32 Correct 112 ms 110072 KB Output is correct
33 Correct 75 ms 109944 KB Output is correct
34 Correct 75 ms 109944 KB Output is correct
35 Correct 75 ms 109944 KB Output is correct
36 Correct 76 ms 109944 KB Output is correct
37 Correct 79 ms 109948 KB Output is correct
38 Correct 78 ms 109852 KB Output is correct
39 Correct 79 ms 109944 KB Output is correct
40 Correct 77 ms 109944 KB Output is correct
41 Correct 97 ms 109944 KB Output is correct
42 Correct 80 ms 109944 KB Output is correct
43 Correct 76 ms 109816 KB Output is correct
44 Correct 78 ms 109944 KB Output is correct
45 Correct 93 ms 109944 KB Output is correct
46 Correct 92 ms 109948 KB Output is correct
47 Correct 75 ms 109944 KB Output is correct
48 Correct 76 ms 109948 KB Output is correct
49 Correct 94 ms 109944 KB Output is correct
50 Correct 99 ms 109944 KB Output is correct
51 Correct 94 ms 110072 KB Output is correct
52 Correct 96 ms 109944 KB Output is correct
53 Correct 97 ms 110072 KB Output is correct
54 Correct 96 ms 109944 KB Output is correct
55 Correct 94 ms 109876 KB Output is correct
56 Correct 99 ms 109944 KB Output is correct
57 Correct 97 ms 109904 KB Output is correct
58 Correct 96 ms 110072 KB Output is correct
59 Correct 108 ms 110072 KB Output is correct
60 Correct 109 ms 109944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 109944 KB Output is correct
2 Correct 81 ms 109944 KB Output is correct
3 Correct 77 ms 109916 KB Output is correct
4 Correct 74 ms 109944 KB Output is correct
5 Correct 101 ms 109924 KB Output is correct
6 Correct 81 ms 109944 KB Output is correct
7 Correct 76 ms 109948 KB Output is correct
8 Correct 80 ms 109944 KB Output is correct
9 Correct 108 ms 109948 KB Output is correct
10 Correct 100 ms 109944 KB Output is correct
11 Correct 97 ms 109944 KB Output is correct
12 Correct 98 ms 110072 KB Output is correct
13 Correct 112 ms 110072 KB Output is correct
14 Correct 112 ms 109944 KB Output is correct
15 Correct 121 ms 110072 KB Output is correct
16 Correct 113 ms 109944 KB Output is correct
17 Correct 101 ms 110072 KB Output is correct
18 Correct 82 ms 109944 KB Output is correct
19 Correct 76 ms 109944 KB Output is correct
20 Correct 75 ms 109848 KB Output is correct
21 Correct 101 ms 109944 KB Output is correct
22 Correct 82 ms 109944 KB Output is correct
23 Correct 77 ms 109944 KB Output is correct
24 Correct 76 ms 109944 KB Output is correct
25 Correct 106 ms 109944 KB Output is correct
26 Correct 98 ms 110072 KB Output is correct
27 Correct 96 ms 109944 KB Output is correct
28 Correct 97 ms 109944 KB Output is correct
29 Correct 114 ms 109944 KB Output is correct
30 Correct 116 ms 109980 KB Output is correct
31 Correct 111 ms 110072 KB Output is correct
32 Correct 112 ms 110072 KB Output is correct
33 Correct 75 ms 109944 KB Output is correct
34 Correct 75 ms 109944 KB Output is correct
35 Correct 75 ms 109944 KB Output is correct
36 Correct 76 ms 109944 KB Output is correct
37 Correct 79 ms 109948 KB Output is correct
38 Correct 78 ms 109852 KB Output is correct
39 Correct 79 ms 109944 KB Output is correct
40 Correct 77 ms 109944 KB Output is correct
41 Correct 97 ms 109944 KB Output is correct
42 Correct 80 ms 109944 KB Output is correct
43 Correct 76 ms 109816 KB Output is correct
44 Correct 78 ms 109944 KB Output is correct
45 Correct 93 ms 109944 KB Output is correct
46 Correct 92 ms 109948 KB Output is correct
47 Correct 75 ms 109944 KB Output is correct
48 Correct 76 ms 109948 KB Output is correct
49 Correct 94 ms 109944 KB Output is correct
50 Correct 99 ms 109944 KB Output is correct
51 Correct 94 ms 110072 KB Output is correct
52 Correct 96 ms 109944 KB Output is correct
53 Correct 97 ms 110072 KB Output is correct
54 Correct 96 ms 109944 KB Output is correct
55 Correct 94 ms 109876 KB Output is correct
56 Correct 99 ms 109944 KB Output is correct
57 Correct 97 ms 109904 KB Output is correct
58 Correct 96 ms 110072 KB Output is correct
59 Correct 108 ms 110072 KB Output is correct
60 Correct 109 ms 109944 KB Output is correct
61 Correct 73 ms 109944 KB Output is correct
62 Correct 73 ms 109948 KB Output is correct
63 Correct 73 ms 109944 KB Output is correct
64 Execution timed out 7112 ms 111088 KB Time limit exceeded
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 109944 KB Output is correct
2 Correct 81 ms 109944 KB Output is correct
3 Correct 77 ms 109916 KB Output is correct
4 Correct 74 ms 109944 KB Output is correct
5 Correct 101 ms 109924 KB Output is correct
6 Correct 81 ms 109944 KB Output is correct
7 Correct 76 ms 109948 KB Output is correct
8 Correct 80 ms 109944 KB Output is correct
9 Correct 108 ms 109948 KB Output is correct
10 Correct 100 ms 109944 KB Output is correct
11 Correct 97 ms 109944 KB Output is correct
12 Correct 98 ms 110072 KB Output is correct
13 Correct 112 ms 110072 KB Output is correct
14 Correct 112 ms 109944 KB Output is correct
15 Correct 121 ms 110072 KB Output is correct
16 Correct 113 ms 109944 KB Output is correct
17 Correct 101 ms 110072 KB Output is correct
18 Correct 82 ms 109944 KB Output is correct
19 Correct 76 ms 109944 KB Output is correct
20 Correct 75 ms 109848 KB Output is correct
21 Correct 101 ms 109944 KB Output is correct
22 Correct 82 ms 109944 KB Output is correct
23 Correct 77 ms 109944 KB Output is correct
24 Correct 76 ms 109944 KB Output is correct
25 Correct 106 ms 109944 KB Output is correct
26 Correct 98 ms 110072 KB Output is correct
27 Correct 96 ms 109944 KB Output is correct
28 Correct 97 ms 109944 KB Output is correct
29 Correct 114 ms 109944 KB Output is correct
30 Correct 116 ms 109980 KB Output is correct
31 Correct 111 ms 110072 KB Output is correct
32 Correct 112 ms 110072 KB Output is correct
33 Correct 75 ms 109944 KB Output is correct
34 Correct 75 ms 109944 KB Output is correct
35 Correct 75 ms 109944 KB Output is correct
36 Correct 76 ms 109944 KB Output is correct
37 Correct 79 ms 109948 KB Output is correct
38 Correct 78 ms 109852 KB Output is correct
39 Correct 79 ms 109944 KB Output is correct
40 Correct 77 ms 109944 KB Output is correct
41 Correct 97 ms 109944 KB Output is correct
42 Correct 80 ms 109944 KB Output is correct
43 Correct 76 ms 109816 KB Output is correct
44 Correct 78 ms 109944 KB Output is correct
45 Correct 93 ms 109944 KB Output is correct
46 Correct 92 ms 109948 KB Output is correct
47 Correct 75 ms 109944 KB Output is correct
48 Correct 76 ms 109948 KB Output is correct
49 Correct 94 ms 109944 KB Output is correct
50 Correct 99 ms 109944 KB Output is correct
51 Correct 94 ms 110072 KB Output is correct
52 Correct 96 ms 109944 KB Output is correct
53 Correct 97 ms 110072 KB Output is correct
54 Correct 96 ms 109944 KB Output is correct
55 Correct 94 ms 109876 KB Output is correct
56 Correct 99 ms 109944 KB Output is correct
57 Correct 97 ms 109904 KB Output is correct
58 Correct 96 ms 110072 KB Output is correct
59 Correct 108 ms 110072 KB Output is correct
60 Correct 109 ms 109944 KB Output is correct
61 Correct 73 ms 109944 KB Output is correct
62 Correct 73 ms 109948 KB Output is correct
63 Correct 73 ms 109944 KB Output is correct
64 Execution timed out 7112 ms 111088 KB Time limit exceeded
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 7030 ms 111232 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 109944 KB Output is correct
2 Correct 81 ms 109944 KB Output is correct
3 Correct 77 ms 109916 KB Output is correct
4 Correct 74 ms 109944 KB Output is correct
5 Correct 101 ms 109924 KB Output is correct
6 Correct 81 ms 109944 KB Output is correct
7 Correct 76 ms 109948 KB Output is correct
8 Correct 80 ms 109944 KB Output is correct
9 Correct 108 ms 109948 KB Output is correct
10 Correct 100 ms 109944 KB Output is correct
11 Correct 97 ms 109944 KB Output is correct
12 Correct 98 ms 110072 KB Output is correct
13 Correct 112 ms 110072 KB Output is correct
14 Correct 112 ms 109944 KB Output is correct
15 Correct 121 ms 110072 KB Output is correct
16 Correct 113 ms 109944 KB Output is correct
17 Correct 101 ms 110072 KB Output is correct
18 Correct 82 ms 109944 KB Output is correct
19 Correct 76 ms 109944 KB Output is correct
20 Correct 75 ms 109848 KB Output is correct
21 Correct 101 ms 109944 KB Output is correct
22 Correct 82 ms 109944 KB Output is correct
23 Correct 77 ms 109944 KB Output is correct
24 Correct 76 ms 109944 KB Output is correct
25 Correct 106 ms 109944 KB Output is correct
26 Correct 98 ms 110072 KB Output is correct
27 Correct 96 ms 109944 KB Output is correct
28 Correct 97 ms 109944 KB Output is correct
29 Correct 114 ms 109944 KB Output is correct
30 Correct 116 ms 109980 KB Output is correct
31 Correct 111 ms 110072 KB Output is correct
32 Correct 112 ms 110072 KB Output is correct
33 Correct 75 ms 109944 KB Output is correct
34 Correct 75 ms 109944 KB Output is correct
35 Correct 75 ms 109944 KB Output is correct
36 Correct 76 ms 109944 KB Output is correct
37 Correct 79 ms 109948 KB Output is correct
38 Correct 78 ms 109852 KB Output is correct
39 Correct 79 ms 109944 KB Output is correct
40 Correct 77 ms 109944 KB Output is correct
41 Correct 97 ms 109944 KB Output is correct
42 Correct 80 ms 109944 KB Output is correct
43 Correct 76 ms 109816 KB Output is correct
44 Correct 78 ms 109944 KB Output is correct
45 Correct 93 ms 109944 KB Output is correct
46 Correct 92 ms 109948 KB Output is correct
47 Correct 75 ms 109944 KB Output is correct
48 Correct 76 ms 109948 KB Output is correct
49 Correct 94 ms 109944 KB Output is correct
50 Correct 99 ms 109944 KB Output is correct
51 Correct 94 ms 110072 KB Output is correct
52 Correct 96 ms 109944 KB Output is correct
53 Correct 97 ms 110072 KB Output is correct
54 Correct 96 ms 109944 KB Output is correct
55 Correct 94 ms 109876 KB Output is correct
56 Correct 99 ms 109944 KB Output is correct
57 Correct 97 ms 109904 KB Output is correct
58 Correct 96 ms 110072 KB Output is correct
59 Correct 108 ms 110072 KB Output is correct
60 Correct 109 ms 109944 KB Output is correct
61 Correct 73 ms 109944 KB Output is correct
62 Correct 73 ms 109948 KB Output is correct
63 Correct 73 ms 109944 KB Output is correct
64 Execution timed out 7112 ms 111088 KB Time limit exceeded
65 Halted 0 ms 0 KB -