답안 #42824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42824 2018-03-04T15:24:54 Z minhtung0404 Segments (IZhO18_segments) C++14
75 / 100
5000 ms 40960 KB
//https://oj.uz/problem/view/IZhO18_segments

#include<bits/stdc++.h>
const int N = 2e5 + 5;
const int MAGIC = 1001;
using namespace std;

struct segment{
    int l, r, id;
};

vector <segment> mv;
int n, t, L[N], R[N], ans, cnt, cur;
int l_sort[N], r_sort[N], l_nosort[N], r_nosort[N], p[N], num;
bool ck[N];

int bsearch(int l, int r, int k){
    while (l != r){
        int mid = (l + r) >> 1;
        if (r_nosort[mid] - l_nosort[mid] + 1 >= k) r = mid;
        else l = mid + 1;
    }
    if (r_nosort[l] - l_nosort[l] + 1 < k) return l + 1;
    return l;
}

void get_L(int pos, int k){
    int Max = (pos / MAGIC + 1) * MAGIC;
    for (int i = pos; i < min(Max, cnt); i++) if (r_nosort[i] < k) ans--;
    for (int i = Max; i < cnt; i += MAGIC){
        int x = i, y = min(i + MAGIC, cnt);
        int val = lower_bound(r_sort+x, r_sort+y, k) - r_sort - x;
        ans -= val;
    }
}

