This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/***Farhan132***/
// #pragma GCC optimize("Ofast,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef double dd;
typedef pair<ll , ll> ii;
typedef tuple < ll, ll, ll > tp;
#define ff first
#define ss second
#define pb push_back
#define in insert
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clz(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcount(n)
#define clean fflush(stdout)
const ll mod = (ll) 998244353;
// const ll mod = (ll) 1e9 + 7;
const ll inf = numeric_limits<int>::max()-5;
const ll INF = (ll)2e18;
// ll dx[]={0,1,0,-1};
// ll dy[]={1,0,-1,0};
// ll dxx[]={0,1,0,-1,1,1,-1,-1};
// ll dyy[]={1,0,-1,0,1,-1,1,-1};
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll N = 450;
vector < ll > R[450], sz[450];
vector < ii > req[450];
ll lx[450], rx[450], S[450]; ii range[450 * 450];
ll block_cnt = 1;
void add(ll l, ll r){
for(ll block = 0; block < block_cnt; block++){
if(lx[block] <= l && l <= rx[block]){
S[block]++;
R[block].pb(r);
sz[block].pb(r - l + 1);
req[block].pb({l, r});
for(ll i = S[block] - 1; i >= 1; i--){
if(R[block][i - 1] > R[block][i]) swap(R[block][i], R[block][i - 1]);
if(sz[block][i - 1] > sz[block][i]) swap(sz[block][i], sz[block][i - 1]);
if(req[block][i - 1] > req[block][i]) swap(req[block][i], req[block][i - 1]);
}
return;
}
}
}
void remove(ll l, ll r){
// NOTE: must TLE for multiple l
for(ll block = 0; block < block_cnt; block++){
if(lx[block] <= l && l <= rx[block] && S[block]){
auto it = lower_bound(req[block].begin(), req[block].begin() + S[block], make_pair(l, r));
if(it == req[block].end() || *it != make_pair(l, r)) continue;
S[block]--;
for(ll i = 0; i < req[block].size(); i++){
if(req[block][i] == make_pair(l, r)){
req[block].erase(req[block].begin() + i);
break;
}
}
for(ll i = 0; i < R[block].size(); i++){
if(R[block][i] == r){
R[block].erase(R[block].begin() + i);
break;
}
}
for(ll i = 0; i < sz[block].size(); i++){
if(sz[block][i] == r - l + 1){
sz[block].erase(sz[block].begin() + i);
break;
}
}
return;
}
}
}
ll query(ll lastans, ll t){
ll l, r, k; cin >> l >> r >> k;
l ^= t * lastans;
r ^= t * lastans;
if(l > r) swap(l, r);
if(r - l + 1 < k){
return 0;
}
ll ans = 0;
if(k == 0){
for(ll i = 0; i < block_cnt; i++) ans += req[i].size();
return ans;
}
for(ll i = 0; i < block_cnt; i++){
if( ((long long)lx[i]) + k - 1 > r) break;
if(rx[i] <= l){
if(!S[i]) continue;
ans += (S[i] - (upper_bound(R[i].begin(), R[i].begin() + S[i], l + k - 2) - R[i].begin()));
// for(auto u : R[i]){
// ans += (u >= l + k - 1);
// }
continue;
}
if(l <= lx[i] && ((long long) rx[i]) + k - 1 <= r){
if(!S[i]) continue;
ans += (S[i] - (upper_bound(sz[i].begin(), sz[i].begin() + S[i], k - 1) - sz[i].begin()));
continue;
}
for(auto [x, y] : req[i]){
ans += ( (min(y, r) - max(l, x) + 1) >= k);
}
}
return ans;
}
void build(){
vector < ii > a;
for(ll i = 0; i < block_cnt; i++){
for(auto x : req[i]) a.pb(x);
R[i].clear(); sz[i].clear(); req[i].clear();
S[i] = 0;
}
sort(a.begin(), a.end());
block_cnt = (a.size() - 1) / N; block_cnt++;
for(ll i = 0; i < a.size(); i++){
auto [l, r] = a[i];
R[i / N].pb(r);
sz[i / N].pb(r - l + 1);
req[i / N].pb(a[i]);
S[i / N]++;
}
for(ll i = 0; i < block_cnt; i++){
sort(R[i].begin(), R[i].end());
sort(sz[i].begin(), sz[i].end());
}
lx[0] = 0; rx[block_cnt - 1] = inf;
for(ll i = 1; i < block_cnt; i++){
lx[i] = rx[i - 1] = req[i][0].ff;
}
return;
}
void solve(){
ll n, t; cin >> n >> t;
ll changes = 0;
ll cur = 0;
lx[0] = 0; rx[0] = inf; S[0] = 0;
ll lastans = 0;
mem(S, 0);
while(n--){
ll T; cin >> T;
if(T == 1){
cin >> range[++cur].ff >> range[cur].ss;
range[cur].ff ^= (t * lastans);
range[cur].ss ^= (t * lastans);
if(range[cur].ff > range[cur].ss) swap(range[cur].ff, range[cur].ss);
add(range[cur].ff, range[cur].ss);
changes++;
}
if(T == 2){
ll id; cin >> id;
remove(range[id].ff, range[id].ss);
}
if(T == 3){
lastans = query(lastans, t);
cout << lastans << '\n';
}
if(changes >= N){
changes = 0;
build();
}
}
return;
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
auto start_time = clock();
#else
// freopen("subsequence.in", "r", stdin);
// freopen("subsequence.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#endif
//precalc();
ll T = 1, CT = 0; //cin >> T;
while(T--){
// cout << "Case #" << ++CT << ": ";
solve();
}
#ifdef LOCAL
auto end_time = clock();
cerr<< "Execution time: "<<(end_time - start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
#endif
return 0;
}
Compilation message (stderr)
segments.cpp: In function 'void remove(ll, ll)':
segments.cpp:74:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(ll i = 0; i < req[block].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~~
segments.cpp:80:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(ll i = 0; i < R[block].size(); i++){
| ~~^~~~~~~~~~~~~~~~~
segments.cpp:86:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(ll i = 0; i < sz[block].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
segments.cpp: In function 'void build()':
segments.cpp:145:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
145 | for(ll i = 0; i < a.size(); i++){
| ~~^~~~~~~~~~
segments.cpp: In function 'void solve()':
segments.cpp:179:26: warning: operation on 'cur' may be undefined [-Wsequence-point]
179 | cin >> range[++cur].ff >> range[cur].ss;
| ^~~~~
segments.cpp: In function 'int main()':
segments.cpp:217:15: warning: unused variable 'CT' [-Wunused-variable]
217 | ll T = 1, CT = 0; //cin >> T;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |