제출 #58851

#제출 시각아이디문제언어결과실행 시간메모리
58851BenqSegments (IZhO18_segments)C++14
55 / 100
1504 ms41960 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define F0R(i, a) for (int i=0; i<(a); i++) #define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() const int MOD = 0; const ll INF = 1e18; const int MX = 200001; int NUM = 250; int TOT = 200000; int n,t,ans, L[MX], R[MX]; short cbucket[MX], bucketsz[MX]; int buckety[2*MX], bucketyx[2*MX], lst[2*MX], v[MX]; bool cmp(int l, int r) { if (L[l] != L[r]) return L[l] < L[r]; return l < r; } void rebuild() { int co = 0; F0R(i,NUM) { int st = 2*TOT/NUM*i; FOR(j,st,st+bucketsz[i]) v[co++] = lst[j]; bucketsz[i] = 0; } F0R(i,NUM) { int st = 2*TOT/NUM*i; FOR(j,i*co/NUM,(i+1)*co/NUM) { cbucket[v[j]] = i; int ind = st+bucketsz[i]; buckety[ind] = R[v[j]]; bucketyx[ind] = R[v[j]]-L[v[j]]; lst[ind] = v[j]; bucketsz[i] ++; } int en = st+bucketsz[i]; sort(buckety+st,buckety+en); sort(bucketyx+st,bucketyx+en); } } void ins(int* v0, int* v1, int x, int ad = 1) { auto it = lb(v0,v1,x); if (ad == 1) { *v1 = x; rotate(it,v1,v1+1); } else { rotate(it,it+1,v1); } } void insLst(int* v0, int* v1, int x, int ad = 1) { auto it = lb(v0,v1,x,cmp); if (ad == 1) { *v1 = x; rotate(it,v1,v1+1); } else { rotate(it,it+1,v1); } } void INS(int id, int ad = 1) { int b = cbucket[id]; int st = 2*TOT/NUM*b, en = st+bucketsz[b]; ins(buckety+st,buckety+en,R[id],ad); ins(bucketyx+st,bucketyx+en,R[id]-L[id],ad); insLst(lst+st,lst+en,id,ad); bucketsz[b] += ad; } void upd(int id, int l, int r) { L[id] = l, R[id] = r; int b = 0; while (b+1 < NUM && (bucketsz[b] == 0 || cmp(lst[2*TOT/NUM*b+bucketsz[b]-1],id))) b ++; cbucket[id] = b; INS(id); } int hix, loy, loyx; int manual(int x, int l) { int t = 0; FOR(i,2*TOT/NUM*x,2*TOT/NUM*x+bucketsz[x]) { if (L[lst[i]] > hix) continue; if (L[lst[i]] > l) t += (R[lst[i]]-L[lst[i]] >= loyx); else t += (R[lst[i]] >= loy); } return t; } int atLeast(int* l, int* r, int y) { return distance(lb(l,r,y),r); } int query(int l, int r, int k) { if (k > r-l+1) return 0; hix = r-k+1, loy = l+k-1, loyx = k-1; int ans = 0, clst = -MOD; F0R(i,NUM) if (bucketsz[i]) { int st = 2*TOT/NUM*i, en = st+bucketsz[i]; int x = lst[en-1]; if (L[x] > hix) { ans += manual(i,l); break; } else if (L[x] > l) { if (clst <= l) ans += manual(i,l); else ans += atLeast(bucketyx+st,bucketyx+en,loyx); } else { ans += atLeast(buckety+st,buckety+en,loy); } clst = L[x]; } return ans; } int getR() { return rand() % (1<<30); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> t; int cur = 0, nex = 1; F0R(i,n) { // int z = 2*(rand()&1)+1; int z; cin >> z; if (z == 1) { // int l = getR(),r = getR(); int l,r; cin >> l >> r; l ^= (t*ans), r ^= (t*ans); if (l > r) swap(l,r); upd(nex++,l,r); } else if (z == 2) { int id; cin >> id; INS(id,-1); } else { // int l = getR(),r = getR(),k = 500; int l,r,k; cin >> l >> r >> k; l ^= (t*ans), r ^= (t*ans); if (l > r) swap(l,r); ans = query(l,r,k); cout << ans << "\n"; } cur ++; if (cur % (TOT/NUM) == 0) rebuild(); } } /* Look for: * the exact constraints (multiple sets are too slow for n=10^6 :( ) * special cases (n=1?) * overflow (ll vs int?) * array bounds */
#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...