void get_R(int pos, int k){
    int Max = (pos / MAGIC + 1) * MAGIC;
    for (int i = pos; i < min(Max, cnt); i++) if (l_nosort[i] > k) ans--;
    for (int i = Max; i < cnt; i += MAGIC){
        int x = i, y = min(i + MAGIC, cnt);
        int val = y - (upper_bound(l_sort+x, l_sort+y, k) - l_sort);
        ans -= val;
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> t;
    while (n--){
        if (mv.size() == MAGIC){
            cnt = 0; mv.clear();
            for (int i = 1; i < N; i++) if (ck[i]) p[cnt++] = i;
            sort(p, p+cnt, [](int x, int y){return (R[x] - L[x]) < (R[y] - L[y]);});
            for (int i = 0; i < cnt; i++) l_sort[i] = l_nosort[i] = L[p[i]];
            for (int i = 0; i < cnt; i++) r_sort[i] = r_nosort[i] = R[p[i]];
            for (int i = 0; i < cnt; i += MAGIC){
                int x = i, y = min(i + MAGIC, cnt);
                sort(l_sort+x, l_sort+y);
                sort(r_sort+x, r_sort+y);
            }
        }
        int type, l, r, id, k;
        cin >> type;
        if (type == 1){
            num++; id = ++cur;
            cin >> l >> r;
            l ^= (t * ans); r ^= (t * ans); if (r < l) swap(l, r);
            ck[id] = true;
            L[id] = l; R[id] = r;
            mv.push_back({l, r, 1});
        }
        if (type == 2){
            num--;
            cin >> id;
            ck[id] = false;
            mv.push_back({L[id], R[id], -1});
        }
        if (type == 3){
            cin >> l >> r >> k;
            l ^= (t * ans); r ^= (t * ans); if (r < l) swap(l, r);
            if (r - l + 1 < k){
                ans = 0; cout << ans << "\n";
                continue;
            }
            ans = num;
            if (cnt > 0){
                int pos = bsearch(0, cnt-1, k);
                ans -= pos;
                get_L(pos, l + k - 1);
                get_R(pos, r - k + 1);
            }
            for (int i = 0; i < mv.size(); i++){
                int x = max(mv[i].l, l), y = min(mv[i].r, r);
                if (y - x + 1 < k) ans -= mv[i].id;
            }
            cout <<  ans << "\n";
        }
    }
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:93:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < mv.size(); i++){
                               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 400 KB Output is correct
3 Correct 7 ms 724 KB Output is correct
4 Correct 8 ms 724 KB Output is correct
5 Correct 10 ms 768 KB Output is correct
6 Correct 16 ms 768 KB Output is correct
7 Correct 11 ms 768 KB Output is correct
8 Correct 11 ms 768 KB Output is correct
9 Correct 11 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 21 ms 768 KB Output is correct
12 Correct 21 ms 768 KB Output is correct
13 Correct 8 ms 768 KB Output is correct
14 Correct 12 ms 780 KB Output is correct
15 Correct 7 ms 780 KB Output is correct
16 Correct 7 ms 780 KB Output is correct
17 Correct 18 ms 780 KB Output is correct
18 Correct 9 ms 796 KB Output is correct
19 Correct 17 ms 924 KB Output is correct
20 Correct 13 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1041 ms 2392 KB Output is correct
2 Correct 1029 ms 5168 KB Output is correct
3 Correct 1064 ms 7868 KB Output is correct
4 Correct 1091 ms 10740 KB Output is correct
5 Correct 1204 ms 13944 KB Output is correct
6 Correct 1245 ms 16160 KB Output is correct
7 Correct 1020 ms 17696 KB Output is correct
8 Correct 1006 ms 20504 KB Output is correct
9 Correct 1010 ms 23104 KB Output is correct
10 Correct 741 ms 25344 KB Output is correct
11 Correct 662 ms 28512 KB Output is correct
12 Correct 979 ms 32092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 32092 KB Output is correct
2 Correct 162 ms 32104 KB Output is correct
3 Correct 223 ms 33976 KB Output is correct
4 Correct 145 ms 35716 KB Output is correct
5 Correct 1186 ms 39916 KB Output is correct
6 Correct 1118 ms 40960 KB Output is correct
7 Correct 1148 ms 40960 KB Output is correct
8 Correct 1291 ms 40960 KB Output is correct
9 Correct 1251 ms 40960 KB Output is correct
10 Correct 1142 ms 40960 KB Output is correct
11 Correct 406 ms 40960 KB Output is correct
12 Correct 1126 ms 40960 KB Output is correct
13 Correct 1006 ms 40960 KB Output is correct
14 Correct 714 ms 40960 KB Output is correct
15 Correct 656 ms 40960 KB Output is correct
16 Correct 551 ms 40960 KB Output is correct
17 Correct 1255 ms 40960 KB Output is correct
18 Correct 1249 ms 40960 KB Output is correct
19 Correct 1262 ms 40960 KB Output is correct
20 Correct 1246 ms 40960 KB Output is correct
21 Correct 439 ms 40960 KB Output is correct
22 Correct 843 ms 40960 KB Output is correct
23 Correct 971 ms 40960 KB Output is correct
24 Correct 887 ms 40960 KB Output is correct
25 Correct 167 ms 40960 KB Output is correct
26 Correct 150 ms 40960 KB Output is correct
27 Correct 171 ms 40960 KB Output is correct
28 Correct 152 ms 40960 KB Output is correct
29 Correct 1037 ms 40960 KB Output is correct
30 Correct 1027 ms 40960 KB Output is correct
31 Correct 1243 ms 40960 KB Output is correct
32 Correct 1132 ms 40960 KB Output is correct
33 Correct 1044 ms 40960 KB Output is correct
34 Correct 654 ms 40960 KB Output is correct
35 Correct 939 ms 40960 KB Output is correct
36 Correct 1078 ms 40960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 40960 KB Output is correct
2 Correct 145 ms 40960 KB Output is correct
3 Correct 138 ms 40960 KB Output is correct
4 Correct 147 ms 40960 KB Output is correct
5 Correct 1146 ms 40960 KB Output is correct
6 Correct 891 ms 40960 KB Output is correct
7 Correct 1113 ms 40960 KB Output is correct
8 Correct 861 ms 40960 KB Output is correct
9 Correct 751 ms 40960 KB Output is correct
10 Correct 1139 ms 40960 KB Output is correct
11 Correct 455 ms 40960 KB Output is correct
12 Correct 1291 ms 40960 KB Output is correct
13 Correct 999 ms 40960 KB Output is correct
14 Correct 713 ms 40960 KB Output is correct
15 Correct 1232 ms 40960 KB Output is correct
16 Correct 1038 ms 40960 KB Output is correct
17 Correct 1034 ms 40960 KB Output is correct
18 Correct 1033 ms 40960 KB Output is correct
19 Correct 1022 ms 40960 KB Output is correct
20 Correct 1038 ms 40960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 400 KB Output is correct
3 Correct 7 ms 724 KB Output is correct
4 Correct 8 ms 724 KB Output is correct
5 Correct 10 ms 768 KB Output is correct
6 Correct 16 ms 768 KB Output is correct
7 Correct 11 ms 768 KB Output is correct
8 Correct 11 ms 768 KB Output is correct
9 Correct 11 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 21 ms 768 KB Output is correct
12 Correct 21 ms 768 KB Output is correct
13 Correct 8 ms 768 KB Output is correct
14 Correct 12 ms 780 KB Output is correct
15 Correct 7 ms 780 KB Output is correct
16 Correct 7 ms 780 KB Output is correct
17 Correct 18 ms 780 KB Output is correct
18 Correct 9 ms 796 KB Output is correct
19 Correct 17 ms 924 KB Output is correct
20 Correct 13 ms 924 KB Output is correct
21 Correct 1041 ms 2392 KB Output is correct
22 Correct 1029 ms 5168 KB Output is correct
23 Correct 1064 ms 7868 KB Output is correct
24 Correct 1091 ms 10740 KB Output is correct
25 Correct 1204 ms 13944 KB Output is correct
26 Correct 1245 ms 16160 KB Output is correct
27 Correct 1020 ms 17696 KB Output is correct
28 Correct 1006 ms 20504 KB Output is correct
29 Correct 1010 ms 23104 KB Output is correct
30 Correct 741 ms 25344 KB Output is correct
31 Correct 662 ms 28512 KB Output is correct
32 Correct 979 ms 32092 KB Output is correct
33 Correct 129 ms 40960 KB Output is correct
34 Correct 145 ms 40960 KB Output is correct
35 Correct 138 ms 40960 KB Output is correct
36 Correct 147 ms 40960 KB Output is correct
37 Correct 1146 ms 40960 KB Output is correct
38 Correct 891 ms 40960 KB Output is correct
39 Correct 1113 ms 40960 KB Output is correct
40 Correct 861 ms 40960 KB Output is correct
41 Correct 751 ms 40960 KB Output is correct
42 Correct 1139 ms 40960 KB Output is correct
43 Correct 455 ms 40960 KB Output is correct
44 Correct 1291 ms 40960 KB Output is correct
45 Correct 999 ms 40960 KB Output is correct
46 Correct 713 ms 40960 KB Output is correct
47 Correct 1232 ms 40960 KB Output is correct
48 Correct 1038 ms 40960 KB Output is correct
49 Correct 1034 ms 40960 KB Output is correct
50 Correct 1033 ms 40960 KB Output is correct
51 Correct 1022 ms 40960 KB Output is correct
52 Correct 1038 ms 40960 KB Output is correct
53 Correct 142 ms 40960 KB Output is correct
54 Correct 143 ms 40960 KB Output is correct
55 Correct 138 ms 40960 KB Output is correct
56 Correct 134 ms 40960 KB Output is correct
57 Correct 976 ms 40960 KB Output is correct
58 Correct 552 ms 40960 KB Output is correct
59 Correct 918 ms 40960 KB Output is correct
60 Correct 796 ms 40960 KB Output is correct
61 Correct 1012 ms 40960 KB Output is correct
62 Correct 1215 ms 40960 KB Output is correct
63 Correct 1233 ms 40960 KB Output is correct
64 Correct 1217 ms 40960 KB Output is correct
65 Correct 532 ms 40960 KB Output is correct
66 Correct 501 ms 40960 KB Output is correct
67 Correct 1034 ms 40960 KB Output is correct
68 Correct 909 ms 40960 KB Output is correct
69 Correct 1024 ms 40960 KB Output is correct
70 Correct 1030 ms 40960 KB Output is correct
71 Correct 1051 ms 40960 KB Output is correct
72 Correct 1034 ms 40960 KB Output is correct
73 Correct 609 ms 40960 KB Output is correct
74 Correct 906 ms 40960 KB Output is correct
75 Correct 1283 ms 40960 KB Output is correct
76 Correct 1234 ms 40960 KB Output is correct
77 Correct 143 ms 40960 KB Output is correct
78 Correct 150 ms 40960 KB Output is correct
79 Correct 148 ms 40960 KB Output is correct
80 Correct 135 ms 40960 KB Output is correct
81 Correct 844 ms 40960 KB Output is correct
82 Correct 593 ms 40960 KB Output is correct
83 Correct 429 ms 40960 KB Output is correct
84 Correct 855 ms 40960 KB Output is correct
85 Correct 1012 ms 40960 KB Output is correct
86 Correct 1077 ms 40960 KB Output is correct
87 Correct 762 ms 40960 KB Output is correct
88 Correct 455 ms 40960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 400 KB Output is correct
3 Correct 7 ms 724 KB Output is correct
4 Correct 8 ms 724 KB Output is correct
5 Correct 10 ms 768 KB Output is correct
6 Correct 16 ms 768 KB Output is correct
7 Correct 11 ms 768 KB Output is correct
8 Correct 11 ms 768 KB Output is correct
9 Correct 11 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 21 ms 768 KB Output is correct
12 Correct 21 ms 768 KB Output is correct
13 Correct 8 ms 768 KB Output is correct
14 Correct 12 ms 780 KB Output is correct
15 Correct 7 ms 780 KB Output is correct
16 Correct 7 ms 780 KB Output is correct
17 Correct 18 ms 780 KB Output is correct
18 Correct 9 ms 796 KB Output is correct
19 Correct 17 ms 924 KB Output is correct
20 Correct 13 ms 924 KB Output is correct
21 Correct 1041 ms 2392 KB Output is correct
22 Correct 1029 ms 5168 KB Output is correct
23 Correct 1064 ms 7868 KB Output is correct
24 Correct 1091 ms 10740 KB Output is correct
25 Correct 1204 ms 13944 KB Output is correct
26 Correct 1245 ms 16160 KB Output is correct
27 Correct 1020 ms 17696 KB Output is correct
28 Correct 1006 ms 20504 KB Output is correct
29 Correct 1010 ms 23104 KB Output is correct
30 Correct 741 ms 25344 KB Output is correct
31 Correct 662 ms 28512 KB Output is correct
32 Correct 979 ms 32092 KB Output is correct
33 Correct 162 ms 32092 KB Output is correct
34 Correct 162 ms 32104 KB Output is correct
35 Correct 223 ms 33976 KB Output is correct
36 Correct 145 ms 35716 KB Output is correct
37 Correct 1186 ms 39916 KB Output is correct
38 Correct 1118 ms 40960 KB Output is correct
39 Correct 1148 ms 40960 KB Output is correct
40 Correct 1291 ms 40960 KB Output is correct
41 Correct 1251 ms 40960 KB Output is correct
42 Correct 1142 ms 40960 KB Output is correct
43 Correct 406 ms 40960 KB Output is correct
44 Correct 1126 ms 40960 KB Output is correct
45 Correct 1006 ms 40960 KB Output is correct
46 Correct 714 ms 40960 KB Output is correct
47 Correct 656 ms 40960 KB Output is correct
48 Correct 551 ms 40960 KB Output is correct
49 Correct 1255 ms 40960 KB Output is correct
50 Correct 1249 ms 40960 KB Output is correct
51 Correct 1262 ms 40960 KB Output is correct
52 Correct 1246 ms 40960 KB Output is correct
53 Correct 439 ms 40960 KB Output is correct
54 Correct 843 ms 40960 KB Output is correct
55 Correct 971 ms 40960 KB Output is correct
56 Correct 887 ms 40960 KB Output is correct
57 Correct 167 ms 40960 KB Output is correct
58 Correct 150 ms 40960 KB Output is correct
59 Correct 171 ms 40960 KB Output is correct
60 Correct 152 ms 40960 KB Output is correct
61 Correct 1037 ms 40960 KB Output is correct
62 Correct 1027 ms 40960 KB Output is correct
63 Correct 1243 ms 40960 KB Output is correct
64 Correct 1132 ms 40960 KB Output is correct
65 Correct 1044 ms 40960 KB Output is correct
66 Correct 654 ms 40960 KB Output is correct
67 Correct 939 ms 40960 KB Output is correct
68 Correct 1078 ms 40960 KB Output is correct
69 Correct 129 ms 40960 KB Output is correct
70 Correct 145 ms 40960 KB Output is correct
71 Correct 138 ms 40960 KB Output is correct
72 Correct 147 ms 40960 KB Output is correct
73 Correct 1146 ms 40960 KB Output is correct
74 Correct 891 ms 40960 KB Output is correct
75 Correct 1113 ms 40960 KB Output is correct
76 Correct 861 ms 40960 KB Output is correct
77 Correct 751 ms 40960 KB Output is correct
78 Correct 1139 ms 40960 KB Output is correct
79 Correct 455 ms 40960 KB Output is correct
80 Correct 1291 ms 40960 KB Output is correct
81 Correct 999 ms 40960 KB Output is correct
82 Correct 713 ms 40960 KB Output is correct
83 Correct 1232 ms 40960 KB Output is correct
84 Correct 1038 ms 40960 KB Output is correct
85 Correct 1034 ms 40960 KB Output is correct
86 Correct 1033 ms 40960 KB Output is correct
87 Correct 1022 ms 40960 KB Output is correct
88 Correct 1038 ms 40960 KB Output is correct
89 Correct 142 ms 40960 KB Output is correct
90 Correct 143 ms 40960 KB Output is correct
91 Correct 138 ms 40960 KB Output is correct
92 Correct 134 ms 40960 KB Output is correct
93 Correct 976 ms 40960 KB Output is correct
94 Correct 552 ms 40960 KB Output is correct
95 Correct 918 ms 40960 KB Output is correct
96 Correct 796 ms 40960 KB Output is correct
97 Correct 1012 ms 40960 KB Output is correct
98 Correct 1215 ms 40960 KB Output is correct
99 Correct 1233 ms 40960 KB Output is correct
100 Correct 1217 ms 40960 KB Output is correct
101 Correct 532 ms 40960 KB Output is correct
102 Correct 501 ms 40960 KB Output is correct
103 Correct 1034 ms 40960 KB Output is correct
104 Correct 909 ms 40960 KB Output is correct
105 Correct 1024 ms 40960 KB Output is correct
106 Correct 1030 ms 40960 KB Output is correct
107 Correct 1051 ms 40960 KB Output is correct
108 Correct 1034 ms 40960 KB Output is correct
109 Correct 609 ms 40960 KB Output is correct
110 Correct 906 ms 40960 KB Output is correct
111 Correct 1283 ms 40960 KB Output is correct
112 Correct 1234 ms 40960 KB Output is correct
113 Correct 143 ms 40960 KB Output is correct
114 Correct 150 ms 40960 KB Output is correct
115 Correct 148 ms 40960 KB Output is correct
116 Correct 135 ms 40960 KB Output is correct
117 Correct 844 ms 40960 KB Output is correct
118 Correct 593 ms 40960 KB Output is correct
119 Correct 429 ms 40960 KB Output is correct
120 Correct 855 ms 40960 KB Output is correct
121 Correct 1012 ms 40960 KB Output is correct
122 Correct 1077 ms 40960 KB Output is correct
123 Correct 762 ms 40960 KB Output is correct
124 Correct 455 ms 40960 KB Output is correct
125 Correct 282 ms 40960 KB Output is correct
126 Correct 291 ms 40960 KB Output is correct
127 Correct 337 ms 40960 KB Output is correct
128 Correct 296 ms 40960 KB Output is correct
129 Correct 273 ms 40960 KB Output is correct
130 Correct 307 ms 40960 KB Output is correct
131 Correct 2121 ms 40960 KB Output is correct
132 Correct 2931 ms 40960 KB Output is correct
133 Correct 3513 ms 40960 KB Output is correct
134 Correct 1956 ms 40960 KB Output is correct
135 Correct 3979 ms 40960 KB Output is correct
136 Correct 1472 ms 40960 KB Output is correct
137 Execution timed out 5072 ms 40960 KB Time limit exceeded
138 Halted 0 ms 0 KB -