Submission #493990

# Submission time Handle Problem Language Result Execution time Memory
493990 2021-12-13T16:26:11 Z patrikpavic2 None (JOI16_matryoshka) C++17
100 / 100
498 ms 47468 KB
#include <cstdio>
#include <vector>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

const int N = 4e5 + 500;

int n, q, A[N], B[N], ans[N], C[N], D[N];
vector < int > szA, szB;
vector < int > dod[N], pit[N];

int main(){
	scanf("%d%d", &n, &q);
	for(int i = 0;i < n;i++){
		scanf("%d%d", A + i, B + i);
		szA.PB(A[i]), szB.PB(B[i]);
	}
	for(int i = 0;i < q;i++){
		scanf("%d%d", C + i, D + i);
		szA.PB(C[i]), szB.PB(D[i]);
	}
	sort(szA.begin(), szA.end()); 
	szA.erase(unique(szA.begin(), szA.end()), szA.end());
	sort(szB.begin(), szB.end());
	szB.erase(unique(szB.begin(), szB.end()), szB.end());
	for(int i = 0;i < n;i++){
		A[i] = lower_bound(szA.begin(), szA.end(), A[i]) - szA.begin();
		B[i] = lower_bound(szB.begin(), szB.end(), B[i]) - szB.begin();
		dod[A[i]].PB(B[i]);	
	}
	for(int i = 0;i < q;i++){
		C[i] = lower_bound(szA.begin(), szA.end(), C[i]) - szA.begin();
		D[i] = lower_bound(szB.begin(), szB.end(), D[i]) - szB.begin();
		pit[C[i]].PB(i);
	}
	vector < int > odg;
	for(int i = N - 1;i >= 0;i--){
		sort(dod[i].begin(), dod[i].end());
		for(int x : dod[i]){
			if((int)odg.size() == 0 || odg.back() <= x)
				odg.PB(x);
			else
				odg[upper_bound(odg.begin(), odg.end(), x) - odg.begin()] = x;
		}
		for(int x : pit[i]){
			ans[x] = upper_bound(odg.begin(), odg.end(), D[x]) - odg.begin();
		}
	}
	for(int i = 0;i < q;i++)
		printf("%d\n", ans[i]);
	return 0;
}

Compilation message

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
matryoshka.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf("%d%d", A + i, B + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   scanf("%d%d", C + i, D + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19056 KB Output is correct
2 Correct 11 ms 19052 KB Output is correct
3 Correct 11 ms 19020 KB Output is correct
4 Correct 11 ms 19020 KB Output is correct
5 Correct 11 ms 19020 KB Output is correct
6 Correct 11 ms 19004 KB Output is correct
7 Correct 12 ms 19092 KB Output is correct
8 Correct 11 ms 19092 KB Output is correct
9 Correct 11 ms 19096 KB Output is correct
10 Correct 11 ms 19008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19056 KB Output is correct
2 Correct 11 ms 19052 KB Output is correct
3 Correct 11 ms 19020 KB Output is correct
4 Correct 11 ms 19020 KB Output is correct
5 Correct 11 ms 19020 KB Output is correct
6 Correct 11 ms 19004 KB Output is correct
7 Correct 12 ms 19092 KB Output is correct
8 Correct 11 ms 19092 KB Output is correct
9 Correct 11 ms 19096 KB Output is correct
10 Correct 11 ms 19008 KB Output is correct
11 Correct 12 ms 19224 KB Output is correct
12 Correct 12 ms 19112 KB Output is correct
13 Correct 11 ms 19020 KB Output is correct
14 Correct 11 ms 19048 KB Output is correct
15 Correct 14 ms 19020 KB Output is correct
16 Correct 13 ms 19020 KB Output is correct
17 Correct 16 ms 19096 KB Output is correct
18 Correct 12 ms 19068 KB Output is correct
19 Correct 12 ms 19020 KB Output is correct
20 Correct 15 ms 19020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19056 KB Output is correct
2 Correct 11 ms 19052 KB Output is correct
3 Correct 11 ms 19020 KB Output is correct
4 Correct 11 ms 19020 KB Output is correct
5 Correct 11 ms 19020 KB Output is correct
6 Correct 11 ms 19004 KB Output is correct
7 Correct 12 ms 19092 KB Output is correct
8 Correct 11 ms 19092 KB Output is correct
9 Correct 11 ms 19096 KB Output is correct
10 Correct 11 ms 19008 KB Output is correct
11 Correct 12 ms 19224 KB Output is correct
12 Correct 12 ms 19112 KB Output is correct
13 Correct 11 ms 19020 KB Output is correct
14 Correct 11 ms 19048 KB Output is correct
15 Correct 14 ms 19020 KB Output is correct
16 Correct 13 ms 19020 KB Output is correct
17 Correct 16 ms 19096 KB Output is correct
18 Correct 12 ms 19068 KB Output is correct
19 Correct 12 ms 19020 KB Output is correct
20 Correct 15 ms 19020 KB Output is correct
21 Correct 12 ms 19116 KB Output is correct
22 Correct 12 ms 19228 KB Output is correct
23 Correct 13 ms 19368 KB Output is correct
24 Correct 14 ms 19404 KB Output is correct
25 Correct 14 ms 19336 KB Output is correct
26 Correct 13 ms 19376 KB Output is correct
27 Correct 17 ms 19356 KB Output is correct
28 Correct 18 ms 19404 KB Output is correct
29 Correct 16 ms 19272 KB Output is correct
30 Correct 17 ms 19148 KB Output is correct
31 Correct 13 ms 19404 KB Output is correct
32 Correct 14 ms 19404 KB Output is correct
33 Correct 16 ms 19368 KB Output is correct
34 Correct 14 ms 19340 KB Output is correct
35 Correct 15 ms 19404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19056 KB Output is correct
2 Correct 11 ms 19052 KB Output is correct
3 Correct 11 ms 19020 KB Output is correct
4 Correct 11 ms 19020 KB Output is correct
5 Correct 11 ms 19020 KB Output is correct
6 Correct 11 ms 19004 KB Output is correct
7 Correct 12 ms 19092 KB Output is correct
8 Correct 11 ms 19092 KB Output is correct
9 Correct 11 ms 19096 KB Output is correct
10 Correct 11 ms 19008 KB Output is correct
11 Correct 12 ms 19224 KB Output is correct
12 Correct 12 ms 19112 KB Output is correct
13 Correct 11 ms 19020 KB Output is correct
14 Correct 11 ms 19048 KB Output is correct
15 Correct 14 ms 19020 KB Output is correct
16 Correct 13 ms 19020 KB Output is correct
17 Correct 16 ms 19096 KB Output is correct
18 Correct 12 ms 19068 KB Output is correct
19 Correct 12 ms 19020 KB Output is correct
20 Correct 15 ms 19020 KB Output is correct
21 Correct 12 ms 19116 KB Output is correct
22 Correct 12 ms 19228 KB Output is correct
23 Correct 13 ms 19368 KB Output is correct
24 Correct 14 ms 19404 KB Output is correct
25 Correct 14 ms 19336 KB Output is correct
26 Correct 13 ms 19376 KB Output is correct
27 Correct 17 ms 19356 KB Output is correct
28 Correct 18 ms 19404 KB Output is correct
29 Correct 16 ms 19272 KB Output is correct
30 Correct 17 ms 19148 KB Output is correct
31 Correct 13 ms 19404 KB Output is correct
32 Correct 14 ms 19404 KB Output is correct
33 Correct 16 ms 19368 KB Output is correct
34 Correct 14 ms 19340 KB Output is correct
35 Correct 15 ms 19404 KB Output is correct
36 Correct 407 ms 41228 KB Output is correct
37 Correct 413 ms 43728 KB Output is correct
38 Correct 131 ms 28428 KB Output is correct
39 Correct 203 ms 32140 KB Output is correct
40 Correct 225 ms 32664 KB Output is correct
41 Correct 334 ms 40536 KB Output is correct
42 Correct 154 ms 31492 KB Output is correct
43 Correct 154 ms 32500 KB Output is correct
44 Correct 427 ms 47264 KB Output is correct
45 Correct 459 ms 47176 KB Output is correct
46 Correct 497 ms 47252 KB Output is correct
47 Correct 419 ms 46892 KB Output is correct
48 Correct 441 ms 47372 KB Output is correct
49 Correct 435 ms 46900 KB Output is correct
50 Correct 498 ms 47468 KB Output is correct