Submission #758573

#TimeUsernameProblemLanguageResultExecution timeMemory
758573scanhexSegments (IZhO18_segments)C++17
0 / 100
5031 ms2012 KiB
#include <bits/stdc++.h> using namespace std; using nagai = long long; struct dss { vector<pair<int,int>> segs; void insert(int l, int r) { segs.push_back({l, r}); } int get(int l, int r, int k) { if (k == 0) return segs.size(); int res = 0; for (auto& x : segs) { int ll = max(x.first, l), rr = min(x.second, r); if (rr - ll + 1 >= k) ++res; } return res; } }; const int oo = 0x3f3f3f3f; struct static1d { vector<int> coords; void clear() { coords.clear(); } void add(int c) { coords.push_back(c); } void finalize() { sort(coords.begin(), coords.end()); } int get(int l, int r) { if (l > r) return 0; auto itr = upper_bound(coords.begin(), coords.end(), r); auto itl = lower_bound(coords.begin(), coords.end(), l); //cerr << l << ' ' << r << ' ' << itr - itl << '\n'; return itr - itl; } }; struct static2d { vector<static1d> v; vector<int> xs; void add(int x, int y) { for (++x; x < v.size(); x = (x | x - 1) + 1) v[x].add(x); } void build(vector<pair<int,int>> pts) { xs.clear(); for (auto& x : v) x.clear(); for (auto& p : pts) xs.push_back(p.first); sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); v.resize(xs.size() + 1); for (auto p : pts) { add(lower_bound(xs.begin(), xs.end(), p.first) - xs.begin(), p.second); } for (int i = 0; i < xs.size(); ++i) v[i].finalize(); } int get(int xr, int y1, int y2) { ++xr; int xrr = xr; xr = lower_bound(xs.begin(), xs.end(), xr) - xs.begin(); int res = 0; for (; xr; xr &= xr - 1) res += v[xr].get(y1, y2); //cerr << xrr << ' ' << y1 << ' ' << y2 << ' ' << res << '\n'; return res; } // all inclusive int get(int x1, int x2, int y1, int y2) { if (x1 > x2) return 0; return get(x2, y1, y2) - get(x1 - 1, y1, y2); } }; const int BL = 1; struct rofl2d { vector<pair<int,int>> all; vector<pair<int,int>> block; static2d st; void insert(int x, int y) { block.push_back({x, y}); if (block.size() >= BL) { for (auto& x : block) all.push_back(x); block.clear(); st.build(all); } } int get(int x1, int x2, int y1, int y2) { int res = st.get(x1, x2, y1, y2); for (auto p : block) if (x1 <= p.first && p.first <= x2 && y1 <= p.second && p.second <= y2) ++res; return res; } }; struct ds { int tot = 0; rofl2d rofl_l, rofl_r; void insert(int l, int r) { ++tot; rofl_l.insert(l, r - l); rofl_r.insert(r, r - l); } int get(int l, int r, int k) { if (k == 0) return tot; int res = tot; //cerr << "rofl_l" << '\n'; res -= rofl_l.get(r - k + 2, oo, k - 1, oo); //cerr << "rofl_r" << '\n'; res -= rofl_r.get(0, l + k - 2, k - 1, oo); //cerr << "rofl_l" << '\n'; res -= rofl_l.get(0, oo, 0, k - 2); return res; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, t; cin >> n >> t; int lastans = 0; vector<pair<int, int>> segs; ds add, del; while (n--) { int tt; cin >> tt; if (tt == 1) { int a, b; cin >> a >> b; a ^= t * lastans; b ^= t * lastans; if (a > b) swap(a, b); segs.push_back({a, b}); add.insert(a, b); } else if (tt == 2) { int id; cin >> id; --id; del.insert(segs[id].first, segs[id].second); } else { int a, b, k; cin >> a >> b >> k; a ^= t * lastans; b ^= t * lastans; if (a > b) swap(a, b); lastans = add.get(a, b, k) - del.get(a, b, k); cout << lastans << '\n'; } } }

Compilation message (stderr)

segments.cpp: In member function 'void static2d::add(int, int)':
segments.cpp:53:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<static1d>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for (++x; x < v.size(); x = (x | x - 1) + 1)
      |             ~~^~~~~~~~~~
segments.cpp:53:38: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
   53 |   for (++x; x < v.size(); x = (x | x - 1) + 1)
      |                                    ~~^~~
segments.cpp: In member function 'void static2d::build(std::vector<std::pair<int, int> >)':
segments.cpp:69:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for (int i = 0; i < xs.size(); ++i)
      |                   ~~^~~~~~~~~~~
segments.cpp: In member function 'int static2d::get(int, int, int)':
segments.cpp:75:7: warning: unused variable 'xrr' [-Wunused-variable]
   75 |   int xrr = xr;
      |       ^~~
#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...