Submission #440564

#TimeUsernameProblemLanguageResultExecution timeMemory
440564fhvirusSegments (IZhO18_segments)C++17
0 / 100
1 ms476 KiB
// 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 kN = 200002;
int n, t;

int tot = 0;
bool occ[kN];
priority_queue<int, vector<int>, greater<int>> pq;
int newID(){
	if(!pq.empty()){
		int r = pq.top(); pq.pop();
		occ[r] = true;
		return r;
	}
	++tot;
	occ[tot] = true;
	return tot;
}
void delID(int id){
	assert(occ[id]);
	occ[id] = false;
	pq.push(id);
}

pii seg[kN];

void insert(int l, int r){
	int id = newID();
	seg[id] = pii(l, r);
}
void remove(int id){
	delID(id);
}
int query(int ql, int qr, int k){
	if(qr - ql + 1 < k) return 0;
	int ans = 0;
	for(int i = 1; i <= tot; ++i){
		if(!occ[i]) continue;
		auto [l, r] = seg[i];
		if(r >= qr) ans += (qr - l + 1 >= k);
		else ans += (r - ql + 1 >= k);
	}
	return ans;
}

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> t;
	assert(n <= 10000);
	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;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...