Submission #1083603

# Submission time Handle Problem Language Result Execution time Memory
1083603 2024-09-03T14:51:56 Z LOLOLO Segments (IZhO18_segments) C++17
100 / 100
2326 ms 9604 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           s     second
#define           f     first
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 2e5 + 10;
const int block = 1e3;

int l[N], r[N];

struct {
    vector <pair <int, int>> st, cur;
    vector <int> ls[N / block + 10], rs[N / block + 10];

    void add(int l, int r) {
        cur.pb({l, r});
        if (sz(cur) >= block) {
            for (auto x : cur) {
                st.pb(x);
            }

            cur.clear();
            sort(all(st), [&] (pair <int, int> &A, pair <int, int> &B) {return A.s - A.f < B.s - B.f;});
            for (int i = 0; i * block < sz(st); i++) {
                ls[i].clear(), rs[i].clear();
            }

            for (int i = 0; i < sz(st); i++) {
                int id = i / block;
                ls[id].pb(st[i].f);
                rs[id].pb(st[i].s);
            }

            for (int i = 0; i * block < sz(st); i++) {
                sort(all(ls[i]));
                sort(all(rs[i]));
            }
        }  
    }

    int cal(int l, int r, int k) {
        if (r - l + 1 < k)
            return 0;

        int ans = 0;
        for (auto x : cur) {
            if (min(r, x.s) - max(l, x.f) + 1 >= k) {
                ans++;
            }
        }

        for (int i = 0; i < sz(st); i += block) {
            int en = min(i + block - 1, sz(st) - 1);
            if (st[i].s - st[i].f + 1 >= k) {
                int bl = i / block;
                ans += (en - i + 1);
                ans -= ls[bl].end() - upper_bound(all(ls[bl]), r - k + 1);
                ans -= lower_bound(all(rs[bl]), l + k - 1) - rs[bl].begin();
            } else if (st[en].s - st[en].f + 1 >= k) {
                for (int j = i; j <= en; j++) {
                    if (min(st[j].s, r) - max(st[j].f, l) + 1 >= k)
                        ans++;
                }
            }
        }

        return ans;
    }
} good, bad;

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

    int n, ss;
    cin >> n >> ss;
    int id = 1;
    int ans = 0;

    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;

        if (t == 1) {
            cin >> l[id] >> r[id];
            l[id] ^= (ans * ss), r[id] ^= (ans * ss);
            if (l[id] > r[id])
                swap(l[id], r[id]);

            good.add(l[id], r[id]);
            id++;
        }

        if (t == 2) {
            int tt;
            cin >> tt;
            bad.add(l[tt], r[tt]);
        }

        if (t == 3) {
            int l, r, k;
            cin >> l >> r >> k;
            l ^= (ans * ss), r ^= (ans * ss);
            if (l > r)
                swap(l, r);

            ans = good.cal(l, r, k) - bad.cal(l, r, k);
            
            cout << ans << "\n";
        }
    }
}

/*
6 1
1 1 2
3 2 4  2
1 3 5
3 2 3 1
2 1
3 0 3 1
*/

/*
6 0
1 3 10
1 3 5
3 6 10 6
2 1
1 3 10
3 6 4 2
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 4 ms 624 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 4 ms 732 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 5 ms 612 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 600 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 4 ms 664 KB Output is correct
16 Correct 6 ms 620 KB Output is correct
17 Correct 6 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 4 ms 488 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 417 ms 4412 KB Output is correct
2 Correct 414 ms 4560 KB Output is correct
3 Correct 417 ms 4552 KB Output is correct
4 Correct 430 ms 4592 KB Output is correct
5 Correct 611 ms 5060 KB Output is correct
6 Correct 595 ms 4972 KB Output is correct
7 Correct 410 ms 4552 KB Output is correct
8 Correct 416 ms 4624 KB Output is correct
9 Correct 406 ms 4552 KB Output is correct
10 Correct 253 ms 4300 KB Output is correct
11 Correct 261 ms 4296 KB Output is correct
12 Correct 467 ms 4804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 264 ms 3912 KB Output is correct
2 Correct 260 ms 3916 KB Output is correct
3 Correct 265 ms 3916 KB Output is correct
4 Correct 256 ms 3864 KB Output is correct
5 Correct 489 ms 4428 KB Output is correct
6 Correct 467 ms 4300 KB Output is correct
7 Correct 483 ms 4552 KB Output is correct
8 Correct 597 ms 4800 KB Output is correct
9 Correct 573 ms 4812 KB Output is correct
10 Correct 452 ms 4548 KB Output is correct
11 Correct 287 ms 3940 KB Output is correct
12 Correct 452 ms 4548 KB Output is correct
13 Correct 406 ms 4476 KB Output is correct
14 Correct 300 ms 4112 KB Output is correct
15 Correct 287 ms 4136 KB Output is correct
16 Correct 276 ms 4040 KB Output is correct
17 Correct 369 ms 4164 KB Output is correct
18 Correct 406 ms 4296 KB Output is correct
19 Correct 408 ms 4216 KB Output is correct
20 Correct 362 ms 4124 KB Output is correct
21 Correct 289 ms 3668 KB Output is correct
22 Correct 348 ms 4300 KB Output is correct
23 Correct 393 ms 4556 KB Output is correct
24 Correct 365 ms 4300 KB Output is correct
25 Correct 269 ms 3916 KB Output is correct
26 Correct 263 ms 3912 KB Output is correct
27 Correct 264 ms 3916 KB Output is correct
28 Correct 273 ms 3912 KB Output is correct
29 Correct 405 ms 4808 KB Output is correct
30 Correct 411 ms 4828 KB Output is correct
31 Correct 582 ms 4992 KB Output is correct
32 Correct 455 ms 4544 KB Output is correct
33 Correct 418 ms 4632 KB Output is correct
34 Correct 291 ms 3956 KB Output is correct
35 Correct 362 ms 4396 KB Output is correct
36 Correct 428 ms 4400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 4168 KB Output is correct
2 Correct 297 ms 4168 KB Output is correct
3 Correct 305 ms 4032 KB Output is correct
4 Correct 322 ms 4168 KB Output is correct
5 Correct 515 ms 4800 KB Output is correct
6 Correct 256 ms 4208 KB Output is correct
7 Correct 529 ms 4728 KB Output is correct
8 Correct 280 ms 4316 KB Output is correct
9 Correct 365 ms 4292 KB Output is correct
10 Correct 502 ms 4804 KB Output is correct
11 Correct 347 ms 3980 KB Output is correct
12 Correct 594 ms 4804 KB Output is correct
13 Correct 460 ms 4728 KB Output is correct
14 Correct 363 ms 4360 KB Output is correct
15 Correct 557 ms 4732 KB Output is correct
16 Correct 469 ms 4552 KB Output is correct
17 Correct 423 ms 4632 KB Output is correct
18 Correct 416 ms 4436 KB Output is correct
19 Correct 442 ms 4608 KB Output is correct
20 Correct 409 ms 4556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 4 ms 624 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 4 ms 732 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 5 ms 612 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 600 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 4 ms 664 KB Output is correct
16 Correct 6 ms 620 KB Output is correct
17 Correct 6 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 4 ms 488 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 417 ms 4412 KB Output is correct
22 Correct 414 ms 4560 KB Output is correct
23 Correct 417 ms 4552 KB Output is correct
24 Correct 430 ms 4592 KB Output is correct
25 Correct 611 ms 5060 KB Output is correct
26 Correct 595 ms 4972 KB Output is correct
27 Correct 410 ms 4552 KB Output is correct
28 Correct 416 ms 4624 KB Output is correct
29 Correct 406 ms 4552 KB Output is correct
30 Correct 253 ms 4300 KB Output is correct
31 Correct 261 ms 4296 KB Output is correct
32 Correct 467 ms 4804 KB Output is correct
33 Correct 302 ms 4168 KB Output is correct
34 Correct 297 ms 4168 KB Output is correct
35 Correct 305 ms 4032 KB Output is correct
36 Correct 322 ms 4168 KB Output is correct
37 Correct 515 ms 4800 KB Output is correct
38 Correct 256 ms 4208 KB Output is correct
39 Correct 529 ms 4728 KB Output is correct
40 Correct 280 ms 4316 KB Output is correct
41 Correct 365 ms 4292 KB Output is correct
42 Correct 502 ms 4804 KB Output is correct
43 Correct 347 ms 3980 KB Output is correct
44 Correct 594 ms 4804 KB Output is correct
45 Correct 460 ms 4728 KB Output is correct
46 Correct 363 ms 4360 KB Output is correct
47 Correct 557 ms 4732 KB Output is correct
48 Correct 469 ms 4552 KB Output is correct
49 Correct 423 ms 4632 KB Output is correct
50 Correct 416 ms 4436 KB Output is correct
51 Correct 442 ms 4608 KB Output is correct
52 Correct 409 ms 4556 KB Output is correct
53 Correct 333 ms 4176 KB Output is correct
54 Correct 354 ms 4076 KB Output is correct
55 Correct 324 ms 4020 KB Output is correct
56 Correct 303 ms 3988 KB Output is correct
57 Correct 336 ms 4448 KB Output is correct
58 Correct 172 ms 4180 KB Output is correct
59 Correct 429 ms 4552 KB Output is correct
60 Correct 204 ms 4176 KB Output is correct
61 Correct 434 ms 4676 KB Output is correct
62 Correct 550 ms 4776 KB Output is correct
63 Correct 569 ms 4872 KB Output is correct
64 Correct 573 ms 4752 KB Output is correct
65 Correct 345 ms 4312 KB Output is correct
66 Correct 319 ms 4020 KB Output is correct
67 Correct 446 ms 4552 KB Output is correct
68 Correct 391 ms 4696 KB Output is correct
69 Correct 424 ms 4552 KB Output is correct
70 Correct 408 ms 4420 KB Output is correct
71 Correct 410 ms 4552 KB Output is correct
72 Correct 419 ms 4552 KB Output is correct
73 Correct 338 ms 4300 KB Output is correct
74 Correct 392 ms 4860 KB Output is correct
75 Correct 616 ms 4980 KB Output is correct
76 Correct 581 ms 4808 KB Output is correct
77 Correct 303 ms 4260 KB Output is correct
78 Correct 301 ms 4164 KB Output is correct
79 Correct 309 ms 4332 KB Output is correct
80 Correct 302 ms 4172 KB Output is correct
81 Correct 377 ms 4680 KB Output is correct
82 Correct 335 ms 4300 KB Output is correct
83 Correct 326 ms 4048 KB Output is correct
84 Correct 398 ms 4548 KB Output is correct
85 Correct 441 ms 4632 KB Output is correct
86 Correct 449 ms 4552 KB Output is correct
87 Correct 359 ms 4296 KB Output is correct
88 Correct 320 ms 4044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 4 ms 624 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 4 ms 732 KB Output is correct
6 Correct 4 ms 604 KB Output is correct
7 Correct 5 ms 612 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 604 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 600 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 4 ms 604 KB Output is correct
15 Correct 4 ms 664 KB Output is correct
16 Correct 6 ms 620 KB Output is correct
17 Correct 6 ms 604 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 4 ms 488 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 417 ms 4412 KB Output is correct
22 Correct 414 ms 4560 KB Output is correct
23 Correct 417 ms 4552 KB Output is correct
24 Correct 430 ms 4592 KB Output is correct
25 Correct 611 ms 5060 KB Output is correct
26 Correct 595 ms 4972 KB Output is correct
27 Correct 410 ms 4552 KB Output is correct
28 Correct 416 ms 4624 KB Output is correct
29 Correct 406 ms 4552 KB Output is correct
30 Correct 253 ms 4300 KB Output is correct
31 Correct 261 ms 4296 KB Output is correct
32 Correct 467 ms 4804 KB Output is correct
33 Correct 264 ms 3912 KB Output is correct
34 Correct 260 ms 3916 KB Output is correct
35 Correct 265 ms 3916 KB Output is correct
36 Correct 256 ms 3864 KB Output is correct
37 Correct 489 ms 4428 KB Output is correct
38 Correct 467 ms 4300 KB Output is correct
39 Correct 483 ms 4552 KB Output is correct
40 Correct 597 ms 4800 KB Output is correct
41 Correct 573 ms 4812 KB Output is correct
42 Correct 452 ms 4548 KB Output is correct
43 Correct 287 ms 3940 KB Output is correct
44 Correct 452 ms 4548 KB Output is correct
45 Correct 406 ms 4476 KB Output is correct
46 Correct 300 ms 4112 KB Output is correct
47 Correct 287 ms 4136 KB Output is correct
48 Correct 276 ms 4040 KB Output is correct
49 Correct 369 ms 4164 KB Output is correct
50 Correct 406 ms 4296 KB Output is correct
51 Correct 408 ms 4216 KB Output is correct
52 Correct 362 ms 4124 KB Output is correct
53 Correct 289 ms 3668 KB Output is correct
54 Correct 348 ms 4300 KB Output is correct
55 Correct 393 ms 4556 KB Output is correct
56 Correct 365 ms 4300 KB Output is correct
57 Correct 269 ms 3916 KB Output is correct
58 Correct 263 ms 3912 KB Output is correct
59 Correct 264 ms 3916 KB Output is correct
60 Correct 273 ms 3912 KB Output is correct
61 Correct 405 ms 4808 KB Output is correct
62 Correct 411 ms 4828 KB Output is correct
63 Correct 582 ms 4992 KB Output is correct
64 Correct 455 ms 4544 KB Output is correct
65 Correct 418 ms 4632 KB Output is correct
66 Correct 291 ms 3956 KB Output is correct
67 Correct 362 ms 4396 KB Output is correct
68 Correct 428 ms 4400 KB Output is correct
69 Correct 302 ms 4168 KB Output is correct
70 Correct 297 ms 4168 KB Output is correct
71 Correct 305 ms 4032 KB Output is correct
72 Correct 322 ms 4168 KB Output is correct
73 Correct 515 ms 4800 KB Output is correct
74 Correct 256 ms 4208 KB Output is correct
75 Correct 529 ms 4728 KB Output is correct
76 Correct 280 ms 4316 KB Output is correct
77 Correct 365 ms 4292 KB Output is correct
78 Correct 502 ms 4804 KB Output is correct
79 Correct 347 ms 3980 KB Output is correct
80 Correct 594 ms 4804 KB Output is correct
81 Correct 460 ms 4728 KB Output is correct
82 Correct 363 ms 4360 KB Output is correct
83 Correct 557 ms 4732 KB Output is correct
84 Correct 469 ms 4552 KB Output is correct
85 Correct 423 ms 4632 KB Output is correct
86 Correct 416 ms 4436 KB Output is correct
87 Correct 442 ms 4608 KB Output is correct
88 Correct 409 ms 4556 KB Output is correct
89 Correct 333 ms 4176 KB Output is correct
90 Correct 354 ms 4076 KB Output is correct
91 Correct 324 ms 4020 KB Output is correct
92 Correct 303 ms 3988 KB Output is correct
93 Correct 336 ms 4448 KB Output is correct
94 Correct 172 ms 4180 KB Output is correct
95 Correct 429 ms 4552 KB Output is correct
96 Correct 204 ms 4176 KB Output is correct
97 Correct 434 ms 4676 KB Output is correct
98 Correct 550 ms 4776 KB Output is correct
99 Correct 569 ms 4872 KB Output is correct
100 Correct 573 ms 4752 KB Output is correct
101 Correct 345 ms 4312 KB Output is correct
102 Correct 319 ms 4020 KB Output is correct
103 Correct 446 ms 4552 KB Output is correct
104 Correct 391 ms 4696 KB Output is correct
105 Correct 424 ms 4552 KB Output is correct
106 Correct 408 ms 4420 KB Output is correct
107 Correct 410 ms 4552 KB Output is correct
108 Correct 419 ms 4552 KB Output is correct
109 Correct 338 ms 4300 KB Output is correct
110 Correct 392 ms 4860 KB Output is correct
111 Correct 616 ms 4980 KB Output is correct
112 Correct 581 ms 4808 KB Output is correct
113 Correct 303 ms 4260 KB Output is correct
114 Correct 301 ms 4164 KB Output is correct
115 Correct 309 ms 4332 KB Output is correct
116 Correct 302 ms 4172 KB Output is correct
117 Correct 377 ms 4680 KB Output is correct
118 Correct 335 ms 4300 KB Output is correct
119 Correct 326 ms 4048 KB Output is correct
120 Correct 398 ms 4548 KB Output is correct
121 Correct 441 ms 4632 KB Output is correct
122 Correct 449 ms 4552 KB Output is correct
123 Correct 359 ms 4296 KB Output is correct
124 Correct 320 ms 4044 KB Output is correct
125 Correct 1020 ms 7796 KB Output is correct
126 Correct 1026 ms 7848 KB Output is correct
127 Correct 1046 ms 8000 KB Output is correct
128 Correct 1034 ms 7768 KB Output is correct
129 Correct 994 ms 7744 KB Output is correct
130 Correct 1041 ms 7996 KB Output is correct
131 Correct 639 ms 7772 KB Output is correct
132 Correct 1278 ms 8536 KB Output is correct
133 Correct 1703 ms 8900 KB Output is correct
134 Correct 723 ms 8144 KB Output is correct
135 Correct 1853 ms 9136 KB Output is correct
136 Correct 379 ms 7632 KB Output is correct
137 Correct 2261 ms 9420 KB Output is correct
138 Correct 1612 ms 9368 KB Output is correct
139 Correct 1882 ms 9152 KB Output is correct
140 Correct 2128 ms 9240 KB Output is correct
141 Correct 1782 ms 8800 KB Output is correct
142 Correct 1086 ms 7728 KB Output is correct
143 Correct 1157 ms 7984 KB Output is correct
144 Correct 1016 ms 7788 KB Output is correct
145 Correct 2104 ms 9232 KB Output is correct
146 Correct 1321 ms 8204 KB Output is correct
147 Correct 1180 ms 7880 KB Output is correct
148 Correct 1181 ms 8028 KB Output is correct
149 Correct 1439 ms 8644 KB Output is correct
150 Correct 1388 ms 8648 KB Output is correct
151 Correct 1433 ms 8644 KB Output is correct
152 Correct 1445 ms 8760 KB Output is correct
153 Correct 1369 ms 8664 KB Output is correct
154 Correct 1437 ms 8648 KB Output is correct
155 Correct 1096 ms 7740 KB Output is correct
156 Correct 1202 ms 7996 KB Output is correct
157 Correct 2177 ms 9276 KB Output is correct
158 Correct 2219 ms 9340 KB Output is correct
159 Correct 1656 ms 9156 KB Output is correct
160 Correct 1382 ms 8388 KB Output is correct
161 Correct 1054 ms 7996 KB Output is correct
162 Correct 1024 ms 7764 KB Output is correct
163 Correct 1028 ms 7968 KB Output is correct
164 Correct 1042 ms 8000 KB Output is correct
165 Correct 1039 ms 7896 KB Output is correct
166 Correct 1038 ms 7884 KB Output is correct
167 Correct 2311 ms 9576 KB Output is correct
168 Correct 2326 ms 9604 KB Output is correct
169 Correct 2166 ms 9408 KB Output is correct
170 Correct 2033 ms 9264 KB Output is correct
171 Correct 1804 ms 8808 KB Output is correct
172 Correct 1307 ms 8276 KB Output is correct
173 Correct 2159 ms 9340 KB Output is correct
174 Correct 1302 ms 8388 KB Output is correct
175 Correct 1821 ms 8892 KB Output is correct
176 Correct 1154 ms 7952 KB Output is correct
177 Correct 1618 ms 9160 KB Output is correct
178 Correct 1551 ms 9488 KB Output is correct