Submission #1063008

# Submission time Handle Problem Language Result Execution time Memory
1063008 2024-08-17T13:17:41 Z belgianbot None (JOI16_matryoshka) C++17
100 / 100
197 ms 25328 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define int long long

using namespace std;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, Q; cin >> N >> Q;
	vector<pair<int,int>> a(N);
	vector<pair<pair<int,int>,int>> q(Q);
	vector<int> res(Q);
	for (int i = 0; i < N; i++) cin >> a[i].fi >> a[i].se;
	for (int i = 0; i < Q; i++) {cin >> q[i].fi.fi >> q[i].fi.se; q[i].se = i;}
	
	sort(a.rbegin(), a.rend());
	sort(q.rbegin(), q.rend());
	
	int j = 0, cnt = 0;
	ordered_set lis;
	for (int i = 0; i < Q; i++) {
		int ans = lis.order_of_key({q[i].fi.se + 1,-1});
		while (j < N && a[j].fi >= q[i].fi.fi) {
			vector<int> curr;
			int actual = a[j].fi;
			for (; j < N && a[j].fi == actual; j++) curr.push_back(a[j].se);
		
			for (int k = 0; k < curr.size(); k++) {
				auto up = lis.upper_bound({curr[k] + 1,-1});
				if (up == lis.end()) {
					if (curr[k] <= q[i].fi.se) ans++;
				}
				else {
					lis.erase(up);
					if ((*up).fi > q[i].fi.se && curr[k] <= q[i].fi.se) ans++;
				}
			}
			for (int k = 0; k < curr.size(); k++) lis.insert({curr[k], cnt++});
		}
		res[q[i].se] = ans;
	}
	
	for (int i = 0; i < Q; i++) cout << res[i] << '\n';
	return 0;
}
	
	

Compilation message

matryoshka.cpp: In function 'int main()':
matryoshka.cpp:34:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |    for (int k = 0; k < curr.size(); k++) {
      |                    ~~^~~~~~~~~~~~~
matryoshka.cpp:44:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |    for (int k = 0; k < curr.size(); k++) lis.insert({curr[k], cnt++});
      |                    ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 456 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 456 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 456 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 616 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 572 KB Output is correct
31 Correct 2 ms 600 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 456 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 616 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 572 KB Output is correct
31 Correct 2 ms 600 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 142 ms 15716 KB Output is correct
37 Correct 146 ms 15096 KB Output is correct
38 Correct 47 ms 5724 KB Output is correct
39 Correct 118 ms 13396 KB Output is correct
40 Correct 149 ms 15472 KB Output is correct
41 Correct 142 ms 14832 KB Output is correct
42 Correct 127 ms 15312 KB Output is correct
43 Correct 197 ms 25328 KB Output is correct
44 Correct 147 ms 18260 KB Output is correct
45 Correct 154 ms 18260 KB Output is correct
46 Correct 152 ms 18288 KB Output is correct
47 Correct 134 ms 18044 KB Output is correct
48 Correct 160 ms 18932 KB Output is correct
49 Correct 133 ms 17912 KB Output is correct
50 Correct 169 ms 19028 KB Output is correct