Submission #290490

# Submission time Handle Problem Language Result Execution time Memory
290490 2020-09-03T22:05:53 Z luciocf Segments (IZhO18_segments) C++14
0 / 100
217 ms 48376 KB
#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 = 2e9+10;

struct Node
{
	Node *l, *r;
	int v;

	Node() {l = r = NULL; v = 0;}
};

Node *root[2];

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[0] = new Node();
	root[1] = 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], 0, maxv, l, 1);
			seg.upd(root[1], 0, maxv, r, 1);
		}
		else if (op == 2)
		{
			int x;
			scanf("%d", &x);

			--qtd_ativo;

			seg.upd(root[0], 0, maxv, range[x].ff, -1);
			seg.upd(root[1], 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);

			lastans = qtd_ativo - seg.query(root[1], 0, maxv, 0, l-1) - seg.query(root[0], 0, maxv, r+1, maxv);
			printf("%d\n", lastans);
		}
	}
}

Compilation message

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:81:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   81 |   scanf("%d", &op);
      |   ~~~~~^~~~~~~~~~~
segments.cpp:86:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   86 |    scanf("%d %d", &l, &r);
      |    ~~~~~^~~~~~~~~~~~~~~~~
segments.cpp:101:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  101 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
segments.cpp:111:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  111 |    scanf("%d %d", &l, &r);
      |    ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 217 ms 48376 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 146 ms 23192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 134 ms 17704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -