#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())
#define pb push_back
#define fr first
#define sc second
#define pw(x) (1ll << x)
using namespace std;
using namespace __gnu_pbds;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef unsigned long long ull;
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const int N = 2e5 + 100;
const int buben = 1000;
const int nb = N / buben + 2;
struct segment {
int l, r;
segment (int l = 0, int r = 0) : l(l), r(r) {}
inline int len () { return r - l + 1; }
inline bool operator < (segment &x) {
if (len() != x.len()) return len() < x.len();
if (l < x.l) return l < x.l;
return r < x.r;
}
};
inline int inter (const segment &a, const segment &b) {
return max(0ll, min(a.r, b.r) - max(a.l, b.l) + 1);
}
struct sex {
vector <segment> buf;
vector <segment> ful;
vector <int> lb[nb], rb[nb];
inline void add (int l, int r) {
segment seg (l, r); buf.pb(seg);
if (sz(buf) == buben) {
sort(all(buf));
vector <segment> mt; mt.reserve(sz(ful) + sz(buf));
int uk1 = 0, uk2 = 0;
while (uk1 < sz(ful) || uk2 < sz(buf)) {
if (uk1 == sz(ful)) mt.pb(buf[uk2++]);
else if (uk2 == sz(buf)) mt.pb(ful[uk1++]);
else if (ful[uk1] < buf[uk2]) mt.pb(ful[uk1++]);
else mt.pb(buf[uk2++]);
}
ful.swap(mt); buf.clear();
for (int i = 0; i < nb; ++i) lb[i].clear(), rb[i].clear();
for (int i = 0; i < sz(ful); ++i) {
lb[i / buben].pb(ful[i].l);
rb[i / buben].pb(ful[i].r);
}
for (int i = 0; i < nb; ++i) {
sort(all(lb[i]));
sort(all(rb[i]));
}
}
}
inline int get (int l, int r, int k) {
int res = 0;
segment seg (l, r);
for (segment x : buf) res += inter(x, seg) >= k;
for (int L = 0, i = 0; L < sz(ful); L += buben, ++i) {
int R = min(sz(ful), L + buben) - 1;
if (ful[L].len() >= k) {
res += R - L + 1;
res -= sz(lb[i]) - (lower_bound(all(lb[i]), r - k + 2) - lb[i].begin());
res -= upper_bound(all(rb[i]), l + k - 2) - rb[i].begin();
}
else if (ful[R].len() >= k) {
for (int j = L; j <= R; ++j) res += inter(ful[j], seg);
}
}
return res;
}
};
inline void solve () {
int q, T; cin >> q >> T;
vector <pii> seg (q); int uk = 0;
int lst = 0;
sex in, out;
while (q--) {
int t; cin >> t;
if (t == 1) {
int l, r; cin >> l >> r;
l = (l ^ (T * lst)), r = (r ^ (T * lst)); if (l > r) swap(l, r);
seg[uk++] = {l, r};
in.add(l, r);
}
if (t == 2) {
int id; cin >> id; --id;
auto [l, r] = seg[id];
out.add(l, r);
}
if (t == 3) {
int l, r, k; cin >> l >> r >> k;
l = (l ^ (T * lst)), r = (r ^ (T * lst)); if (l > r) swap(l, r);
lst = in.get(l, r, k) - out.get(l, r, k);
cout << lst << endl;
}
}
}
signed main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
int t = 1; // cin >> t;
while (t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
9 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
551 ms |
4168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
373 ms |
4668 KB |
Output is correct |
2 |
Correct |
327 ms |
4584 KB |
Output is correct |
3 |
Correct |
335 ms |
4680 KB |
Output is correct |
4 |
Correct |
346 ms |
4680 KB |
Output is correct |
5 |
Correct |
544 ms |
5348 KB |
Output is correct |
6 |
Correct |
503 ms |
4840 KB |
Output is correct |
7 |
Correct |
555 ms |
4936 KB |
Output is correct |
8 |
Correct |
510 ms |
6368 KB |
Output is correct |
9 |
Correct |
487 ms |
6472 KB |
Output is correct |
10 |
Correct |
449 ms |
6152 KB |
Output is correct |
11 |
Correct |
332 ms |
6868 KB |
Output is correct |
12 |
Correct |
422 ms |
6252 KB |
Output is correct |
13 |
Correct |
397 ms |
6304 KB |
Output is correct |
14 |
Correct |
334 ms |
5920 KB |
Output is correct |
15 |
Correct |
337 ms |
6160 KB |
Output is correct |
16 |
Correct |
332 ms |
5620 KB |
Output is correct |
17 |
Correct |
450 ms |
4264 KB |
Output is correct |
18 |
Correct |
554 ms |
4144 KB |
Output is correct |
19 |
Correct |
511 ms |
4508 KB |
Output is correct |
20 |
Correct |
491 ms |
4196 KB |
Output is correct |
21 |
Correct |
336 ms |
6768 KB |
Output is correct |
22 |
Correct |
377 ms |
6024 KB |
Output is correct |
23 |
Correct |
404 ms |
6328 KB |
Output is correct |
24 |
Correct |
390 ms |
6072 KB |
Output is correct |
25 |
Correct |
325 ms |
4676 KB |
Output is correct |
26 |
Correct |
326 ms |
4632 KB |
Output is correct |
27 |
Correct |
334 ms |
4648 KB |
Output is correct |
28 |
Correct |
331 ms |
4668 KB |
Output is correct |
29 |
Correct |
402 ms |
6012 KB |
Output is correct |
30 |
Correct |
401 ms |
6112 KB |
Output is correct |
31 |
Correct |
469 ms |
6336 KB |
Output is correct |
32 |
Correct |
425 ms |
6116 KB |
Output is correct |
33 |
Correct |
391 ms |
6400 KB |
Output is correct |
34 |
Correct |
326 ms |
5580 KB |
Output is correct |
35 |
Correct |
367 ms |
6316 KB |
Output is correct |
36 |
Correct |
398 ms |
6476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
399 ms |
4840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
9 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
9 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |