답안 #200156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200156 2020-02-05T14:33:42 Z dennisstar Matryoshka (JOI16_matryoshka) C++17
100 / 100
683 ms 36068 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
#define unq(V) (V).erase(unique(all(V)), (V).end())
using namespace std;
typedef vector<int> vim;
typedef pair<int, int> pii;

struct Seg {
	int ar[(1<<19)];
	void upd(int i, int s, int e, int t, int v) {
		if (s==e) { ar[i]=max(ar[i], v); return ; }
		int md=(s+e)/2;
		if (t<=md) upd(i*2, s, md, t, v);
		else upd(i*2+1, md+1, e, t, v);
		ar[i]=max(ar[i*2], ar[i*2+1]);
	}
	int get(int i, int s, int e, int ts, int te) {
		if (e<ts||te<s) return 0;
		if (ts<=s&&e<=te) return ar[i];
		int md=(s+e)/2;
		return max(get(i*2, s, md, ts, te), get(i*2+1, md+1, e, ts, te));
	}
}S;

int N, Q, A[200010], B[200010], ans[200010];
pii P[200010];
vim cp1, cp2, pn[200010]; vector<pii> qu[200010];

int main() {
	scanf("%d %d", &N, &Q);
	for (int i=1; i<=N; i++) scanf("%d %d", &P[i].fi, &P[i].se), cp1.eb(P[i].fi), cp2.eb(P[i].se);
	sort(all(cp1)); unq(cp1); sort(all(cp2)); unq(cp2);
	for (int i=1; i<=N; i++) P[i].fi=lower_bound(all(cp1), P[i].fi)-cp1.begin()+1, P[i].se=lower_bound(all(cp2), P[i].se)-cp2.begin()+1;
	sort(P+1, P+N+1);
	for (int i=1; i<=N; i++) pn[P[i].fi].eb(P[i].se);
	for (int i=1; i<=Q; i++) {
		scanf("%d %d", &A[i], &B[i]);
		A[i]=lower_bound(all(cp1), A[i])-cp1.begin()+1; B[i]=upper_bound(all(cp2), B[i])-cp2.begin();
		qu[A[i]].eb(B[i], i);
	}
	for (int i=cp1.size(); i; i--) {
		for (auto &j:pn[i]) {
			int im=S.get(1, 1, cp2.size(), 1, j);
			S.upd(1, 1, cp2.size(), j, im+1);
		}
		for (auto &j:qu[i]) ans[j.se]=S.get(1, 1, cp2.size(), 1, j.fi);
	}
	for (int i=1; i<=Q; i++) printf("%d\n", ans[i]);
	return 0;
}

Compilation message

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &Q);
  ~~~~~^~~~~~~~~~~~~~~~~
