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 <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <deque>
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define x first
#define y second
const string FILENAME = "input";
const int MAXN = 200228;
const int MAGIC = 1500;
//12:00
//17:00
int n, t;
int id = 0;
bool alive[MAXN];
int L[MAXN], R[MAXN];
int ids[MAXN];
int li[MAXN], ri[MAXN];
int lsz[MAXN], rsz[MAXN];
int cntin;
bool comp(const int &a, const int &b) {
return R[a] - L[a] + 1 < R[b] - L[b] + 1;
}
int cntsmall(int l, int r, int k) {
while (l != r){
int mid = (l + r) >> 1;
if (rsz[mid] - lsz[mid] + 1 >= k) {
r = mid;
} else {
l = mid + 1;
}
}
if (rsz[l] - lsz[l] + 1 < k) {
return l + 1;
}
return l;
}
int getl(int pos, int k) {
int res = 0;
int border = (pos / MAGIC + 1) * MAGIC;
for (int i = pos; i < min(border, cntin); i++) {
if (rsz[i] < k) {
res--;
}
}
for (int i = border; i < cntin; i += MAGIC){
int lb = i, rb = min(i + MAGIC, cntin);
int val = lower_bound(ri + lb, ri + rb, k) - ri - lb;
res -= val;
}
return res;
}
int getr(int pos, int k) {
int res = 0;
int border = (pos / MAGIC + 1) * MAGIC;
for (int i = pos; i < min(border, cntin); i++) {
if (lsz[i] > k) {
res--;
}
}
for (int i = border; i < cntin; i += MAGIC) {
int lb = i, rb = min(i + MAGIC, cntin);
int val = rb - (upper_bound(li + lb, li + rb, k) - li);
res -= val;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//read(FILENAME);
cin >> n >> t;
int cnt = 0;
vector<pair<pair<int, int>, bool> > st;
int pans = 0;
for (int it = 0; it < n; it++) {
if (sz(st) >= MAGIC) {
cntin = 0;
st.clear();
for (int i = 1; i < MAXN; i++) {
if (alive[i]) {
ids[cntin] = i;
cntin++;
}
}
sort(ids, ids + cntin, comp);
for (int i = 0; i < cntin; i++) {
li[i] = lsz[i] = L[ids[i]];
}
for (int i = 0; i < cntin; i++) {
ri[i] = rsz[i] = R[ids[i]];
}
for (int i = 0; i < cntin; i += MAGIC){
int lb = i, rb = min(i + MAGIC, cntin);
sort(li + lb, li + rb);
sort(ri + lb, ri + rb);
}
}
int type;
cin >> type;
if (type == 1) {
int l, r;
cin >> l >> r;
l ^= pans * t;
r ^= pans * t;
if (l > r) {
swap(l, r);
}
id++;
cnt++;
alive[id] = true;
L[id] = l;
R[id] = r;
st.pb({{l, r}, 1});
} else if (type == 2) {
int id1;
cin >> id1;
cnt--;
alive[id1] = false;
st.pb({{L[id1], R[id1]}, 0});
} else if (type == 3) {
int l, r, k;
cin >> l >> r >> k;
l ^= pans * t;
r ^= pans * t;
if (l > r) {
swap(l, r);
}
if (r - l + 1 < k) {
cout << 0 << '\n';
pans = 0;
continue;
}
int ans = cnt;
if (cntin) {
int pos = cntsmall(0, cntin - 1, k);
ans -= pos;
ans += getl(pos, l + k - 1);
ans += getr(pos, r - k + 1);
}
for (auto x: st) {
int tl = max(x.first.first, l);
int tr = min(x.first.second, r);
if (tr - tl + 1 < k) {
if (x.second) {
ans--;
} else {
ans++;
}
}
}
cout << ans << '\n';
pans = ans;
}
}
}
# | 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... |