답안 #49748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49748 2018-06-02T16:03:07 Z model_code Matryoshka (JOI16_matryoshka) C++17
100 / 100
676 ms 92744 KB
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int p[210000];
int q[210000];
int z[210000];
int s[210000];
int t[210000];
int segtree[524288];
int query(int a,int b,int c,int d,int e){
	if(d<a||b<c)return 0;
	if(c<=a&&b<=d)return segtree[e];
	return max(query(a,(a+b)/2,c,d,e*2),query((a+b)/2+1,b,c,d,e*2+1));
}
void update(int a,int b){
	a+=262144;
	while(a){
		segtree[a]=max(segtree[a],b);
		a/=2;
	}
}
int ans[210000];
vector<pair<int,pair<int,int> > >ev;
int main(){
	int N,Q;
	scanf("%d%d",&N,&Q);
	for(int i=0;i<N;i++)scanf("%d%d",q+i,p+i);
	for(int i=0;i<N;i++)z[i]=q[i];
	std::sort(z,z+N);
	for(int i=0;i<Q;i++){
		scanf("%d%d",t+i,s+i);
	}
	for(int i=0;i<N;i++){
		ev.push_back(make_pair(p[i],make_pair(0,-q[i])));
	}
	for(int i=0;i<Q;i++){
		ev.push_back(make_pair(s[i],make_pair(1,i)));
	}
	std::sort(ev.begin(),ev.end());
	for(int i=0;i<ev.size();i++){
		if(ev[i].second.first==0){
			int at=lower_bound(z,z+N,-ev[i].second.second)-z;
			int val=query(0,262143,at,N-1,1);
			update(at,val+1);
		}else{
			int at=lower_bound(z,z+N,t[ev[i].second.second])-z;
			ans[ev[i].second.second]=query(0,262143,at,N-1,1);
		}
	}
	for(int i=0;i<Q;i++)printf("%d\n",ans[i]);
}

Compilation message

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:41:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ev.size();i++){
              ~^~~~~~~~~~
matryoshka.cpp:27: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:28:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<N;i++)scanf("%d%d",q+i,p+i);
                      ~~~~~^~~~~~~~~~~~~~~~
matryoshka.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",t+i,s+i);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
8 Correct 2 ms 608 KB Output is correct
9 Correct 3 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
8 Correct 2 ms 608 KB Output is correct
9 Correct 3 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 2 ms 664 KB Output is correct
16 Correct 2 ms 664 KB Output is correct
17 Correct 2 ms 664 KB Output is correct
18 Correct 2 ms 664 KB Output is correct
19 Correct 2 ms 664 KB Output is correct
20 Correct 2 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
8 Correct 2 ms 608 KB Output is correct
9 Correct 3 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 2 ms 664 KB Output is correct
16 Correct 2 ms 664 KB Output is correct
17 Correct 2 ms 664 KB Output is correct
18 Correct 2 ms 664 KB Output is correct
19 Correct 2 ms 664 KB Output is correct
20 Correct 2 ms 664 KB Output is correct
21 Correct 2 ms 664 KB Output is correct
22 Correct 4 ms 740 KB Output is correct
23 Correct 6 ms 884 KB Output is correct
24 Correct 6 ms 948 KB Output is correct
25 Correct 6 ms 1012 KB Output is correct
26 Correct 9 ms 1220 KB Output is correct
27 Correct 6 ms 1220 KB Output is correct
28 Correct 7 ms 1220 KB Output is correct
29 Correct 9 ms 1256 KB Output is correct
30 Correct 4 ms 1256 KB Output is correct
31 Correct 6 ms 1328 KB Output is correct
32 Correct 6 ms 1504 KB Output is correct
33 Correct 6 ms 1504 KB Output is correct
34 Correct 7 ms 1624 KB Output is correct
35 Correct 6 ms 1624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
8 Correct 2 ms 608 KB Output is correct
9 Correct 3 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 2 ms 664 KB Output is correct
16 Correct 2 ms 664 KB Output is correct
17 Correct 2 ms 664 KB Output is correct
18 Correct 2 ms 664 KB Output is correct
19 Correct 2 ms 664 KB Output is correct
20 Correct 2 ms 664 KB Output is correct
21 Correct 2 ms 664 KB Output is correct
22 Correct 4 ms 740 KB Output is correct
23 Correct 6 ms 884 KB Output is correct
24 Correct 6 ms 948 KB Output is correct
25 Correct 6 ms 1012 KB Output is correct
26 Correct 9 ms 1220 KB Output is correct
27 Correct 6 ms 1220 KB Output is correct
28 Correct 7 ms 1220 KB Output is correct
29 Correct 9 ms 1256 KB Output is correct
30 Correct 4 ms 1256 KB Output is correct
31 Correct 6 ms 1328 KB Output is correct
32 Correct 6 ms 1504 KB Output is correct
33 Correct 6 ms 1504 KB Output is correct
34 Correct 7 ms 1624 KB Output is correct
35 Correct 6 ms 1624 KB Output is correct
36 Correct 547 ms 18272 KB Output is correct
37 Correct 404 ms 22840 KB Output is correct
38 Correct 156 ms 22840 KB Output is correct
39 Correct 397 ms 27976 KB Output is correct
40 Correct 372 ms 31388 KB Output is correct
41 Correct 435 ms 35576 KB Output is correct
42 Correct 263 ms 36228 KB Output is correct
43 Correct 274 ms 37636 KB Output is correct
44 Correct 676 ms 46400 KB Output is correct
45 Correct 629 ms 54024 KB Output is correct
46 Correct 488 ms 61732 KB Output is correct
47 Correct 582 ms 69284 KB Output is correct
48 Correct 460 ms 77452 KB Output is correct
49 Correct 445 ms 84704 KB Output is correct
50 Correct 468 ms 92744 KB Output is correct