Submission #290487

#TimeUsernameProblemLanguageResultExecution timeMemory
290487luciocfSegments (IZhO18_segments)C++14
0 / 100
230 ms48248 KiB
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; typedef pair<int, int> pii; const int maxn = 1e5+10; const int maxv = 1e9+10; struct Node { Node *l, *r; int v; Node() {l = r = NULL; v = 0;} }; Node *root; struct SegmentTree { int get(Node *node) { return (node ? node->v : 0); } void upd(Node *node, int l, int r, int pos, int v) { if (l == r) { node->v += v; return; } int mid = (l+r)>>1; if (pos <= mid) { if (!node->l) node->l = new Node(); upd(node->l, l, mid, pos, v); } else { if (!node->r) node->r = new Node(); upd(node->r, mid+1, r, pos, v); } node->v = get(node->l)+get(node->r); } int query(Node *node, int l, int r, int a, int b) { if (!node || l > b || r < a) return 0; if (l >= a && r <= b) return node->v; int mid = (l+r)>>1; return query(node->l, l, mid, a, b) + query(node->r, mid+1, r, a, b); } } seg; pii range[maxn]; int main(void) { int q, t; scanf("%d %d", &q, &t); int lastans = 0; int ind = 0, qtd_ativo = 0; root = new Node(); while (q--) { int op; scanf("%d", &op); if (op == 1) { int l, r; scanf("%d %d", &l, &r); l = (l ^ (t*lastans)); r = (r ^ (t*lastans)); if (l > r) swap(l, r); range[++ind] = {l, r}; ++qtd_ativo; seg.upd(root, 0, maxv, l, 1); seg.upd(root, 0, maxv, r, 1); } else if (op == 2) { int x; scanf("%d", &x); --qtd_ativo; seg.upd(root, 0, maxv, range[x].ff, -1); seg.upd(root, 0, maxv, range[x].ss, -1); } else { int l, r; scanf("%d %d", &l, &r); l = (l ^ (t*lastans)); r = (r ^ (t*lastans)); if (l > r) swap(l, r); printf("%d\n", qtd_ativo - seg.query(root, 0, maxv, 0, l-1) - seg.query(root, 0, maxv, r+1, maxv)); } } }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:70:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |  scanf("%d %d", &q, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~~
segments.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   80 |   scanf("%d", &op);
      |   ~~~~~^~~~~~~~~~~
segments.cpp:85:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   85 |    scanf("%d %d", &l, &r);
      |    ~~~~~^~~~~~~~~~~~~~~~~
segments.cpp:100:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  100 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
segments.cpp:110:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  110 |    scanf("%d %d", &l, &r);
      |    ~~~~~^~~~~~~~~~~~~~~~~
#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...