Submission #758612

#TimeUsernameProblemLanguageResultExecution timeMemory
758612scanhexSegments (IZhO18_segments)C++17
0 / 100
2247 ms62548 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() { vector<int>{}.swap(coords); } void add(int c) { coords.push_back(c); } void finalize() { } 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 << "coords\n"; //for(auto& x : coords) //cerr << x << ' '; //cerr << '\n'; //cerr << l << ' ' << r << ' ' << itr - itl << '\n'; return itr - itl; } }; bool ycmp(pair<int, int> a, pair<int, int> b) { if (a.second != b.second) return a.second < b.second; return a.first < b.first; } struct static2d { vector<vector<int>> t; vector<vector<int>> ple, pri; int n; vector<int> xs; void add(int x, int y) { x += n; while (x > 0) t[x].push_back(y), x >>= 1; } void finalize(int u, int ul, int ur) { if (u >= n) return; int ptrle = 0, ptrri = 0; ple[u].resize(t[u].size()); pri[u].resize(t[u].size()); for (int i = 0; i < t[u].size(); ++i) { while (ptrle < t[2 * u].size() && t[2 * u][ptrle] < t[u][i]) ++ptrle; while (ptrri < t[2 * u + 1].size() && t[2 * u + 1][ptrri] < t[u][i]) ++ptrri; ple[u][i] = ptrle; pri[u][i] = ptrri; } ple[u].push_back(t[2 * u].size()); pri[u].push_back(t[2 * u + 1].size()); int um = (ul + ur) / 2; finalize(2 * u, ul, um); finalize(2 * u + 1, um, ur); } void build(vector<pair<int,int>> pts) { xs.clear(); for (auto& p : pts) xs.push_back(p.first); sort(xs.begin(), xs.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); n = 1; while (n < xs.size()) n *= 2; t.assign(2 * n, {}); ple.assign(2 * n, {}); pri.assign(2 * n, {}); for (auto p : pts) { add(lower_bound(xs.begin(), xs.end(), p.first) - xs.begin(), p.second); } finalize(1, 0, n); } int get(int u, int ul, int ur, int x1, int x2, int y1, int y2) { //cerr << u << ' ' << ul << ' ' << ur << ' ' << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << ' ' << ple[u].size() << ' ' << t[u].size() << '\n'; if (x2 <= ul || ur <= x1 || t[u].empty()) return 0; if (x1 <= ul && ur <= x2) { return y2 - y1; } int res = 0; int um = (ul + ur) / 2; res += get(u * 2, ul, um, x1, x2, ple[u][y1], ple[u][y2]); res += get(u * 2 + 1, um, ur, x1, x2, pri[u][y1], pri[u][y2]); return res; } // all inclusive int get(int x1, int x2, int y1, int y2) { if (n == 0) return 0; if (x1 > x2) return 0; x1 = lower_bound(xs.begin(), xs.end(), x1) - xs.begin(); x2 = upper_bound(xs.begin(), xs.end(), x2) - xs.begin(); y1 = lower_bound(t[1].begin(), t[1].end(), y1) - t[1].begin(); y2 = upper_bound(t[1].begin(), t[1].end(), y2) - t[1].begin(); return get(1, 0, n, x1, x2, y1, y2); } }; const int BL = 1000; struct rofl2d { vector<pair<int,int>> all; vector<pair<int,int>> block; vector<pair<int,int>> erblock; vector<pair<int, int>> newall; static2d st; void check_rebuild() { if (block.size() + erblock.size() >= BL) { sort(block.begin(), block.end(), ycmp); newall.resize(all.size() + block.size()); merge(all.begin(), all.end(), block.begin(), block.end(), newall.begin(), ycmp); sort(erblock.begin(), erblock.end(), ycmp); all.clear(); int ptr = 0; for (auto x : erblock) { while (ptr < newall.size() && ycmp(newall[ptr], x)) all.push_back(newall[ptr++]); // always true? ++ptr; } while (ptr < newall.size()) all.push_back(newall[ptr++]); block.clear(); erblock.clear(); st.build(all); } } void insert(int x, int y) { block.push_back({x, y}); check_rebuild(); } void erase(int x, int y) { erblock.push_back({x, y}); check_rebuild(); } 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; for (auto p : erblock) 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; rofl2d rofl_len; void insert(int l, int r) { ++tot; rofl_l.insert(l, r - l); rofl_r.insert(r, r - l); //rofl_len.insert(0, r - l); } void erase(int l, int r) { --tot; rofl_l.erase(l, r - l); rofl_r.erase(r, r - l); //rofl_len.erase(0, r - l); } int get(int l, int r, int k) { if (r - l + 1 < k) return 0; if (k == 0) return tot; int res = tot; //cerr << "rofl_l" << ' ' << res << '\n'; res -= rofl_l.get(r - k + 2, oo, k - 1, oo); //cerr << "rofl_r" << ' ' << res << '\n'; res -= rofl_r.get(0, l + k - 2, k - 1, oo); //cerr << "rofl_len" << ' ' << res << '\n'; res -= rofl_l.get(0, oo, 0, k - 2); return res; } }; void stress() { int C = 5; for (int i = 0; i < 10000; ++i) { ds smart; dss stupid; stringstream ss; for (int i = 0; i < 10; ++i) { int x = rand() % C, y = rand() % C; if (x > y) swap(x, y); ss << "1 " << x << ' ' << y << '\n'; smart.insert(x, y); stupid.insert(x, y); int a = rand() % C, b = rand() % C, k = rand() % C; if (a > b) swap(a, b); if (smart.get(a, b, k) != stupid.get(a, b, k)) { ss << smart.get(a, b, k) << ' ' << stupid.get(a, b, k) << '\n'; ss << "3 " << a << ' ' << b << ' ' << k << '\n'; cerr << ss.str(); exit(1); } } } exit(0); } int main() { //stress(); ios::sync_with_stdio(false); cin.tie(0); int n, t; cin >> n >> t; int lastans = 0; vector<pair<int, int>> segs; ds add; 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; add.erase(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); cout << lastans << '\n'; } } }

Compilation message (stderr)

segments.cpp: In member function 'void static2d::finalize(int, int, int)':
segments.cpp:74:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for (int i = 0; i < t[u].size(); ++i) {
      |                   ~~^~~~~~~~~~~~~
segments.cpp:75:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |    while (ptrle < t[2 * u].size() && t[2 * u][ptrle] < t[u][i])
      |           ~~~~~~^~~~~~~~~~~~~~~~~
segments.cpp:77:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |    while (ptrri < t[2 * u + 1].size() && t[2 * u + 1][ptrri] < t[u][i])
      |           ~~~~~~^~~~~~~~~~~~~~~~~~~~~
segments.cpp: In member function 'void static2d::build(std::vector<std::pair<int, int> >)':
segments.cpp:96:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |   while (n < xs.size()) n *= 2;
      |          ~~^~~~~~~~~~~
segments.cpp: In member function 'void rofl2d::check_rebuild()':
segments.cpp:149:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  149 |      while (ptr < newall.size() && ycmp(newall[ptr], x))
      |             ~~~~^~~~~~~~~~~~~~~
segments.cpp:154:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  154 |    while (ptr < newall.size())
      |           ~~~~^~~~~~~~~~~~~~~
#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...