Submission #1088392

#TimeUsernameProblemLanguageResultExecution timeMemory
1088392vladiliusSegments (IZhO18_segments)C++17
7 / 100
269 ms65536 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second const int N = 2e9; struct ordered_set{ vector<int> a; void init(){ a = {}; } void add(int x){ a.pb(x); } int get(int x){ int out = 0; for (int i: a){ out += (i <= x); } return out; } int get(int l, int r){ return get(r) - get(l - 1); } }; struct DS{ struct node{ node *l, *r; ordered_set st, ln; node(){ l = r = 0; st.init(); ln.init(); } }; ordered_set all; node *rt, *rt1; void init(){ rt = new node(); rt1 = new node(); } void add(node *v, int tl, int tr, int& l, int& r){ v -> st.add(r); v -> ln.add(r - l + 1); if (tl == tr) return; int tm = (tl + tr) / 2; if (l <= tm){ if (!(v -> l)) v -> l = new node(); add(v -> l, tl, tm, l, r); } else { if (!(v -> r)) v -> r = new node(); add(v -> r, tm + 1, tr, l, r); } } void add1(node *v, int tl, int tr, int& l, int& r){ v -> ln.add(r - l + 1); if (tl == tr) return; int tm = (tl + tr) / 2; if (r <= tm){ if (!(v -> l)) v -> l = new node(); add1(v -> l, tl, tm, l, r); } else { if (!(v -> r)) v -> r = new node(); add1(v -> r, tm + 1, tr, l, r); } } void add(int l, int r){ add(rt, 1, N, l, r); add1(rt1, 1, N, l, r); all.add(r - l + 1); } int get1(node *v, int tl, int tr, int l, int r, int k){ if (l > tr || r < tl) return 0; if (l <= tl && tr <= r){ return v -> st.get(k, N); } int tm = (tl + tr) / 2, s = 0; if (v -> l) s += get1(v -> l, tl, tm, l, r, k); if (v -> r) s += get1(v -> r, tm + 1, tr, l, r, k); return s; } int get1(int l, int r){ return get1(rt, 1, N, 1, l, r); } int get2(node *v, int tl, int tr, int l, int r, int k){ if (l > tr || r < tl || l > r) return 0; if (l <= tl && tr <= r){ return v -> ln.get(k, N); } int tm = (tl + tr) / 2, s = 0; if (v -> l) s += get2(v -> l, tl, tm, l, r, k); if (v -> r) s += get2(v -> r, tm + 1, tr, l, r, k); return s; } int get2(int l, int r, int k){ if (l > r) return 0; return all.get(k, N) - get2(rt, 1, N, 1, l - 1, k) - get2(rt1, 1, N, r + 1, N, k); } int get(int l, int r, int k){ if ((r - l + 1) < k) return 0; return get1(l, l + k - 1) + get1(r - k + 1, r) + get2(l + 1, r - 1, k); } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q, cc = 0, out = 0; bool t; cin>>q>>t; pii f[q + 1]; DS T1, T2; T1.init(); T2.init(); while (q--){ int type; cin>>type; if (type == 1){ int l, r; cin>>l>>r; l = (l ^ (t * out)); r = (r ^ (t * out)); if (l > r) swap(l, r); T1.add(l, r); f[++cc] = {l, r}; } else if (type == 2){ int i; cin>>i; T2.add(f[i].ff, f[i].ss); } else { int l, r, k; cin>>l>>r>>k; l = (l ^ (t * out)); r = (r ^ (t * out)); if (l > r) swap(l, r); out = T1.get(l, r, k) - T2.get(l, r, k); cout<<out<<"\n"; } } }
#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...