Submission #175729

# Submission time Handle Problem Language Result Execution time Memory
175729 2020-01-07T10:27:02 Z VEGAnn Segments (IZhO18_segments) C++14
75 / 100
5000 ms 10528 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N = 200100;
const int BLOCK = 1850;
//const int BLOCK = 2;
const int NB = N / BLOCK + 10;
const int PW = 20;
vector<int> bad, old, nw, lf, rt, glf, grt;
int last_ans = 0, n, l[N], r[N], tt = 0;
bool mrk[N], T;

bool cmp(int _x, int _y){
    return (r[_x] - l[_x]) < (r[_y] - l[_y]);
}

bool cmp_lf(int _x, int _y){
    return l[_x] < l[_y];
}

bool cmp_rt(int _x, int _y){
    return r[_x] < r[_y];
}

bool ok(int id, int l1, int r1, int k){
    int lef = max(l1, l[id]);
    int rgt = min(r1, r[id]);
    return bool((rgt - lef + 1) >= k);
}

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

//    freopen("in.txt","r",stdin);

    cin >> n >> T;

    old.clear();

    for (int it = 0; it < n; it += BLOCK){
        int bd = min(n, it + BLOCK);
        int mem_tt = tt;
        bad.clear();

        for (int i = it; i < bd; i++){
            int tp; cin >> tp;
            if (tp == 1){
                cin >> l[tt] >> r[tt];
                if (T){
                    l[tt] = (l[tt] ^ last_ans);
                    r[tt] = (r[tt] ^ last_ans);
                }
                if (l[tt] > r[tt])
                    swap(l[tt], r[tt]);
                tt++;
            } else if (tp == 2){
                int id; cin >> id; id--;
                bad.PB(id);
                mrk[id] = 1;
            } else {
                int l1, r1, k;
                cin >> l1 >> r1 >> k;
                if (T){
                    l1 = (l1 ^ last_ans);
                    r1 = (r1 ^ last_ans);
                }
                if (l1 > r1)
                    swap(l1, r1);

                if (r1 - l1 + 1 < k){
                    last_ans = 0;
                    cout << "0\n";
                    continue;
                }

                int dl = 0;
                if (sz(lf)){
                    dl += lower_bound(all(grt), l1 + k - 1) - grt.begin();
                    dl += sz(glf);
                    dl -= upper_bound(all(glf), r1 - k + 1) - glf.begin();

                    for (int i = 0; i < sz(lf); i += BLOCK){
                        int bd = min(sz(lf), i + BLOCK);
                        if (r[nw[bd - 1]] - l[nw[bd - 1]] + 1 >= k){
                            for (int j = i; j < bd; j++){
                                int nm = nw[j];
                                if (r[nm] - l[nm] + 1 >= k) break;
                                if (r[nm] < l1 + k - 1)
                                    dl--;
                                if (l[nm] > r1 - k + 1)
                                    dl--;
                                dl++;
                            }
                        } else {
                            dl -= lower_bound(rt.begin() + i, rt.begin() + bd, l1 + k - 1) - rt.begin() - i;
                            dl -= bd;
                            dl += upper_bound(lf.begin() + i, lf.begin() + bd, r1 - k + 1) - lf.begin();

                            dl += bd - i;
                        }
                    }
                }
                int ans = sz(lf) - dl;

                for (int i = mem_tt; i < tt; i++)
                    if (ok(i, l1, r1, k))
                        ans++;

                for (int i : bad)
                    if (ok(i, l1, r1, k))
                        ans--;

                cout << ans << '\n';
                last_ans = ans;
            }
        }

        old = nw;
        nw.clear();

        for (int id : old)
            if (!mrk[id])
                nw.PB(id);

        for (int i = mem_tt; i < tt; i++)
            if (!mrk[i])
                nw.PB(i);

        sort(all(nw), cmp);

        lf.resize(sz(nw));
        rt.resize(sz(nw));
        glf.resize(sz(nw));
        grt.resize(sz(nw));
        for (int i = 0; i < sz(nw); i++){
            lf[i] = glf[i] = l[nw[i]];
            rt[i] = grt[i] = r[nw[i]];
        }

        for (int i = 0; i < sz(nw); i += BLOCK){
            int bd = min(sz(nw), i + BLOCK);
            sort(lf.begin() + i, lf.begin() + bd);
            sort(rt.begin() + i, rt.begin() + bd);
        }

        sort(all(glf));
        sort(all(grt));
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 6 ms 532 KB Output is correct
5 Correct 10 ms 632 KB Output is correct
6 Correct 10 ms 632 KB Output is correct
7 Correct 7 ms 504 KB Output is correct
8 Correct 9 ms 632 KB Output is correct
9 Correct 8 ms 632 KB Output is correct
10 Correct 8 ms 632 KB Output is correct
11 Correct 12 ms 632 KB Output is correct
12 Correct 12 ms 632 KB Output is correct
13 Correct 8 ms 632 KB Output is correct
14 Correct 10 ms 632 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 6 ms 504 KB Output is correct
17 Correct 8 ms 504 KB Output is correct
18 Correct 8 ms 636 KB Output is correct
19 Correct 7 ms 632 KB Output is correct
20 Correct 7 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1225 ms 3884 KB Output is correct
2 Correct 1205 ms 4044 KB Output is correct
3 Correct 1212 ms 4048 KB Output is correct
4 Correct 1260 ms 3996 KB Output is correct
5 Correct 1422 ms 5096 KB Output is correct
6 Correct 1429 ms 5640 KB Output is correct
7 Correct 1218 ms 4032 KB Output is correct
8 Correct 1219 ms 3964 KB Output is correct
9 Correct 1217 ms 4204 KB Output is correct
10 Correct 708 ms 3212 KB Output is correct
11 Correct 848 ms 3408 KB Output is correct
12 Correct 1406 ms 4656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 1968 KB Output is correct
2 Correct 84 ms 2148 KB Output is correct
3 Correct 89 ms 2296 KB Output is correct
4 Correct 84 ms 2140 KB Output is correct
5 Correct 1146 ms 4524 KB Output is correct
6 Correct 1024 ms 4472 KB Output is correct
7 Correct 1079 ms 4532 KB Output is correct
8 Correct 1459 ms 5444 KB Output is correct
9 Correct 1428 ms 5312 KB Output is correct
10 Correct 1255 ms 4716 KB Output is correct
11 Correct 155 ms 2424 KB Output is correct
12 Correct 1274 ms 4816 KB Output is correct
13 Correct 1199 ms 4092 KB Output is correct
14 Correct 703 ms 3648 KB Output is correct
15 Correct 617 ms 3244 KB Output is correct
16 Correct 419 ms 2988 KB Output is correct
17 Correct 898 ms 3888 KB Output is correct
18 Correct 909 ms 3920 KB Output is correct
19 Correct 882 ms 4024 KB Output is correct
20 Correct 881 ms 4124 KB Output is correct
21 Correct 194 ms 2424 KB Output is correct
22 Correct 844 ms 3984 KB Output is correct
23 Correct 1077 ms 4056 KB Output is correct
24 Correct 911 ms 3956 KB Output is correct
25 Correct 88 ms 2192 KB Output is correct
26 Correct 85 ms 2192 KB Output is correct
27 Correct 86 ms 2168 KB Output is correct
28 Correct 83 ms 2168 KB Output is correct
29 Correct 1158 ms 4336 KB Output is correct
30 Correct 1166 ms 4504 KB Output is correct
31 Correct 1435 ms 5312 KB Output is correct
32 Correct 1310 ms 4584 KB Output is correct
33 Correct 1183 ms 4592 KB Output is correct
34 Correct 579 ms 3320 KB Output is correct
35 Correct 1065 ms 4208 KB Output is correct
36 Correct 1210 ms 4660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 2172 KB Output is correct
2 Correct 88 ms 2296 KB Output is correct
3 Correct 89 ms 2300 KB Output is correct
4 Correct 91 ms 2364 KB Output is correct
5 Correct 1427 ms 5032 KB Output is correct
6 Correct 555 ms 3008 KB Output is correct
7 Correct 1435 ms 5160 KB Output is correct
8 Correct 727 ms 3420 KB Output is correct
9 Correct 954 ms 3976 KB Output is correct
10 Correct 1453 ms 4928 KB Output is correct
11 Correct 458 ms 2808 KB Output is correct
12 Correct 1417 ms 5816 KB Output is correct
13 Correct 1269 ms 4676 KB Output is correct
14 Correct 834 ms 3776 KB Output is correct
15 Correct 1518 ms 5664 KB Output is correct
16 Correct 1312 ms 4600 KB Output is correct
17 Correct 1214 ms 4044 KB Output is correct
18 Correct 1198 ms 4332 KB Output is correct
19 Correct 1224 ms 4044 KB Output is correct
20 Correct 1204 ms 4156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 6 ms 532 KB Output is correct
5 Correct 10 ms 632 KB Output is correct
6 Correct 10 ms 632 KB Output is correct
7 Correct 7 ms 504 KB Output is correct
8 Correct 9 ms 632 KB Output is correct
9 Correct 8 ms 632 KB Output is correct
10 Correct 8 ms 632 KB Output is correct
11 Correct 12 ms 632 KB Output is correct
12 Correct 12 ms 632 KB Output is correct
13 Correct 8 ms 632 KB Output is correct
14 Correct 10 ms 632 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 6 ms 504 KB Output is correct
17 Correct 8 ms 504 KB Output is correct
18 Correct 8 ms 636 KB Output is correct
19 Correct 7 ms 632 KB Output is correct
20 Correct 7 ms 504 KB Output is correct
21 Correct 1225 ms 3884 KB Output is correct
22 Correct 1205 ms 4044 KB Output is correct
23 Correct 1212 ms 4048 KB Output is correct
24 Correct 1260 ms 3996 KB Output is correct
25 Correct 1422 ms 5096 KB Output is correct
26 Correct 1429 ms 5640 KB Output is correct
27 Correct 1218 ms 4032 KB Output is correct
28 Correct 1219 ms 3964 KB Output is correct
29 Correct 1217 ms 4204 KB Output is correct
30 Correct 708 ms 3212 KB Output is correct
31 Correct 848 ms 3408 KB Output is correct
32 Correct 1406 ms 4656 KB Output is correct
33 Correct 81 ms 2172 KB Output is correct
34 Correct 88 ms 2296 KB Output is correct
35 Correct 89 ms 2300 KB Output is correct
36 Correct 91 ms 2364 KB Output is correct
37 Correct 1427 ms 5032 KB Output is correct
38 Correct 555 ms 3008 KB Output is correct
39 Correct 1435 ms 5160 KB Output is correct
40 Correct 727 ms 3420 KB Output is correct
41 Correct 954 ms 3976 KB Output is correct
42 Correct 1453 ms 4928 KB Output is correct
43 Correct 458 ms 2808 KB Output is correct
44 Correct 1417 ms 5816 KB Output is correct
45 Correct 1269 ms 4676 KB Output is correct
46 Correct 834 ms 3776 KB Output is correct
47 Correct 1518 ms 5664 KB Output is correct
48 Correct 1312 ms 4600 KB Output is correct
49 Correct 1214 ms 4044 KB Output is correct
50 Correct 1198 ms 4332 KB Output is correct
51 Correct 1224 ms 4044 KB Output is correct
52 Correct 1204 ms 4156 KB Output is correct
53 Correct 92 ms 2420 KB Output is correct
54 Correct 91 ms 1476 KB Output is correct
55 Correct 89 ms 2296 KB Output is correct
56 Correct 88 ms 2168 KB Output is correct
57 Correct 952 ms 3144 KB Output is correct
58 Correct 442 ms 2680 KB Output is correct
59 Correct 1348 ms 4428 KB Output is correct
60 Correct 408 ms 2680 KB Output is correct
61 Correct 1327 ms 4436 KB Output is correct
62 Correct 1524 ms 5252 KB Output is correct
63 Correct 1447 ms 5724 KB Output is correct
64 Correct 1507 ms 5080 KB Output is correct
65 Correct 566 ms 3232 KB Output is correct
66 Correct 477 ms 2936 KB Output is correct
67 Correct 1343 ms 4592 KB Output is correct
68 Correct 1192 ms 4324 KB Output is correct
69 Correct 1198 ms 3508 KB Output is correct
70 Correct 1216 ms 3148 KB Output is correct
71 Correct 1241 ms 3340 KB Output is correct
72 Correct 1220 ms 3692 KB Output is correct
73 Correct 694 ms 2420 KB Output is correct
74 Correct 1184 ms 3024 KB Output is correct
75 Correct 1509 ms 5144 KB Output is correct
76 Correct 1429 ms 4664 KB Output is correct
77 Correct 94 ms 1784 KB Output is correct
78 Correct 89 ms 1912 KB Output is correct
79 Correct 92 ms 1912 KB Output is correct
80 Correct 88 ms 1784 KB Output is correct
81 Correct 1166 ms 3712 KB Output is correct
82 Correct 719 ms 2812 KB Output is correct
83 Correct 428 ms 2416 KB Output is correct
84 Correct 1165 ms 3776 KB Output is correct
85 Correct 1356 ms 4088 KB Output is correct
86 Correct 1342 ms 4052 KB Output is correct
87 Correct 937 ms 3448 KB Output is correct
88 Correct 413 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 6 ms 532 KB Output is correct
5 Correct 10 ms 632 KB Output is correct
6 Correct 10 ms 632 KB Output is correct
7 Correct 7 ms 504 KB Output is correct
8 Correct 9 ms 632 KB Output is correct
9 Correct 8 ms 632 KB Output is correct
10 Correct 8 ms 632 KB Output is correct
11 Correct 12 ms 632 KB Output is correct
12 Correct 12 ms 632 KB Output is correct
13 Correct 8 ms 632 KB Output is correct
14 Correct 10 ms 632 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 6 ms 504 KB Output is correct
17 Correct 8 ms 504 KB Output is correct
18 Correct 8 ms 636 KB Output is correct
19 Correct 7 ms 632 KB Output is correct
20 Correct 7 ms 504 KB Output is correct
21 Correct 1225 ms 3884 KB Output is correct
22 Correct 1205 ms 4044 KB Output is correct
23 Correct 1212 ms 4048 KB Output is correct
24 Correct 1260 ms 3996 KB Output is correct
25 Correct 1422 ms 5096 KB Output is correct
26 Correct 1429 ms 5640 KB Output is correct
27 Correct 1218 ms 4032 KB Output is correct
28 Correct 1219 ms 3964 KB Output is correct
29 Correct 1217 ms 4204 KB Output is correct
30 Correct 708 ms 3212 KB Output is correct
31 Correct 848 ms 3408 KB Output is correct
32 Correct 1406 ms 4656 KB Output is correct
33 Correct 86 ms 1968 KB Output is correct
34 Correct 84 ms 2148 KB Output is correct
35 Correct 89 ms 2296 KB Output is correct
36 Correct 84 ms 2140 KB Output is correct
37 Correct 1146 ms 4524 KB Output is correct
38 Correct 1024 ms 4472 KB Output is correct
39 Correct 1079 ms 4532 KB Output is correct
40 Correct 1459 ms 5444 KB Output is correct
41 Correct 1428 ms 5312 KB Output is correct
42 Correct 1255 ms 4716 KB Output is correct
43 Correct 155 ms 2424 KB Output is correct
44 Correct 1274 ms 4816 KB Output is correct
45 Correct 1199 ms 4092 KB Output is correct
46 Correct 703 ms 3648 KB Output is correct
47 Correct 617 ms 3244 KB Output is correct
48 Correct 419 ms 2988 KB Output is correct
49 Correct 898 ms 3888 KB Output is correct
50 Correct 909 ms 3920 KB Output is correct
51 Correct 882 ms 4024 KB Output is correct
52 Correct 881 ms 4124 KB Output is correct
53 Correct 194 ms 2424 KB Output is correct
54 Correct 844 ms 3984 KB Output is correct
55 Correct 1077 ms 4056 KB Output is correct
56 Correct 911 ms 3956 KB Output is correct
57 Correct 88 ms 2192 KB Output is correct
58 Correct 85 ms 2192 KB Output is correct
59 Correct 86 ms 2168 KB Output is correct
60 Correct 83 ms 2168 KB Output is correct
61 Correct 1158 ms 4336 KB Output is correct
62 Correct 1166 ms 4504 KB Output is correct
63 Correct 1435 ms 5312 KB Output is correct
64 Correct 1310 ms 4584 KB Output is correct
65 Correct 1183 ms 4592 KB Output is correct
66 Correct 579 ms 3320 KB Output is correct
67 Correct 1065 ms 4208 KB Output is correct
68 Correct 1210 ms 4660 KB Output is correct
69 Correct 81 ms 2172 KB Output is correct
70 Correct 88 ms 2296 KB Output is correct
71 Correct 89 ms 2300 KB Output is correct
72 Correct 91 ms 2364 KB Output is correct
73 Correct 1427 ms 5032 KB Output is correct
74 Correct 555 ms 3008 KB Output is correct
75 Correct 1435 ms 5160 KB Output is correct
76 Correct 727 ms 3420 KB Output is correct
77 Correct 954 ms 3976 KB Output is correct
78 Correct 1453 ms 4928 KB Output is correct
79 Correct 458 ms 2808 KB Output is correct
80 Correct 1417 ms 5816 KB Output is correct
81 Correct 1269 ms 4676 KB Output is correct
82 Correct 834 ms 3776 KB Output is correct
83 Correct 1518 ms 5664 KB Output is correct
84 Correct 1312 ms 4600 KB Output is correct
85 Correct 1214 ms 4044 KB Output is correct
86 Correct 1198 ms 4332 KB Output is correct
87 Correct 1224 ms 4044 KB Output is correct
88 Correct 1204 ms 4156 KB Output is correct
89 Correct 92 ms 2420 KB Output is correct
90 Correct 91 ms 1476 KB Output is correct
91 Correct 89 ms 2296 KB Output is correct
92 Correct 88 ms 2168 KB Output is correct
93 Correct 952 ms 3144 KB Output is correct
94 Correct 442 ms 2680 KB Output is correct
95 Correct 1348 ms 4428 KB Output is correct
96 Correct 408 ms 2680 KB Output is correct
97 Correct 1327 ms 4436 KB Output is correct
98 Correct 1524 ms 5252 KB Output is correct
99 Correct 1447 ms 5724 KB Output is correct
100 Correct 1507 ms 5080 KB Output is correct
101 Correct 566 ms 3232 KB Output is correct
102 Correct 477 ms 2936 KB Output is correct
103 Correct 1343 ms 4592 KB Output is correct
104 Correct 1192 ms 4324 KB Output is correct
105 Correct 1198 ms 3508 KB Output is correct
106 Correct 1216 ms 3148 KB Output is correct
107 Correct 1241 ms 3340 KB Output is correct
108 Correct 1220 ms 3692 KB Output is correct
109 Correct 694 ms 2420 KB Output is correct
110 Correct 1184 ms 3024 KB Output is correct
111 Correct 1509 ms 5144 KB Output is correct
112 Correct 1429 ms 4664 KB Output is correct
113 Correct 94 ms 1784 KB Output is correct
114 Correct 89 ms 1912 KB Output is correct
115 Correct 92 ms 1912 KB Output is correct
116 Correct 88 ms 1784 KB Output is correct
117 Correct 1166 ms 3712 KB Output is correct
118 Correct 719 ms 2812 KB Output is correct
119 Correct 428 ms 2416 KB Output is correct
120 Correct 1165 ms 3776 KB Output is correct
121 Correct 1356 ms 4088 KB Output is correct
122 Correct 1342 ms 4052 KB Output is correct
123 Correct 937 ms 3448 KB Output is correct
124 Correct 413 ms 2552 KB Output is correct
125 Correct 178 ms 2172 KB Output is correct
126 Correct 182 ms 2196 KB Output is correct
127 Correct 198 ms 2196 KB Output is correct
128 Correct 185 ms 2140 KB Output is correct
129 Correct 175 ms 2168 KB Output is correct
130 Correct 188 ms 2168 KB Output is correct
131 Correct 1562 ms 3364 KB Output is correct
132 Correct 4333 ms 5244 KB Output is correct
133 Execution timed out 5088 ms 10528 KB Time limit exceeded
134 Halted 0 ms 0 KB -