제출 #682675

#제출 시각아이디문제언어결과실행 시간메모리
682675phoenixSegments (IZhO18_segments)C++17
100 / 100
2383 ms15132 KiB
#include<bits/stdc++.h> using namespace std; const int N = 200000; const int B = 1800; void UGABUGA(bool f) { if(!f) { } } struct SQRT { struct obj { int key; int val; obj(int key, int val) : key(key), val(val) {} }; bool equal(obj a, obj b) { return (a.key == b.key && a.val == b.val); } vector<obj> arr[N / B + 5]; vector<int> st[N / B + 5]; int sz = 0, b_num = 0; void add(int key, int val) { int block = 0; while(block < b_num - 1 && (arr[block].empty() || arr[block].back().key < key)) block++; int pos_arr = 0, pos_st = 0; for(int i = 0; i < (int)arr[block].size(); i++) { if(arr[block][i].key < key || (arr[block][i].key == key && arr[block][i].val < val)) pos_arr++; if(st[block][i] < val) pos_st++; } if(!sz) b_num = 1; sz++; st[block].insert(st[block].begin() + pos_st, val); arr[block].insert(arr[block].begin() + pos_arr, obj(key, val)); } void del(int key, int val) { int block = 0; while(block < b_num - 1 && (arr[block].empty() || arr[block].back().key < key)) block++; int pos_arr = 0, pos_st = 0; for(int i = 0; i < (int)arr[block].size(); i++) { if(arr[block][i].key < key || (arr[block][i].key == key && arr[block][i].val < val)) pos_arr++; if(st[block][i] < val) pos_st++; } assert(pos_arr < (int)arr[block].size() && equal(arr[block][pos_arr], obj(key, val))); // assert(pos_arr < (int)arr[block].size()); arr[block].erase(arr[block].begin() + pos_arr); assert(pos_st < (int)st[block].size() && st[block][pos_st] == val); // assert(pos_st < (int)st[block].size()); st[block].erase(st[block].begin() + pos_st); sz--; if(!sz) b_num = 0; } int get(int k, int x) { int ans = 0; int block_p = b_num - 1; while(block_p >= 0 && (arr[block_p].empty() || arr[block_p].front().key >= k)) { int lb = -1, rb = arr[block_p].size(); while(rb - lb > 1) { int m = (lb + rb) / 2; if(st[block_p][m] < x) lb = m; else rb = m; } ans += lb + 1; block_p--; } if(block_p < 0) return ans; int arr_p = arr[block_p].size() - 1; while(arr_p >= 0 && arr[block_p][arr_p].key >= k) { ans += (arr[block_p][arr_p].val < x); arr_p--; } return ans; } void normalize() { vector<obj> v; for(int i = 0; i < b_num; i++) { for(obj x : arr[i]) v.push_back(x); } for(int i = 0; i < sz; i++) { if(i % B == 0 && !arr[i / B].empty()) { arr[i / B].clear(); st[i / B].clear(); } arr[i / B].push_back(v[i]); st[i / B].push_back(v[i].val); } b_num = (sz - 1) / B + 1; for(int i = 0; i < b_num; i++) sort(st[i].begin(), st[i].end()); } }; SQRT ll, rr; int lastans; vector<pair<int, int>> v; int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); v.push_back({-1, -1}); int n, t; cin >> n >> t; for(int iter = 1; iter <= n; iter++) { int type; cin >> type; if(type == 1) { int l, r; cin >> l >> r; l = (l ^ (t * lastans)); r = (r ^ (t * lastans)); if(l > r) swap(l, r); v.push_back({l, r}); int len = r - l + 1; ll.add(len, l); rr.add(len, r); } if(type == 2) { int id; cin >> id; ll.del(v[id].second - v[id].first + 1, v[id].first); rr.del(v[id].second - v[id].first + 1, v[id].second); } if(type == 3) { int l, r, k; cin >> l >> r >> k; l = (l ^ (t * lastans)); r = (r ^ (t * lastans)); if(l > r) swap(l, r); lastans = 0; if(r - l + 1 < k) { cout << 0 << '\n'; continue; } lastans = ll.get(k, r - k + 2) - rr.get(k, l + k - 1); cout << lastans << '\n'; } if(iter % B == 0) { ll.normalize(); rr.normalize(); } } }
#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...