답안 #92310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
92310 2019-01-02T13:05:05 Z maruii Matryoshka (JOI16_matryoshka) C++17
100 / 100
313 ms 17212 KB
#include<bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
#define ff first
#define ss second
const int SIZE = 1<<18;
struct ST{
	int data[2*SIZE];
	void update(int x, int v){
		for(x+=SIZE; x; x/=2)
			data[x] = max(data[x], v);
	}
	int query(int s, int e){
		int ret = 0;
		for(s+=SIZE, e+=SIZE; s<=e; s/=2, e/=2){
			if(s&1) ret = max(ret, data[s++]);
			if(~e&1) ret = max(ret, data[e--]);
		}
		return ret;
	}
}seg;
ii p[200001];
pair<ii, int> qr[200001];
int ans[200001];
vector<int> xx,yy;
int main(){
	int N,Q; scanf("%d%d",&N,&Q);
	for(int i=0; i<N; ++i){
		int x, y; scanf("%d%d",&x, &y);
		p[i] = {-x, y};
		xx.push_back(-x);
		yy.push_back(y);
	}
	sort(xx.begin(), xx.end());
	sort(yy.begin(), yy.end());
	xx.erase(unique(xx.begin(), xx.end()), xx.end());
	yy.erase(unique(yy.begin(), yy.end()), yy.end());
	for(int i=0; i<N; ++i) p[i].ss = lower_bound(yy.begin(), yy.end(), p[i].ss) - yy.begin() + 1;
	sort(p, p+N);
	for(int i=0; i<Q; ++i){
		int x, y; scanf("%d%d",&x,&y);
		x = -x;
		y = upper_bound(yy.begin(), yy.end(), y) - yy.begin();
		qr[i] = {{x, y}, i};
	}
	sort(qr, qr+Q);
	for(int i=0, j=0; i<Q; ++i){
		while(j<N && p[j].ff<=qr[i].ff.ff){
			seg.update(p[j].ss, seg.query(0, p[j].ss)+1);
			++j;
		}
		ans[qr[i].ss] = seg.query(0, qr[i].ff.ss);
	}
	for(int i=0; i<Q; ++i) printf("%d\n",ans[i]);
	return 0;
}

Compilation message

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:27:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N,Q; scanf("%d%d",&N,&Q);
           ~~~~~^~~~~~~~~~~~~~
matryoshka.cpp:29:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d",&x, &y);
             ~~~~~^~~~~~~~~~~~~~~
matryoshka.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d",&x,&y);
             ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 7 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 7 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 7 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 5 ms 632 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 4 ms 508 KB Output is correct
26 Correct 4 ms 604 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 632 KB Output is correct
33 Correct 4 ms 632 KB Output is correct
34 Correct 4 ms 632 KB Output is correct
35 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 7 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 5 ms 632 KB Output is correct
24 Correct 4 ms 504 KB Output is correct
25 Correct 4 ms 508 KB Output is correct
26 Correct 4 ms 604 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 4 ms 504 KB Output is correct
29 Correct 4 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 4 ms 632 KB Output is correct
33 Correct 4 ms 632 KB Output is correct
34 Correct 4 ms 632 KB Output is correct
35 Correct 4 ms 504 KB Output is correct
36 Correct 270 ms 13636 KB Output is correct
37 Correct 194 ms 12000 KB Output is correct
38 Correct 100 ms 6248 KB Output is correct
39 Correct 187 ms 10464 KB Output is correct
40 Correct 189 ms 10976 KB Output is correct
41 Correct 215 ms 12104 KB Output is correct
42 Correct 139 ms 9700 KB Output is correct
43 Correct 98 ms 9824 KB Output is correct
44 Correct 307 ms 16984 KB Output is correct
45 Correct 303 ms 17052 KB Output is correct
46 Correct 309 ms 17124 KB Output is correct
47 Correct 313 ms 16612 KB Output is correct
48 Correct 299 ms 17212 KB Output is correct
49 Correct 298 ms 16580 KB Output is correct
50 Correct 312 ms 17136 KB Output is correct