This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
int cnt = sizeof...(T);
((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
using namespace std;
using namespace __gnu_pbds;
template <typename T> using rbt = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef int64_t ll;
const int maxc = 2e9, inf = 1e9, K = 256, maxn = 100025;
pair<int,int> seg[maxn];
int segId = 0;
vector<tuple<int,int,int>> recent, total;
vector<tuple<int,int,int>> block[maxn];
int minLen[maxn], blockCnt;
vector<int> lens;
struct StaticPrefixSum {
vector<pair<int,int>> st;
int query(int x) {
auto it = lower_bound(st.begin(), st.end(), make_pair(x, -inf));
if (it == st.begin()) return 0;
return prev(it) -> second;
}
void add(int p, int v) {
st.emplace_back(p, v);
}
void clear() {
st.clear();
}
void build() {
sort(st.begin(), st.end());
int it = 0;
for (int i = 1; i < st.size(); i++) {
if (st[i].first != st[it].first) {
st[it++] = st[i];
} else {
st[it].second += st[i].second;
}
}
st.resize(it);
}
} lpref[maxn], rpref[maxn];
void build() {
sort(lens.begin(), lens.end(), greater<int>());
lens.erase(unique(lens.begin(), lens.end()), lens.end());
for (int i = 0; i < lens.size(); i++) minLen[i / K] = lens[i];
blockCnt = lens.size() / K;
for (int i = 0; i < blockCnt; i++) lpref[i].clear(), rpref[i].clear();
for (auto [l, r, v]: total) {
int id = lower_bound(lens.begin(), lens.end(), r - l) - lens.begin();
int bid = id / K;
block[id / K].emplace_back(l, r, v);
lpref[id / K].add(l, v);
rpref[id / K].add(-r, v);
}
for (int i = 0; i < blockCnt; i++) lpref[i].build(), rpref[i].build();
}
void add(int l, int r, int d) {
recent.emplace_back(l, r, d);
if (recent.size() == K) {
for (auto [l, r, v]: recent) {
lens.emplace_back(r - l);
total.emplace_back(l, r, v);
}
recent.clear();
build();
}
}
int query(int l, int r, int k) {
int res = 0;
for (int i = 0; i < blockCnt; i++) {
if (minLen[i] >= k) {
res += block[i].size() - rpref[i].query(l + k - 1) - lpref[i].query(-(r - k + 1));
} else {
for (auto [nl, nr, v]: block[i]) {
if (nr - nl >= k) {
res += v;
if (nr < l + k) res -= v;
if (nl > r - k) res -= v;
}
}
break;
}
}
for (auto [nl, nr, v]: recent) {
if (nr - nl >= k) {
res += v;
if (nr < l + k) res -= v;
if (nl > r - k) res -= v;
}
}
return res;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, encode;
cin >> n >> encode;
int ans = 0;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
if (t == 1) {
int a, b;
cin >> a >> b;
if (encode) a ^= ans, b ^= ans;
if (a > b) swap(a, b);
++b;
add(a, b, 1);
seg[segId++] = { a, b };
} else if (t == 2) {
int id;
cin >> id;
--id;
auto [a, b] = seg[id];
add(a, b, -1);
} else if (t == 3) {
int a, b, k;
cin >> a >> b >> k;
if (encode) a ^= ans, b ^= ans;
if (a > b) swap(a, b);
++b;
ans = query(a, b, k);
cout << ans << '\n';
}
}
}
/*
6 1
1 1 2
3 2 4 2
1 3 5
3 2 3 1
2 1
3 0 3 1
6 0
1 3 10
1 3 5
3 6 10 6
2 1
1 3 10
3 6 4 2
*/
Compilation message (stderr)
segments.cpp:2: warning: ignoring #pragma loop_opt [-Wunknown-pragmas]
2 | #pragma loop_opt(on)
|
segments.cpp: In member function 'void StaticPrefixSum::build()':
segments.cpp:48:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 1; i < st.size(); i++) {
| ~~^~~~~~~~~~~
segments.cpp: In function 'void build()':
segments.cpp:63:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int i = 0; i < lens.size(); i++) minLen[i / K] = lens[i];
| ~~^~~~~~~~~~~~~
segments.cpp:66:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
66 | for (auto [l, r, v]: total) {
| ^
segments.cpp:68:13: warning: unused variable 'bid' [-Wunused-variable]
68 | int bid = id / K;
| ^~~
segments.cpp: In function 'void add(int, int, int)':
segments.cpp:79:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
79 | for (auto [l, r, v]: recent) {
| ^
segments.cpp: In function 'int query(int, int, int)':
segments.cpp:94:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
94 | for (auto [nl, nr, v]: block[i]) {
| ^
segments.cpp:104:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
104 | for (auto [nl, nr, v]: recent) {
| ^
segments.cpp: In function 'int main()':
segments.cpp:134:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
134 | auto [a, b] = seg[id];
| ^
# | 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... |