This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll;
#define ff first
#define ss second
#define pb emplace_back
#define AI(x) begin(x),end(x)
template<class I>bool chmax(I&a,I b){return a<b?(a=b,true):false;}
template<class I>bool chmin(I&a,I b){return b<a?(a=b,true):false;}
#ifdef OWO
#define debug(args...) SDF(#args, args)
#define OIU(args...) ostream& operator<<(ostream&O,args)
#define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;}
LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss)
template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));}
template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));}template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';}template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';}
#else
#pragma GCC optimize("Ofast")
#define debug(...) ((void)0)
#endif
const int inf = INT_MAX;
struct PRE : vector<pii> {
void build(){
if(empty()) return;
sort(AI());
auto i = begin(), j = next(i);
while(j != end()){
if(i->ff == j->ff) i->ss += j->ss;
else ++i, *i = *j, i->ss += prev(i)->ss;
++j;
}
erase(next(i), end());
}
int query(int p){
auto i = lower_bound(AI(), pii(p, inf));
return (i == begin() ? 0 : prev(i)->ss);
}
};
const int kN = 200002;
int n, t;
int tot = 0;
pii seg[kN];
int cnt, bnd;
PRE sl, sr;
vector<tuple<int, int, int>> tmp;
void eek(){
++cnt; if(cnt < bnd) return;
cnt = 0;
// rebuild
for(auto [l, r, v]: tmp){
sl.pb(l, v);
sr.pb(r, v);
}
tmp.clear();
debug(sl, sr);
sl.build();
sr.build();
debug(sl, sr);
}
void insert(int l, int r){
seg[++tot] = pii(l, r);
tmp.pb(l, r, 1);
eek();
}
void remove(int id){
auto [l, r] = seg[id];
tmp.pb(l, r, -1);
eek();
}
int query(int ql, int qr, int k){
//assert(k == 1);
//debug(sl, sr);
// #( l <= qr ) - #( r < ql )
int ans = sl.query(qr) - sr.query(ql-1);
for(auto [l, r, v]: tmp){
if(l <= qr) ans += v;
if(r < ql) ans -= v;
}
return ans;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> t;
bnd = ceil(sqrt(n));
int lastans = 0;
for(int cmd, a, b, k, id, i = 0; i < n; ++i){
cin >> cmd;
if(cmd == 1){
cin >> a >> b;
int l = (a ^ (lastans * t));
int r = (b ^ (lastans * t));
if(l > r) swap(l, r);
insert(l, r);
} else if(cmd == 2){
cin >> id;
remove(id);
} else if(cmd == 3){
cin >> a >> b >> k;
int l = (a ^ (lastans * t));
int r = (b ^ (lastans * t));
if(l > r) swap(l, r);
lastans = query(l, r, k);
cout << lastans << '\n';
}
}
return 0;
}
Compilation message (stderr)
segments.cpp: In function 'void eek()':
segments.cpp:56:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
56 | for(auto [l, r, v]: tmp){
| ^
segments.cpp: In function 'void remove(int)':
segments.cpp:72:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
72 | auto [l, r] = seg[id];
| ^
segments.cpp: In function 'int query(int, int, int)':
segments.cpp:81:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
81 | for(auto [l, r, v]: tmp){
| ^
# | 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... |