Submission #372971

# Submission time Handle Problem Language Result Execution time Memory
372971 2021-03-02T18:46:26 Z luciocf Examination (JOI19_examination) C++14
2 / 100
3000 ms 206188 KB
#include <bits/stdc++.h>

#define ff first
#define ss second

using namespace std;

typedef pair<int, int> pii;

const int maxn = 2e5+10;

struct BIT2D
{
	map<int, int> bit[maxn];

	void upd(int x, int y, int v)
	{
		for (int i = x; i < maxn; i += (i&-i))
			for (int j = y; j < maxn; j += (j&-j))
				bit[i][j] += v;
	}

	int soma(int x, int y)
	{
		int ans = 0;

		for (int i = x; i > 0; i -= (i&-i))
			for (int j = y; j > 0; j -= (j&-j))
				if (bit[i].find(j) != bit[i].end())
					ans += bit[i][j];

		return ans;
	}
} BIT;

struct Query
{
	int x, y, z, ind;
} query[maxn];

pii a[maxn];
int ans[maxn];

int main(void)
{
	int n, q;
	scanf("%d %d", &n, &q);

	map<int, int> mpx, mpy;

	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &a[i].ff, &a[i].ss);

		mpx[a[i].ff] = 0;
		mpy[a[i].ss] = 0;
	}

	for (int i = 1; i <= q; i++)
	{
		scanf("%d %d %d", &query[i].x, &query[i].y, &query[i].z);
		query[i].ind = i;

		mpx[query[i].x] = 0;
		mpy[query[i].y] = 0;
	}

	int aux = 0;
	for (auto &x: mpx)
		x.second = ++aux;

	aux = 0;
	for (auto &x: mpy)
		x.second = ++aux;

	sort(a+1, a+n+1, [&] (pii a, pii b) {return a.ff+a.ss > b.ff+b.ss;});
	sort(query+1, query+q+1, [&] (Query a, Query b) {return a.z > b.z;});

	int ptr = 1;

	for (int i = 1; i <= q; i++)
	{
		while (ptr <= n && a[ptr].ff+a[ptr].ss >= query[i].z)
		{
			BIT.upd(maxn-mpx[a[ptr].ff], maxn-mpy[a[ptr].ss], 1);
			ptr++;
		}

		ans[query[i].ind] = BIT.soma(maxn-mpx[query[i].x], maxn-mpy[query[i].y]);
	}

	for (int i = 1; i <= q; i++)
		printf("%d\n", ans[i]);
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |  scanf("%d %d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |   scanf("%d %d", &a[i].ff, &a[i].ss);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |   scanf("%d %d %d", &query[i].x, &query[i].y, &query[i].z);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 7 ms 9708 KB Output is correct
3 Correct 8 ms 9708 KB Output is correct
4 Correct 7 ms 9708 KB Output is correct
5 Correct 7 ms 9708 KB Output is correct
6 Correct 6 ms 9708 KB Output is correct
7 Correct 41 ms 14316 KB Output is correct
8 Correct 46 ms 14316 KB Output is correct
9 Correct 39 ms 14188 KB Output is correct
10 Correct 16 ms 10732 KB Output is correct
11 Correct 20 ms 10732 KB Output is correct
12 Correct 10 ms 9836 KB Output is correct
13 Correct 42 ms 14188 KB Output is correct
14 Correct 42 ms 14188 KB Output is correct
15 Correct 42 ms 14188 KB Output is correct
16 Correct 14 ms 10348 KB Output is correct
17 Correct 13 ms 10348 KB Output is correct
18 Correct 9 ms 9836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3086 ms 206188 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3086 ms 206188 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 7 ms 9708 KB Output is correct
3 Correct 8 ms 9708 KB Output is correct
4 Correct 7 ms 9708 KB Output is correct
5 Correct 7 ms 9708 KB Output is correct
6 Correct 6 ms 9708 KB Output is correct
7 Correct 41 ms 14316 KB Output is correct
8 Correct 46 ms 14316 KB Output is correct
9 Correct 39 ms 14188 KB Output is correct
10 Correct 16 ms 10732 KB Output is correct
11 Correct 20 ms 10732 KB Output is correct
12 Correct 10 ms 9836 KB Output is correct
13 Correct 42 ms 14188 KB Output is correct
14 Correct 42 ms 14188 KB Output is correct
15 Correct 42 ms 14188 KB Output is correct
16 Correct 14 ms 10348 KB Output is correct
17 Correct 13 ms 10348 KB Output is correct
18 Correct 9 ms 9836 KB Output is correct
19 Execution timed out 3086 ms 206188 KB Time limit exceeded
20 Halted 0 ms 0 KB -