Submission #798587

#TimeUsernameProblemLanguageResultExecution timeMemory
798587kingfran1907Segments (IZhO18_segments)C++14
0 / 100
5050 ms532 KiB
#include <bits/stdc++.h> #define X first #define Y second using namespace std; typedef long long llint; const int maxn = 2e5+10; const int block = 1; int n, t; int cnt = 0; vector< int > lef[block], rig[block]; int L[maxn], R[maxn]; int bio[maxn]; vector< pair<int, int> > v; vector< int > inds; bool cmp(int x, int y) { return R[x] - L[x] < R[y] - L[y]; } int inter(pair<int, int> a, pair<int, int> b) { return min(a.Y, b.Y) - max(a.X, b.X) + 1; } int main() { scanf("%d%d", &n, &t); int lastans = 0; while (n--) { int type; scanf("%d", &type); if (type == 1) { int l, r; scanf("%d%d", &l, &r); l = l ^ (t * lastans); r = r ^ (t * lastans); if (l > r) swap(l, r); ++cnt; v.push_back({cnt, 1}); L[cnt] = l, R[cnt] = r; } else if (type == 2) { int x; scanf("%d", &x); v.push_back({x, -1}); } else { int l, r, k; scanf("%d%d%d", &l, &r, &k); l = l ^ (t * lastans); r = r ^ (t * lastans); if (l > r) swap(l, r); lastans = 0; for (int i = 0; i < inds.size(); i += block) { int tr = i / block; int las = min((int)inds.size(), i + block) - 1; if (R[inds[las]] - L[inds[las]] + 1 < k) continue; if (R[inds[i]] - L[inds[i]] + 1 >= k) { lastans += las - i + 1; int ind = lower_bound(rig[tr].begin(), rig[tr].end(), l + k) - rig[tr].begin(); lastans -= ind; ind = upper_bound(lef[tr].begin(), lef[tr].end(), r - k) - lef[tr].begin(); lastans -= lef[tr].size() - ind; } else { for (int j = 0; j < block; j++) { if (i + j >= inds.size()) break; lastans += (inter({l, r}, {L[inds[i + j]], R[inds[i + j]]}) >= k); } } } for (auto iter : v) { int ind = iter.X; int cost = iter.Y; if (inter({l, r}, {L[ind], R[ind]}) >= k) lastans += cost; } printf("%d\n", lastans); } if (n % block == 0) { for (int i = 0; i < block; i++) { lef[i].clear(); rig[i].clear(); } for (auto iter : v) { bio[iter.X] += iter.Y; } v.clear(); inds.clear(); for (int i = 1; i <= cnt; i++) { if (bio[i]) inds.push_back(i); } sort(inds.begin(), inds.end(), cmp); for (int i = 0; i < inds.size(); i++) { int tr = i / block; lef[tr].push_back(L[inds[i]]); rig[tr].push_back(R[inds[i]]); } for (int i = 0; i < block; i++) { sort(lef[i].begin(), lef[i].end(), cmp); sort(rig[i].begin(), rig[i].end(), cmp); } } } return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |    for (int i = 0; i < inds.size(); i += block) {
      |                    ~~^~~~~~~~~~~~~
segments.cpp:68:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |       if (i + j >= inds.size()) break;
      |           ~~~~~~^~~~~~~~~~~~~~
segments.cpp:99:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |    for (int i = 0; i < inds.size(); i++) {
      |                    ~~^~~~~~~~~~~~~
segments.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d%d", &n, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~
segments.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   scanf("%d", &type);
      |   ~~~~~^~~~~~~~~~~~~
segments.cpp:35:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |    scanf("%d%d", &l, &r);
      |    ~~~~~^~~~~~~~~~~~~~~~
segments.cpp:45:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
segments.cpp:49:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |    scanf("%d%d%d", &l, &r, &k);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...