답안 #310766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
310766 2020-10-07T20:42:55 Z luciocf Matryoshka (JOI16_matryoshka) C++14
100 / 100
815 ms 42616 KB
#include <bits/stdc++.h>
 
#define ff first
#define ss second
 
using namespace std;
 
typedef pair<int, int> pii;
 
const int maxn = 4e5+10;
 
struct SegmentTree
{
	int tree[3*maxn];
 
	void upd(int node, int l, int r, int pos, int v)
	{
		if (l == r)
		{
			tree[node] = v;
			return;
		}
 
		int mid = (l+r)>>1;
 
		if (pos <= mid) upd(2*node, l, mid, pos, v);
		else upd(2*node+1, mid+1, r, pos, v);
 
		tree[node] = max(tree[2*node], tree[2*node+1]);
	}
 
	int query(int node, int l, int r, int a, int b)
	{
		if (l > r || l > b || r < a) return 0;
		if (l >= a && r <= b) return tree[node];
 
		int mid = (l+r)>>1;
 
		return max(query(2*node, l, mid, a, b), query(2*node+1, mid+1, r, a, b)); 
	}
} seg;
 
struct Query
{
	int r, h, ind;
} qry[maxn];
 
int n, q;
pii a[maxn];
 
int ans[maxn];
 
vector<int> pos[maxn];
 
void compress(void)
{
	map<int, int> mp;
 
	for (int i = 1; i <= n; i++)
		mp[a[i].ss] = 0;
	for (int i = 1; i <= q; i++)
		mp[qry[i].h] = 0;
 
	int aux = 0;
	for (auto &x: mp)
		x.second = ++aux;
 
	for (int i = n; i >= 1; i--)
	{
		a[i].ss = mp[a[i].ss];
		pos[a[i].ss].push_back(i);
	}
 
	for (int i = 1; i <= q; i++)
		qry[i].h = mp[qry[i].h];
}
 
bool comp(pii x, pii y)
{
	if (x.ff == y.ff) return x.ss > y.ss;
	return x.ff < y.ff;
}
 
int main(void)
{
	scanf("%d %d", &n, &q);
 
	for (int i = 1; i <= n; i++)
		scanf("%d %d", &a[i].ff, &a[i].ss);
 
	for (int i = 1; i <= q; i++)
	{
		scanf("%d %d", &qry[i].r, &qry[i].h);
		qry[i].ind = i;
	}
 
	sort(a+1, a+n+1, comp);
	sort(qry+1, qry+q+1, [&] (Query a, Query b) {return a.h < b.h;});
 
	compress();
 
	int ptr = 1;
 
	for (int i = 1; i <= q; i++)
	{
		while (ptr <= qry[i].h)
		{
			for (auto j: pos[ptr])
			{
				int mx = seg.query(1, 1, n, j+1, n)+1;
				seg.upd(1, 1, n, j, mx);
			}
 
			ptr++;
		}
 
		int pos = (int)(lower_bound(a+1, a+n+1, make_pair(qry[i].r, 0))-a);
 
		ans[qry[i].ind] = seg.query(1, 1, n, pos, n);
	}
 
	for (int i = 1; i <= q; i++)
		printf("%d\n", ans[i]);
}

Compilation message

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   86 |  scanf("%d %d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~
matryoshka.cpp:89:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   89 |   scanf("%d %d", &a[i].ff, &a[i].ss);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:93:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   93 |   scanf("%d %d", &qry[i].r, &qry[i].h);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 6 ms 9728 KB Output is correct
5 Correct 6 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 6 ms 9728 KB Output is correct
9 Correct 6 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 6 ms 9728 KB Output is correct
5 Correct 6 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 6 ms 9728 KB Output is correct
9 Correct 6 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 6 ms 9728 KB Output is correct
12 Correct 6 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 7 ms 9728 KB Output is correct
20 Correct 6 ms 9728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 6 ms 9728 KB Output is correct
5 Correct 6 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 6 ms 9728 KB Output is correct
9 Correct 6 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 6 ms 9728 KB Output is correct
12 Correct 6 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 7 ms 9728 KB Output is correct
20 Correct 6 ms 9728 KB Output is correct
21 Correct 6 ms 9728 KB Output is correct
22 Correct 8 ms 9856 KB Output is correct
23 Correct 11 ms 10112 KB Output is correct
24 Correct 12 ms 9984 KB Output is correct
25 Correct 11 ms 10112 KB Output is correct
26 Correct 10 ms 10112 KB Output is correct
27 Correct 10 ms 10112 KB Output is correct
28 Correct 10 ms 9984 KB Output is correct
29 Correct 12 ms 10112 KB Output is correct
30 Correct 9 ms 9856 KB Output is correct
31 Correct 11 ms 10112 KB Output is correct
32 Correct 11 ms 10112 KB Output is correct
33 Correct 11 ms 10112 KB Output is correct
34 Correct 11 ms 10112 KB Output is correct
35 Correct 11 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 7 ms 9728 KB Output is correct
4 Correct 6 ms 9728 KB Output is correct
5 Correct 6 ms 9728 KB Output is correct
6 Correct 7 ms 9728 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 6 ms 9728 KB Output is correct
9 Correct 6 ms 9728 KB Output is correct
10 Correct 7 ms 9728 KB Output is correct
11 Correct 6 ms 9728 KB Output is correct
12 Correct 6 ms 9728 KB Output is correct
13 Correct 7 ms 9728 KB Output is correct
14 Correct 7 ms 9728 KB Output is correct
15 Correct 7 ms 9728 KB Output is correct
16 Correct 7 ms 9728 KB Output is correct
17 Correct 7 ms 9728 KB Output is correct
18 Correct 7 ms 9728 KB Output is correct
19 Correct 7 ms 9728 KB Output is correct
20 Correct 6 ms 9728 KB Output is correct
21 Correct 6 ms 9728 KB Output is correct
22 Correct 8 ms 9856 KB Output is correct
23 Correct 11 ms 10112 KB Output is correct
24 Correct 12 ms 9984 KB Output is correct
25 Correct 11 ms 10112 KB Output is correct
26 Correct 10 ms 10112 KB Output is correct
27 Correct 10 ms 10112 KB Output is correct
28 Correct 10 ms 9984 KB Output is correct
29 Correct 12 ms 10112 KB Output is correct
30 Correct 9 ms 9856 KB Output is correct
31 Correct 11 ms 10112 KB Output is correct
32 Correct 11 ms 10112 KB Output is correct
33 Correct 11 ms 10112 KB Output is correct
34 Correct 11 ms 10112 KB Output is correct
35 Correct 11 ms 10112 KB Output is correct
36 Correct 639 ms 28976 KB Output is correct
37 Correct 336 ms 18404 KB Output is correct
38 Correct 189 ms 22392 KB Output is correct
39 Correct 306 ms 18168 KB Output is correct
40 Correct 306 ms 18808 KB Output is correct
41 Correct 378 ms 18680 KB Output is correct
42 Correct 216 ms 18940 KB Output is correct
43 Correct 177 ms 18836 KB Output is correct
44 Correct 783 ms 42360 KB Output is correct
45 Correct 804 ms 42360 KB Output is correct
46 Correct 815 ms 42488 KB Output is correct
47 Correct 548 ms 41976 KB Output is correct
48 Correct 544 ms 42616 KB Output is correct
49 Correct 550 ms 41976 KB Output is correct
50 Correct 545 ms 42488 KB Output is correct