This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define isz(a) (int)(a).size()
const int NM = 1e5, BL = 10000, inf = INT_MAX;
int n, t, type[NM+5], a[NM+5], b[NM+5], id[NM+5], k[NM+5], lastans = 0;
int num = 0, l[NM+5], r[NM+5];
bool del[NM+5];
int sz;
vector <int> arr;
vector <int> node1[NM+5], node2[NM+5];
vector <int> bit1[NM+5], bit2[NM+5];
int cnt[NM+5];
void fake_update1(int x, int y){
while (x <= sz){
node1[x].push_back(y);
x += x & (-x);
}
}
void fake_update2(int x, int y){
while (x <= sz){
node2[x].push_back(y);
x += x & (-x);
}
}
void update1(int x, int yy){
while (x <= sz){
int y = lower_bound(node1[x].begin(), node1[x].end(), yy)-node1[x].begin()+1;
while (y <= isz(node1[x])){
bit1[x][y]++;
y += y & (-y);
}
x += x & (-x);
}
}
void update2(int x, int yy){
while (x <= sz){
int y = lower_bound(node2[x].begin(), node2[x].end(), yy)-node2[x].begin()+1;
while (y <= isz(node2[x])){
bit2[x][y]++;
y += y & (-y);
}
x += x & (-x);
}
}
void update_cnt(int x){
while (x <= sz){
cnt[x]++;
x += x & (-x);
}
}
int find_pos(vector <int> &v, int x){
if (v.empty()) return 0;
if (x < v[0]) return 0;
if (x >= v.back()) return isz(v);
return upper_bound(v.begin(), v.end(), x)-v.begin();
}
int find_pos_ll(vector <int> &v, int x){
if (v.empty()) return 0;
if (x < v[0]) return 0;
if (x >= v.back()) return isz(v);
return upper_bound(v.begin(), v.end(), x)-v.begin();
}
int get1(int x, int yy){
int res = 0;
while (x > 0){
int y = find_pos_ll(node1[x], yy);
while (y > 0){
res += bit1[x][y];
y -= y & (-y);
}
x -= x & (-x);
}
return res;
}
int get2(int x, int yy){
int res = 0;
while (x > 0){
int y = find_pos_ll(node2[x], yy);
while (y > 0){
res += bit2[x][y];
y -= y & (-y);
}
x -= x & (-x);
}
return res;
}
int get_cnt(int x){
int res = 0;
while (x > 0){
res += cnt[x];
x -= x & (-x);
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> t;
for (int i = 0; i < n; i++){
cin >> type[i];
if (type[i] == 1){
cin >> a[i] >> b[i];
a[i] ^= (t*lastans), b[i] ^= (t*lastans);
if (a[i] > b[i]) swap(a[i], b[i]);
l[++num] = a[i], r[num] = b[i];
}
else if (type[i] == 2){
cin >> id[i];
del[id[i]] = 1;
}
else{
cin >> a[i] >> b[i] >> k[i];
a[i] ^= (t*lastans), b[i] ^= (t*lastans);
if (a[i] > b[i]) swap(a[i], b[i]);
lastans = get_cnt(find_pos(arr, -k[i]))-get1(find_pos(arr, -k[i]), -b[i]+k[i]-2)
-get2(find_pos(arr, -k[i]), (a[i] < +inf-(k[i]-2) ? a[i]+k[i]-2 : +inf));
for (int j = i-i%BL; j < i; j++){
if (type[j] == 1){
int lo = max(a[j], a[i]), hi = min(b[j], b[i]);
if (hi-lo+1 >= k[i]) lastans++;
}
else if (type[j] == 2){
int lo = max(l[id[j]], a[i]), hi = min(r[id[j]], b[i]);
if (hi-lo+1 >= k[i]) lastans--;
}
}
cout << lastans << '\n';
}
if (i%BL == BL-1 && i < n-1){
arr.clear();
for (int j = 1; j <= num; j++)
if (!del[j]){
arr.push_back(-(r[j]-l[j]+1));
}
sort(arr.begin(), arr.end());
arr.erase(unique(arr.begin(), arr.end()), arr.end());
sz = isz(arr);
for (int j = 1; j <= sz; j++){
node1[j].clear();
node2[j].clear();
}
for (int j = 1; j <= num; j++){
if (del[j]) continue;
int x = lower_bound(arr.begin(), arr.end(), -(r[j]-l[j]+1))-arr.begin()+1;
fake_update1(x, -l[j]);
fake_update2(x, r[j]);
}
for (int j = 1; j <= sz; j++){
sort(node1[j].begin(), node1[j].end());
sort(node2[j].begin(), node2[j].end());
bit1[j].assign(isz(node1[j])+1, 0);
bit2[j].assign(isz(node2[j])+1, 0);
}
memset(cnt, 0, sizeof(cnt));
for (int j = 1; j <= num; j++){
if (del[j]) continue;
int x = lower_bound(arr.begin(), arr.end(), -(r[j]-l[j]+1))-arr.begin()+1;
update1(x, -l[j]);
update2(x, r[j]);
update_cnt(x);
}
}
}
return 0;
}
# | 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... |