답안 #372969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372969 2021-03-02T18:44:16 Z luciocf Examination (JOI19_examination) C++14
2 / 100
3000 ms 267056 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))
				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:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |  scanf("%d %d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |   scanf("%d %d", &a[i].ff, &a[i].ss);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   60 |   scanf("%d %d %d", &query[i].x, &query[i].y, &query[i].z);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9836 KB Output is correct
2 Correct 7 ms 9708 KB Output is correct
3 Correct 7 ms 9708 KB Output is correct
4 Correct 7 ms 9836 KB Output is correct
5 Correct 7 ms 9708 KB Output is correct
6 Correct 7 ms 9708 KB Output is correct
7 Correct 67 ms 19052 KB Output is correct
8 Correct 65 ms 18924 KB Output is correct
9 Correct 68 ms 18924 KB Output is correct
10 Correct 22 ms 12524 KB Output is correct
11 Correct 36 ms 12396 KB Output is correct
12 Correct 11 ms 9836 KB Output is correct
13 Correct 71 ms 18924 KB Output is correct
14 Correct 69 ms 19052 KB Output is correct
15 Correct 65 ms 18924 KB Output is correct
16 Correct 26 ms 11884 KB Output is correct
17 Correct 17 ms 11756 KB Output is correct
18 Correct 10 ms 9836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3062 ms 267056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3062 ms 267056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9836 KB Output is correct
2 Correct 7 ms 9708 KB Output is correct
3 Correct 7 ms 9708 KB Output is correct
4 Correct 7 ms 9836 KB Output is correct
5 Correct 7 ms 9708 KB Output is correct
6 Correct 7 ms 9708 KB Output is correct
7 Correct 67 ms 19052 KB Output is correct
8 Correct 65 ms 18924 KB Output is correct
9 Correct 68 ms 18924 KB Output is correct
10 Correct 22 ms 12524 KB Output is correct
11 Correct 36 ms 12396 KB Output is correct
12 Correct 11 ms 9836 KB Output is correct
13 Correct 71 ms 18924 KB Output is correct
14 Correct 69 ms 19052 KB Output is correct
15 Correct 65 ms 18924 KB Output is correct
16 Correct 26 ms 11884 KB Output is correct
17 Correct 17 ms 11756 KB Output is correct
18 Correct 10 ms 9836 KB Output is correct
19 Execution timed out 3062 ms 267056 KB Time limit exceeded
20 Halted 0 ms 0 KB -