matryoshka.cpp:34:78: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=1; i<=N; i++) scanf("%d %d", &P[i].fi, &P[i].se), cp1.eb(P[i].fi), cp2.eb(P[i].se);
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
matryoshka.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &A[i], &B[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 12 ms 9720 KB Output is correct
3 Correct 11 ms 9720 KB Output is correct
4 Correct 10 ms 9720 KB Output is correct
5 Correct 10 ms 9720 KB Output is correct
6 Correct 12 ms 9720 KB Output is correct
7 Correct 10 ms 9720 KB Output is correct
8 Correct 10 ms 9720 KB Output is correct
9 Correct 10 ms 9720 KB Output is correct
10 Correct 12 ms 9696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 12 ms 9720 KB Output is correct
3 Correct 11 ms 9720 KB Output is correct
4 Correct 10 ms 9720 KB Output is correct
5 Correct 10 ms 9720 KB Output is correct
6 Correct 12 ms 9720 KB Output is correct
7 Correct 10 ms 9720 KB Output is correct
8 Correct 10 ms 9720 KB Output is correct
9 Correct 10 ms 9720 KB Output is correct
10 Correct 12 ms 9696 KB Output is correct
11 Correct 10 ms 9720 KB Output is correct
12 Correct 10 ms 9720 KB Output is correct
13 Correct 11 ms 9720 KB Output is correct
14 Correct 10 ms 9720 KB Output is correct
15 Correct 10 ms 9720 KB Output is correct
16 Correct 10 ms 9720 KB Output is correct
17 Correct 10 ms 9724 KB Output is correct
18 Correct 12 ms 9720 KB Output is correct
19 Correct 16 ms 9720 KB Output is correct
20 Correct 13 ms 9720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 12 ms 9720 KB Output is correct
3 Correct 11 ms 9720 KB Output is correct
4 Correct 10 ms 9720 KB Output is correct
5 Correct 10 ms 9720 KB Output is correct
6 Correct 12 ms 9720 KB Output is correct
7 Correct 10 ms 9720 KB Output is correct
8 Correct 10 ms 9720 KB Output is correct
9 Correct 10 ms 9720 KB Output is correct
10 Correct 12 ms 9696 KB Output is correct
11 Correct 10 ms 9720 KB Output is correct
12 Correct 10 ms 9720 KB Output is correct
13 Correct 11 ms 9720 KB Output is correct
14 Correct 10 ms 9720 KB Output is correct
15 Correct 10 ms 9720 KB Output is correct
16 Correct 10 ms 9720 KB Output is correct
17 Correct 10 ms 9724 KB Output is correct
18 Correct 12 ms 9720 KB Output is correct
19 Correct 16 ms 9720 KB Output is correct
20 Correct 13 ms 9720 KB Output is correct
21 Correct 11 ms 9720 KB Output is correct
22 Correct 12 ms 9848 KB Output is correct
23 Correct 14 ms 9976 KB Output is correct
24 Correct 14 ms 9976 KB Output is correct
25 Correct 14 ms 9976 KB Output is correct
26 Correct 14 ms 9976 KB Output is correct
27 Correct 18 ms 9956 KB Output is correct
28 Correct 15 ms 9976 KB Output is correct
29 Correct 14 ms 9976 KB Output is correct
30 Correct 15 ms 9848 KB Output is correct
31 Correct 15 ms 9980 KB Output is correct
32 Correct 16 ms 9976 KB Output is correct
33 Correct 14 ms 9976 KB Output is correct
34 Correct 15 ms 9976 KB Output is correct
35 Correct 14 ms 9976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9720 KB Output is correct
2 Correct 12 ms 9720 KB Output is correct
3 Correct 11 ms 9720 KB Output is correct
4 Correct 10 ms 9720 KB Output is correct
5 Correct 10 ms 9720 KB Output is correct
6 Correct 12 ms 9720 KB Output is correct
7 Correct 10 ms 9720 KB Output is correct
8 Correct 10 ms 9720 KB Output is correct
9 Correct 10 ms 9720 KB Output is correct
10 Correct 12 ms 9696 KB Output is correct
11 Correct 10 ms 9720 KB Output is correct
12 Correct 10 ms 9720 KB Output is correct
13 Correct 11 ms 9720 KB Output is correct
14 Correct 10 ms 9720 KB Output is correct
15 Correct 10 ms 9720 KB Output is correct
16 Correct 10 ms 9720 KB Output is correct
17 Correct 10 ms 9724 KB Output is correct
18 Correct 12 ms 9720 KB Output is correct
19 Correct 16 ms 9720 KB Output is correct
20 Correct 13 ms 9720 KB Output is correct
21 Correct 11 ms 9720 KB Output is correct
22 Correct 12 ms 9848 KB Output is correct
23 Correct 14 ms 9976 KB Output is correct
24 Correct 14 ms 9976 KB Output is correct
25 Correct 14 ms 9976 KB Output is correct
26 Correct 14 ms 9976 KB Output is correct
27 Correct 18 ms 9956 KB Output is correct
28 Correct 15 ms 9976 KB Output is correct
29 Correct 14 ms 9976 KB Output is correct
30 Correct 15 ms 9848 KB Output is correct
31 Correct 15 ms 9980 KB Output is correct
32 Correct 16 ms 9976 KB Output is correct
33 Correct 14 ms 9976 KB Output is correct
34 Correct 15 ms 9976 KB Output is correct
35 Correct 14 ms 9976 KB Output is correct
36 Correct 548 ms 30316 KB Output is correct
37 Correct 371 ms 30408 KB Output is correct
38 Correct 197 ms 19628 KB Output is correct
39 Correct 296 ms 22112 KB Output is correct
40 Correct 287 ms 22780 KB Output is correct
41 Correct 474 ms 28796 KB Output is correct
42 Correct 191 ms 21576 KB Output is correct
43 Correct 159 ms 20836 KB Output is correct
44 Correct 610 ms 35808 KB Output is correct
45 Correct 683 ms 35904 KB Output is correct
46 Correct 577 ms 35808 KB Output is correct
47 Correct 590 ms 35516 KB Output is correct
48 Correct 647 ms 35996 KB Output is correct
49 Correct 563 ms 35556 KB Output is correct
50 Correct 568 ms 36068 KB Output is correct