이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree <pair <int, int>, null_type, less <pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
#define ll long long
#define db double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define size(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"
//#define int long long
using namespace std;
void dout() {
cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
cerr << H << ' ';
dout(T...);
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
const int N = 200003, K = 1877;
int n, t, modify, m, cnt;
pii seg[N];
vector <int> tmp;
bool cur[N];
int arr[N];
bool cmp(const int & a, const int & b) {
return seg[a].fi < seg[b].fi;
}
vector <int> vec1[N / K + 1], vec2[N / K + 1];
void rebuild() {
for (auto i : tmp) {
if (i < 0) {
cur[-i] = false;
} else {
cur[i] = true;
}
}
tmp = {};
for (int i = 0; i < cnt; i++) {
arr[i] = 0;
}
cnt = 0;
for (int i = 1; i <= m; i++) {
if (cur[i]) {
arr[cnt] = i;
cnt++;
}
}
sort(arr, arr + cnt, cmp);
int b = (cnt - 1) / K + 1;
for (int i = 0; i < b; i++) {
vec1[i] = {};
vec2[i] = {};
}
for (int i = 0; i < cnt; i++) {
vec1[i / K].pb(seg[arr[i]].se);
vec2[i / K].pb(seg[arr[i]].se - seg[arr[i]].fi);
}
for (int i = 0; i < b; i++) {
sort(all(vec1[i]));
sort(all(vec2[i]));
}
}
int query(int l, int r, int k) {
if (r - l < k) {
return 0;
}
int i = 0, res = 0;
while (i < cnt) {
if (seg[arr[i]].fi > r - k) {
break;
}
if (i % K == 0 && seg[arr[min(cnt - 1, i + K - 1)]].fi < l) {
i += K;
continue;
}
if (seg[arr[i]].fi < l) {
i++;
continue;
}
if (i % K == 0 && seg[arr[min(cnt - 1, i + K - 1)]].fi <= r - k) {
int num = i / K;
res += size(vec2[num]) - (lower_bound(all(vec2[num]), k) - vec2[num].begin());
i += K;
} else {
res += (seg[arr[i]].se - seg[arr[i]].fi >= k);
i++;
}
}
i = 0;
while (i < cnt) {
if (seg[arr[i]].fi >= l) {
break;
}
if (i % K == 0 && seg[arr[min(cnt - 1, i + K - 1)]].fi < l) {
int num = i / K;
res += size(vec1[num]) - (lower_bound(all(vec1[num]), l + k) - vec1[num].begin());
i += K;
} else {
res += (seg[arr[i]].se >= l + k);
i++;
}
}
int L, R;
for (auto i : tmp) {
if (i < 0) {
L = seg[-i].fi, R = seg[-i].se;
res -= (L >= l && L <= r - k && R - L >= k) + (L < l && R >= l + k);
} else {
L = seg[i].fi, R = seg[i].se;
res += (L >= l && L <= r - k && R - L >= k) + (L < l && R >= l + k);
}
}
return res;
}
void solve(int tc) {
// check for (int i = 0; i < n; j++)
cin >> n >> t;
int tp, id, a, b, k, last = -1;
for (int i = 0; i < n; i++) {
cin >> tp;
if (tp == 1) {
cin >> a >> b;
if (last != -1 && t == 1) {
a ^= last;
b ^= last;
}
if (a > b) {
swap(a, b);
}
b++;
m++;
seg[m] = {a, b};
tmp.pb(m);
modify++;
} else if (tp == 2) {
cin >> id;
tmp.pb(-id);
modify++;
} else {
cin >> a >> b >> k;
if (last != -1 && t == 1) {
a ^= last;
b ^= last;
}
if (a > b) {
swap(a, b);
}
b++;
last = query(a, b, k);
cout << last << endl;
}
if (modify == K) {
rebuild();
modify = 0;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int tc = 1;
// cin >> tc;
for (int i = 0; i < tc; i++) {
solve(i);
// cleanup();
}
}
# | 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... |