제출 #908909

#제출 시각아이디문제언어결과실행 시간메모리
908909daoquanglinh2007Segments (IZhO18_segments)C++17
75 / 100
4719 ms42468 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair <int, int> #define fi first #define se second #define mp make_pair #define isz(a) (int)(a).size() const int NM = 2e5, BL = 2e4, inf = 2e9+11; int n, t, type[NM+5], a[NM+5], b[NM+5], id[NM+5], k[NM+5], lastans = 0; int num = 0, l[NM+5], r[NM+5]; bool del[NM+5]; int sz, sz1, sz2; vector <pii> v; vector <int> arr, arr1, arr2; vector <pii> bit1[NM+5], bit2[NM+5]; int cnt[NM+5]; void update(int n, vector <pii> bit[NM+5], int x, int y){ while (x <= n){ if (bit[x].empty()){ bit[x].push_back(mp(y, 1)); } else if (bit[x].back().fi < y){ bit[x].push_back(mp(y, bit[x].back().se+1)); } else{ bit[x].back().se++; } x += x & (-x); } } int get(vector <pii> bit[NM+5], int x, int y){ int res = 0, z; while (x > 0){ if (bit[x].empty() || y < bit[x][0].fi); else if (y >= bit[x].back().fi){ res += bit[x].back().se; } else{ z = upper_bound(bit[x].begin(), bit[x].end(), mp(y, +inf))-bit[x].begin(); res += bit[x][z-1].se; } x -= x & (-x); } return res; } void process(){ v.clear(); arr.clear(); arr1.clear(); arr2.clear(); for (int i = 1; i <= num; i++) if (!del[i]){ v.push_back(mp(l[i], r[i])); arr.push_back(-(r[i]-l[i]+1)); arr1.push_back(-l[i]); arr2.push_back(r[i]); } sort(v.begin(), v.end(), [&](pii a, pii b){ return a.se-a.fi+1 > b.se-b.fi+1; }); sort(arr.begin(), arr.end()); arr.erase(unique(arr.begin(), arr.end()), arr.end()); sort(arr1.begin(), arr1.end()); arr1.erase(unique(arr1.begin(), arr1.end()), arr1.end()); sort(arr2.begin(), arr2.end()); arr2.erase(unique(arr2.begin(), arr2.end()), arr2.end()); sz = isz(arr), sz1 = isz(arr1), sz2 = isz(arr2); assert(sz <= NM); assert(sz1 <= NM); assert(sz2 <= NM); for (int i = 1; i <= sz1; i++) bit1[i].clear(); for (int i = 1; i <= sz2; i++) bit2[i].clear(); memset(cnt, 0, sizeof(cnt)); int j = 0; for (pii P : v){ update(sz1, bit1, lower_bound(arr1.begin(), arr1.end(), -P.fi)-arr1.begin()+1, -(P.se-P.fi+1)); update(sz2, bit2, lower_bound(arr2.begin(), arr2.end(), P.se)-arr2.begin()+1, -(P.se-P.fi+1)); while (arr[j] < -(P.se-P.fi+1)) j++; cnt[j+1]++; } for (int i = 1; i <= sz; i++) cnt[i] += cnt[i-1]; } int find_pos(vector <int> &v, int x){ if (v.empty()) return 0; if (x < v[0]) return 0; if (x >= v.back()) return isz(v); return upper_bound(v.begin(), v.end(), x)-v.begin(); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> t; for (int i = 0; i < n; i++){ cin >> type[i]; if (type[i] == 1){ cin >> a[i] >> b[i]; a[i] ^= (t*lastans), b[i] ^= (t*lastans); if (a[i] > b[i]) swap(a[i], b[i]); l[++num] = a[i], r[num] = b[i]; } else if (type[i] == 2){ cin >> id[i]; del[id[i]] = 1; } else{ cin >> a[i] >> b[i] >> k[i]; a[i] ^= (t*lastans), b[i] ^= (t*lastans); if (a[i] > b[i]) swap(a[i], b[i]); if (b[i]-a[i]+1 < k[i]) lastans = 0; else{ lastans = cnt[find_pos(arr, -k[i])]-get(bit1, find_pos(arr1, -b[i]+k[i]-2), -k[i]) -get(bit2, find_pos(arr2, a[i] < +inf-(k[i]-2) ? a[i]+k[i]-2 : +inf), -k[i]); for (int j = i-i%BL; j < i; j++){ if (type[j] == 1){ int lo = max(a[j], a[i]), hi = min(b[j], b[i]); if (hi-lo+1 >= k[i]) lastans++; } else if (type[j] == 2){ int lo = max(l[id[j]], a[i]), hi = min(r[id[j]], b[i]); if (hi-lo+1 >= k[i]) lastans--; } } } cout << lastans << '\n'; } if (i%BL == BL-1 && i < n-1){ process(); } } 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...