//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x << " = " << x << endl;
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;
const ll N = 1e5+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
using namespace std;
int n , t , BL , blsz;
vector<pair<int , pii>> v;
vector<int> bl[N] , br[N];
void build(){
BL = sqrt(v.sz());
sort(all(v));
blsz = v.sz()/BL;
for(int i = 0 ; i < v.sz(); i++){
int j = i / BL;
bl[j].pb(v[i].S.S);
br[j].pb(v[i].S.F);
}
for(int i = 0; i < blsz; i++){
sort(all(bl[i]));
sort(all(br[i]));
}
}
int get(int l , int r , int k){
int ans = 0;
for(int i = 0; i < blsz; i++){
if(v[(i+1)*BL-1].F >= k && v[i*BL].F < k){
for(int j = i*BL; j <= (i+1)*BL-1; j++){
int res = 0;
int L = v[j].S.F , R = v[j].S.S;
if(l <= L && R <= r) res = R-L+1;
else if(l <= L && L <= r) res = r-L+1;
else if(l <= R && R <= r) res = R-l+1;
else if(L <= l && r <= R) res = r-l+1;
if(res >= k) ans++;
}
} else if(v[(i+1)*BL-1].F >= k && v[i*BL].F >= k){
int res = 0;
for(int L = 0 , R = br[i].sz()-1; L <= R;){
int md = (L+R) >> 1;
if(br[i][md] <= r-k+1) res = md , L = md+1;
else R = md-1;
}
ans += res+1;
res = 0;
for(int L = 0 , R = bl[i].sz()-1; L <= R;){
int md = (L+R) >> 1;
if(bl[i][md] >= l+k-1) res = md , R = md-1;
else L = md+1;
}
ans += bl[i].sz() - res;
}
}
return ans;
}
void solve(){
cin >> n >> t;
int lst = 0 , ok = 0;
while(n--){
int tp , l , r;
cin >> tp >> l >> r;
l = (l ^ (t * lst));
r = (r ^ (t * lst));
if(tp == 3){
if(ok == 0) build();
ok = 1;
int k;
cin >> k;
lst = get(l,r,k);
cout << lst <<"\n";
} else {
int ras = r-l+1;
v.pb({ras , {l , r}});
}
}
}
signed main(){
ios;
solve();
return 0;
}
/*
6 0
1 3 10
1 3 5
3 6 10 6
1 3 10
3 6 4 2
*/
Compilation message
segments.cpp: In function 'void build()':
segments.cpp:45:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i = 0 ; i < v.sz(); i++){
| ~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
636 ms |
9488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
9308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
9164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |