답안 #1083514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083514 2024-09-03T11:04:30 Z LOLOLO Segments (IZhO18_segments) C++17
75 / 100
5000 ms 7896 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 = 2e5;
int l[N], r[N];

struct {
    vector <pair <int, int>> in;
    vector <int> ls, rs;
    void add(int l, int r) {
        in.pb({l, r});
        if (sz(in) >= block) {
            for (auto x : in) {
                ls.pb(x.f);
                rs.pb(x.s);
            }

            in.clear();
            sort(all(ls));
            sort(all(rs));
        } 
    }

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

        int ans = 0;
        int p = upper_bound(all(ls), r - k + 1) - ls.begin();
        ans += sz(ls) - p;

        p = lower_bound(all(rs), l + k - 1) - rs.begin();
        ans += p;

        for (auto x : in) {
            if (min(x.s, r) - max(x.f, l) + 1 < k) 
                ans++;
        }

        return sz(ls) + sz(rs) + sz(in) - 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
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
6 Correct 6 ms 680 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 8 ms 684 KB Output is correct
12 Correct 8 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 4 ms 660 KB Output is correct
15 Correct 5 ms 476 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 4 ms 604 KB Output is correct
20 Correct 4 ms 648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2513 ms 3024 KB Output is correct
2 Correct 2514 ms 4308 KB Output is correct
3 Correct 2524 ms 4304 KB Output is correct
4 Correct 2536 ms 4304 KB Output is correct
5 Correct 547 ms 4312 KB Output is correct
6 Correct 299 ms 4308 KB Output is correct
7 Correct 2528 ms 4304 KB Output is correct
8 Correct 2538 ms 4268 KB Output is correct
9 Correct 2521 ms 4304 KB Output is correct
10 Correct 1577 ms 4052 KB Output is correct
11 Correct 2079 ms 4052 KB Output is correct
12 Correct 2130 ms 4204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1134 ms 3020 KB Output is correct
2 Correct 1130 ms 3020 KB Output is correct
3 Correct 1139 ms 3020 KB Output is correct
4 Correct 1187 ms 3536 KB Output is correct
5 Correct 2066 ms 4016 KB Output is correct
6 Correct 2458 ms 4064 KB Output is correct
7 Correct 2286 ms 4296 KB Output is correct
8 Correct 541 ms 4312 KB Output is correct
9 Correct 349 ms 4264 KB Output is correct
10 Correct 914 ms 4048 KB Output is correct
11 Correct 1189 ms 3596 KB Output is correct
12 Correct 889 ms 4140 KB Output is correct
13 Correct 1053 ms 4156 KB Output is correct
14 Correct 1337 ms 3736 KB Output is correct
15 Correct 1285 ms 3424 KB Output is correct
16 Correct 1256 ms 3404 KB Output is correct
17 Correct 2514 ms 3792 KB Output is correct
18 Correct 2539 ms 3792 KB Output is correct
19 Correct 2496 ms 3796 KB Output is correct
20 Correct 2526 ms 3920 KB Output is correct
21 Correct 1186 ms 3412 KB Output is correct
22 Correct 1251 ms 3832 KB Output is correct
23 Correct 1149 ms 4308 KB Output is correct
24 Correct 1242 ms 3796 KB Output is correct
25 Correct 1139 ms 3576 KB Output is correct
26 Correct 1140 ms 3596 KB Output is correct
27 Correct 1188 ms 3592 KB Output is correct
28 Correct 1129 ms 3540 KB Output is correct
29 Correct 1103 ms 4372 KB Output is correct
30 Correct 1100 ms 4300 KB Output is correct
31 Correct 321 ms 4304 KB Output is correct
32 Correct 912 ms 4040 KB Output is correct
33 Correct 1010 ms 4048 KB Output is correct
34 Correct 1308 ms 3404 KB Output is correct
35 Correct 1166 ms 3768 KB Output is correct
36 Correct 979 ms 4008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1144 ms 2996 KB Output is correct
2 Correct 1127 ms 2972 KB Output is correct
3 Correct 1155 ms 2896 KB Output is correct
4 Correct 1127 ms 3020 KB Output is correct
5 Correct 1780 ms 3568 KB Output is correct
6 Correct 1221 ms 4176 KB Output is correct
7 Correct 1431 ms 4336 KB Output is correct
8 Correct 1658 ms 4052 KB Output is correct
9 Correct 1236 ms 3968 KB Output is correct
10 Correct 804 ms 4044 KB Output is correct
11 Correct 1238 ms 3664 KB Output is correct
12 Correct 176 ms 4328 KB Output is correct
13 Correct 1075 ms 4044 KB Output is correct
14 Correct 1292 ms 3820 KB Output is correct
15 Correct 387 ms 4160 KB Output is correct
16 Correct 988 ms 4048 KB Output is correct
17 Correct 2507 ms 4224 KB Output is correct
18 Correct 2522 ms 4304 KB Output is correct
19 Correct 2507 ms 4308 KB Output is correct
20 Correct 2509 ms 4332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
6 Correct 6 ms 680 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 8 ms 684 KB Output is correct
12 Correct 8 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 4 ms 660 KB Output is correct
15 Correct 5 ms 476 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 4 ms 604 KB Output is correct
20 Correct 4 ms 648 KB Output is correct
21 Correct 2513 ms 3024 KB Output is correct
22 Correct 2514 ms 4308 KB Output is correct
23 Correct 2524 ms 4304 KB Output is correct
24 Correct 2536 ms 4304 KB Output is correct
25 Correct 547 ms 4312 KB Output is correct
26 Correct 299 ms 4308 KB Output is correct
27 Correct 2528 ms 4304 KB Output is correct
28 Correct 2538 ms 4268 KB Output is correct
29 Correct 2521 ms 4304 KB Output is correct
30 Correct 1577 ms 4052 KB Output is correct
31 Correct 2079 ms 4052 KB Output is correct
32 Correct 2130 ms 4204 KB Output is correct
33 Correct 1144 ms 2996 KB Output is correct
34 Correct 1127 ms 2972 KB Output is correct
35 Correct 1155 ms 2896 KB Output is correct
36 Correct 1127 ms 3020 KB Output is correct
37 Correct 1780 ms 3568 KB Output is correct
38 Correct 1221 ms 4176 KB Output is correct
39 Correct 1431 ms 4336 KB Output is correct
40 Correct 1658 ms 4052 KB Output is correct
41 Correct 1236 ms 3968 KB Output is correct
42 Correct 804 ms 4044 KB Output is correct
43 Correct 1238 ms 3664 KB Output is correct
44 Correct 176 ms 4328 KB Output is correct
45 Correct 1075 ms 4044 KB Output is correct
46 Correct 1292 ms 3820 KB Output is correct
47 Correct 387 ms 4160 KB Output is correct
48 Correct 988 ms 4048 KB Output is correct
49 Correct 2507 ms 4224 KB Output is correct
50 Correct 2522 ms 4304 KB Output is correct
51 Correct 2507 ms 4308 KB Output is correct
52 Correct 2509 ms 4332 KB Output is correct
53 Correct 1125 ms 3792 KB Output is correct
54 Correct 1121 ms 3752 KB Output is correct
55 Correct 1138 ms 3792 KB Output is correct
56 Correct 1142 ms 3920 KB Output is correct
57 Correct 2237 ms 4288 KB Output is correct
58 Correct 856 ms 4212 KB Output is correct
59 Correct 2415 ms 4120 KB Output is correct
60 Correct 734 ms 3944 KB Output is correct
61 Correct 1048 ms 4044 KB Output is correct
62 Correct 459 ms 4052 KB Output is correct
63 Correct 261 ms 4540 KB Output is correct
64 Correct 425 ms 4056 KB Output is correct
65 Correct 1260 ms 3404 KB Output is correct
66 Correct 1322 ms 3688 KB Output is correct
67 Correct 966 ms 4304 KB Output is correct
68 Correct 1172 ms 4052 KB Output is correct
69 Correct 2525 ms 4308 KB Output is correct
70 Correct 2554 ms 4300 KB Output is correct
71 Correct 2508 ms 4324 KB Output is correct
72 Correct 2571 ms 4304 KB Output is correct
73 Correct 1276 ms 3640 KB Output is correct
74 Correct 1192 ms 3884 KB Output is correct
75 Correct 99 ms 4424 KB Output is correct
76 Correct 241 ms 4300 KB Output is correct
77 Correct 1173 ms 3800 KB Output is correct
78 Correct 1135 ms 3788 KB Output is correct
79 Correct 1146 ms 3808 KB Output is correct
80 Correct 1130 ms 3640 KB Output is correct
81 Correct 1196 ms 4044 KB Output is correct
82 Correct 1266 ms 3660 KB Output is correct
83 Correct 1247 ms 3536 KB Output is correct
84 Correct 1218 ms 4060 KB Output is correct
85 Correct 955 ms 4044 KB Output is correct
86 Correct 937 ms 4044 KB Output is correct
87 Correct 1253 ms 3948 KB Output is correct
88 Correct 1241 ms 3660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 5 ms 600 KB Output is correct
6 Correct 6 ms 680 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 8 ms 684 KB Output is correct
12 Correct 8 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 4 ms 660 KB Output is correct
15 Correct 5 ms 476 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 4 ms 604 KB Output is correct
20 Correct 4 ms 648 KB Output is correct
21 Correct 2513 ms 3024 KB Output is correct
22 Correct 2514 ms 4308 KB Output is correct
23 Correct 2524 ms 4304 KB Output is correct
24 Correct 2536 ms 4304 KB Output is correct
25 Correct 547 ms 4312 KB Output is correct
26 Correct 299 ms 4308 KB Output is correct
27 Correct 2528 ms 4304 KB Output is correct
28 Correct 2538 ms 4268 KB Output is correct
29 Correct 2521 ms 4304 KB Output is correct
30 Correct 1577 ms 4052 KB Output is correct
31 Correct 2079 ms 4052 KB Output is correct
32 Correct 2130 ms 4204 KB Output is correct
33 Correct 1134 ms 3020 KB Output is correct
34 Correct 1130 ms 3020 KB Output is correct
35 Correct 1139 ms 3020 KB Output is correct
36 Correct 1187 ms 3536 KB Output is correct
37 Correct 2066 ms 4016 KB Output is correct
38 Correct 2458 ms 4064 KB Output is correct
39 Correct 2286 ms 4296 KB Output is correct
40 Correct 541 ms 4312 KB Output is correct
41 Correct 349 ms 4264 KB Output is correct
42 Correct 914 ms 4048 KB Output is correct
43 Correct 1189 ms 3596 KB Output is correct
44 Correct 889 ms 4140 KB Output is correct
45 Correct 1053 ms 4156 KB Output is correct
46 Correct 1337 ms 3736 KB Output is correct
47 Correct 1285 ms 3424 KB Output is correct
48 Correct 1256 ms 3404 KB Output is correct
49 Correct 2514 ms 3792 KB Output is correct
50 Correct 2539 ms 3792 KB Output is correct
51 Correct 2496 ms 3796 KB Output is correct
52 Correct 2526 ms 3920 KB Output is correct
53 Correct 1186 ms 3412 KB Output is correct
54 Correct 1251 ms 3832 KB Output is correct
55 Correct 1149 ms 4308 KB Output is correct
56 Correct 1242 ms 3796 KB Output is correct
57 Correct 1139 ms 3576 KB Output is correct
58 Correct 1140 ms 3596 KB Output is correct
59 Correct 1188 ms 3592 KB Output is correct
60 Correct 1129 ms 3540 KB Output is correct
61 Correct 1103 ms 4372 KB Output is correct
62 Correct 1100 ms 4300 KB Output is correct
63 Correct 321 ms 4304 KB Output is correct
64 Correct 912 ms 4040 KB Output is correct
65 Correct 1010 ms 4048 KB Output is correct
66 Correct 1308 ms 3404 KB Output is correct
67 Correct 1166 ms 3768 KB Output is correct
68 Correct 979 ms 4008 KB Output is correct
69 Correct 1144 ms 2996 KB Output is correct
70 Correct 1127 ms 2972 KB Output is correct
71 Correct 1155 ms 2896 KB Output is correct
72 Correct 1127 ms 3020 KB Output is correct
73 Correct 1780 ms 3568 KB Output is correct
74 Correct 1221 ms 4176 KB Output is correct
75 Correct 1431 ms 4336 KB Output is correct
76 Correct 1658 ms 4052 KB Output is correct
77 Correct 1236 ms 3968 KB Output is correct
78 Correct 804 ms 4044 KB Output is correct
79 Correct 1238 ms 3664 KB Output is correct
80 Correct 176 ms 4328 KB Output is correct
81 Correct 1075 ms 4044 KB Output is correct
82 Correct 1292 ms 3820 KB Output is correct
83 Correct 387 ms 4160 KB Output is correct
84 Correct 988 ms 4048 KB Output is correct
85 Correct 2507 ms 4224 KB Output is correct
86 Correct 2522 ms 4304 KB Output is correct
87 Correct 2507 ms 4308 KB Output is correct
88 Correct 2509 ms 4332 KB Output is correct
89 Correct 1125 ms 3792 KB Output is correct
90 Correct 1121 ms 3752 KB Output is correct
91 Correct 1138 ms 3792 KB Output is correct
92 Correct 1142 ms 3920 KB Output is correct
93 Correct 2237 ms 4288 KB Output is correct
94 Correct 856 ms 4212 KB Output is correct
95 Correct 2415 ms 4120 KB Output is correct
96 Correct 734 ms 3944 KB Output is correct
97 Correct 1048 ms 4044 KB Output is correct
98 Correct 459 ms 4052 KB Output is correct
99 Correct 261 ms 4540 KB Output is correct
100 Correct 425 ms 4056 KB Output is correct
101 Correct 1260 ms 3404 KB Output is correct
102 Correct 1322 ms 3688 KB Output is correct
103 Correct 966 ms 4304 KB Output is correct
104 Correct 1172 ms 4052 KB Output is correct
105 Correct 2525 ms 4308 KB Output is correct
106 Correct 2554 ms 4300 KB Output is correct
107 Correct 2508 ms 4324 KB Output is correct
108 Correct 2571 ms 4304 KB Output is correct
109 Correct 1276 ms 3640 KB Output is correct
110 Correct 1192 ms 3884 KB Output is correct
111 Correct 99 ms 4424 KB Output is correct
112 Correct 241 ms 4300 KB Output is correct
113 Correct 1173 ms 3800 KB Output is correct
114 Correct 1135 ms 3788 KB Output is correct
115 Correct 1146 ms 3808 KB Output is correct
116 Correct 1130 ms 3640 KB Output is correct
117 Correct 1196 ms 4044 KB Output is correct
118 Correct 1266 ms 3660 KB Output is correct
119 Correct 1247 ms 3536 KB Output is correct
120 Correct 1218 ms 4060 KB Output is correct
121 Correct 955 ms 4044 KB Output is correct
122 Correct 937 ms 4044 KB Output is correct
123 Correct 1253 ms 3948 KB Output is correct
124 Correct 1241 ms 3660 KB Output is correct
125 Correct 4536 ms 6928 KB Output is correct
126 Correct 4545 ms 6936 KB Output is correct
127 Correct 4556 ms 6928 KB Output is correct
128 Correct 4497 ms 6884 KB Output is correct
129 Correct 4517 ms 6848 KB Output is correct
130 Correct 4602 ms 6996 KB Output is correct
131 Correct 3673 ms 7896 KB Output is correct
132 Execution timed out 5057 ms 6180 KB Time limit exceeded
133 Halted 0 ms 0 KB -