Submission #172756

# Submission time Handle Problem Language Result Execution time Memory
172756 2020-01-02T14:24:27 Z songc None (JOI16_matryoshka) C++14
100 / 100
321 ms 12268 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, Q;
int T[202020];
int ans[202020];
pii A[202020];
vector<int> comp, L;

struct query{
	int a, b, id;
	bool operator<(const query &r)const{
		return a > r.a;
	}
} qu[202020];

void update(int k, int v){
	while (k<=N){
		T[k] = max(T[k], v);
		k += k&-k;
	}
}

int read(int k){
	int ret=0;
	while (k>0){
		ret = max(ret, T[k]);
		k ^= k&-k;
	}
	return ret;
}

int com(int k){return lower_bound(comp.begin(), comp.end(), k)-comp.begin()+1;}

int main(){
	scanf("%d %d", &N, &Q);
	for (int i=1; i<=N; i++){
		scanf("%d %d", &A[i].first, &A[i].second);
		comp.push_back(A[i].second);
	}
	sort(comp.begin(), comp.end());
	comp.erase(unique(comp.begin(), comp.end()), comp.end());
	sort(A+1, A+N+1, [&](pii a, pii b){
		if (a.first == b.first) return a.second < b.second;
		return a.first > b.first;
	});
	for (int i=1; i<=Q; i++){
		scanf("%d %d", &qu[i].a, &qu[i].b);
		qu[i].id = i;
	}
	sort(qu+1, qu+Q+1);

	int t=1;
	for (int i=1; i<=Q; i++){
		while (A[t].first >= qu[i].a){
			int lis = upper_bound(L.begin(), L.end(), A[t].second)-L.begin()+1;
			if (lis > L.size()) L.push_back(A[t].second);
			else L[lis-1] = A[t].second;
			update(com(A[t].second), lis);
			t++;
		}

		int k = com(qu[i].b+1)-1;
		ans[qu[i].id] = read(k);
	}
	for (int i=1; i<=Q; i++) printf("%d\n", ans[i]);
	return 0;
}

Compilation message

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:59:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (lis > L.size()) L.push_back(A[t].second);
        ~~~~^~~~~~~~~~
matryoshka.cpp:38: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:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &A[i].first, &A[i].second);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &qu[i].a, &qu[i].b);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 380 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory 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 380 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 6 ms 376 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 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory 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 380 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 6 ms 376 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 380 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 504 KB Output is correct
24 Correct 5 ms 476 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 6 ms 556 KB Output is correct
29 Correct 5 ms 488 KB Output is correct
30 Correct 4 ms 428 KB Output is correct
31 Correct 5 ms 504 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
33 Correct 5 ms 504 KB Output is correct
34 Correct 5 ms 500 KB Output is correct
35 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory 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 380 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 6 ms 376 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 380 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 504 KB Output is correct
24 Correct 5 ms 476 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 6 ms 556 KB Output is correct
29 Correct 5 ms 488 KB Output is correct
30 Correct 4 ms 428 KB Output is correct
31 Correct 5 ms 504 KB Output is correct
32 Correct 5 ms 504 KB Output is correct
33 Correct 5 ms 504 KB Output is correct
34 Correct 5 ms 500 KB Output is correct
35 Correct 5 ms 504 KB Output is correct
36 Correct 277 ms 10084 KB Output is correct
37 Correct 214 ms 11240 KB Output is correct
38 Correct 98 ms 5232 KB Output is correct
39 Correct 193 ms 9676 KB Output is correct
40 Correct 197 ms 10288 KB Output is correct
41 Correct 233 ms 11116 KB Output is correct
42 Correct 144 ms 9068 KB Output is correct
43 Correct 121 ms 9704 KB Output is correct
44 Correct 321 ms 12008 KB Output is correct
45 Correct 319 ms 12088 KB Output is correct
46 Correct 316 ms 12268 KB Output is correct
47 Correct 298 ms 11628 KB Output is correct
48 Correct 303 ms 12140 KB Output is correct
49 Correct 298 ms 11756 KB Output is correct
50 Correct 301 ms 12124 KB Output is correct