#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7, pr = 31;
const int mxn = 1e5 + 5, mxq = 1e5 + 5, sq = 500, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e18 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
//https://usaco.org/current/data/sol_prob2_gold_open24.html
struct th{
int len, l, r;
bool operator <(const th &other){
return(len < other.len);
}
};
vt<th>all;
int n, t;
int lseg[mxn + 1], rseg[mxn + 1];
multiset<pii>seg;
vt<pii>more, bad;
vt<int>lp[sq + 1], rp[sq + 1];
void add(){
vt<th>all;
for(auto [l, r]: seg)all.pb({r - l + 1, l, r});
sort(ALL(all));
for(int i = 0; i < sq; i++){
lp[i].clear(); rp[i].clear();
}
for(int i = 0; i < sz(all); i++){
lp[i / sq].pb(all[i].l); rp[i / sq].pb(all[i].r);
}
for(int i = 0; i < sq; i++){
sort(ALLR(lp[i])); sort(ALL(rp[i]));
}
more.clear(); bad.clear();
}
int solve(int l, int r, int k){
if(r - l + 1 < k)return(0);
int ans = 0;
for(int i = 0; i <= n / sq; i++){
if(all[i * sq].len < k && all[min((i + 1) * sq - 1, sz(all) - 1)].len >= k){
for(int j = i * sq; j <= min((i + 1) * sq - 1, sz(all) - 1); j++){
if(all[j].len >= k && all[j].r >= l + k - 1 && all[j].l <= r - k + 1)ans++;
}
}else if(all[i * sq].len >= k){
ans += sz(lp[i]);
int l = 0, r = sz(lp[i]) - 1, res = -1;
while(l <= r){
int mid = (l + r) >> 1;
if(lp[i][mid] > r - k + 1){
res = mid; l = mid + 1;
}else{
r = mid - 1;
}
}
ans -= (res + 1);
l = 0, r = sz(rp[i]) - 1, res = -1;
while(l <= r){
int mid = (l + r) >> 1;
if(rp[i][mid] < l + k - 1){
res = mid; l = mid + 1;
}else{
r = mid - 1;
}
}
ans -= (res + 1);
}
}
for(auto [le, ri]: more){
if(ri - le + 1 >= k && le <= r - k + 1 && ri >= l + k - 1)ans++;
}
for(auto [le, ri]: bad){
if(ri - le + 1 >= k && le <= r - k + 1 && ri >= l + k - 1)ans--;
}
return(ans);
}
void solve(){
cin >> n >> t;
all.pb({-1, 0, 0});
int last = 0, idseg = 0;
while(n--){
int idq; cin >> idq;
if(idq == 1){
int a, b; cin >> a >> b;
a = (a ^ (t * last)); b = (b ^ (t * last));
if(a > b)swap(a, b);
lseg[++idseg] = a; rseg[idseg] = b;
more.pb(mpp(a, b)); seg.insert(mpp(a, b));
}else if(idq == 2){
int id; cin >> id;
seg.erase(seg.find(mpp(lseg[id], rseg[id]))); bad.pb(mpp(lseg[id], rseg[id]));
}else{
int l, r, k; cin >> l >> r >> k;
l = (l ^ (t * last)), r = (r ^ (t * last));
if(l > r)swap(l, r);
last = solve(l, r, k);
//cout << l << " " << r << " " << k << "\n";
cout << last << "\n";
}
if(sz(more) + sz(bad) == sq){
add();
}
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("DATA.inp", "r", stdin);
//freopen("DATA.out", "w", stdout);
int tt; tt = 1;
while(tt--){
solve();
}
return(0);
}
Compilation message
segments.cpp: In function 'void add()':
segments.cpp:44:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | for(auto [l, r]: seg)all.pb({r - l + 1, l, r});
| ^
segments.cpp: In function 'int solve(int, int, int)':
segments.cpp:89:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
89 | for(auto [le, ri]: more){
| ^
segments.cpp:95:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
95 | for(auto [le, ri]: bad){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
594 ms |
5080 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |