Submission #471697

# Submission time Handle Problem Language Result Execution time Memory
471697 2021-09-10T10:47:35 Z prvocislo Examination (JOI19_examination) C++17
100 / 100
612 ms 16172 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
typedef long long ll;
using namespace std;

const int maxn = 1e5 + 5;
struct ev { int a, b, c, qu, i; };
bool cmpa(const ev& a, const ev& b) { return a.a == b.a ? a.qu > b.qu : a.a < b.a; }
bool cmpb(const ev& a, const ev& b) { return a.b == b.b ? a.qu > b.qu : a.b < b.b; }
int ans[maxn];
void solve_bc(const vector<ev>& v, int l, int r)
{
	if (l >= r) return;
	int m = (l + r) / 2;
	vector<int> c;
	for (int i = m + 1; i <= r; i++)
		if (!v[i].qu) c.push_back(v[i].c);
	sort(c.begin(), c.end());
	for (int i = l; i <= m; i++)
		if (v[i].qu) ans[v[i].i] += c.end() - lower_bound(c.begin(), c.end(), v[i].c);
	solve_bc(v, l, m);
	solve_bc(v, m + 1, r);
}
void solve_abc(const vector<ev>& v, int l, int r)
{
	if (l >= r) return;
	int m = (l + r) / 2;
	vector<ev> e;
	for (int i = l; i <= m; i++) if (v[i].qu)
		e.push_back(v[i]);
	for (int i = m + 1; i <= r; i++) if (!v[i].qu)
		e.push_back(v[i]);
	sort(e.begin(), e.end(), cmpb);
	solve_bc(e, 0, e.size() - 1);
	solve_abc(v, l, m);
	solve_abc(v, m + 1, r);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	vector<ev> e(n + q);
	for (int i = 0; i < n; i++) cin >> e[i].a >> e[i].b, e[i].c = e[i].a + e[i].b, e[i].qu = 0;
	for (int i = 0; i < q; i++) cin >> e[i + n].a >> e[i + n].b >> e[i + n].c, e[i + n].i = i, e[i + n].qu = 1;
	sort(e.begin(), e.end(), cmpa);
	solve_abc(e, 0, e.size() - 1);
	for (int i = 0; i < q; i++) cout << ans[i] << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 12 ms 776 KB Output is correct
8 Correct 11 ms 776 KB Output is correct
9 Correct 11 ms 716 KB Output is correct
10 Correct 10 ms 728 KB Output is correct
11 Correct 10 ms 716 KB Output is correct
12 Correct 8 ms 588 KB Output is correct
13 Correct 10 ms 716 KB Output is correct
14 Correct 10 ms 716 KB Output is correct
15 Correct 11 ms 748 KB Output is correct
16 Correct 8 ms 716 KB Output is correct
17 Correct 8 ms 732 KB Output is correct
18 Correct 7 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 544 ms 11440 KB Output is correct
2 Correct 530 ms 11448 KB Output is correct
3 Correct 522 ms 11316 KB Output is correct
4 Correct 458 ms 11176 KB Output is correct
5 Correct 409 ms 11360 KB Output is correct
6 Correct 325 ms 10384 KB Output is correct
7 Correct 507 ms 13864 KB Output is correct
8 Correct 462 ms 11244 KB Output is correct
9 Correct 487 ms 13740 KB Output is correct
10 Correct 362 ms 12852 KB Output is correct
11 Correct 360 ms 10992 KB Output is correct
12 Correct 255 ms 10368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 544 ms 11440 KB Output is correct
2 Correct 530 ms 11448 KB Output is correct
3 Correct 522 ms 11316 KB Output is correct
4 Correct 458 ms 11176 KB Output is correct
5 Correct 409 ms 11360 KB Output is correct
6 Correct 325 ms 10384 KB Output is correct
7 Correct 507 ms 13864 KB Output is correct
8 Correct 462 ms 11244 KB Output is correct
9 Correct 487 ms 13740 KB Output is correct
10 Correct 362 ms 12852 KB Output is correct
11 Correct 360 ms 10992 KB Output is correct
12 Correct 255 ms 10368 KB Output is correct
13 Correct 568 ms 11788 KB Output is correct
14 Correct 557 ms 11828 KB Output is correct
15 Correct 541 ms 11444 KB Output is correct
16 Correct 481 ms 11956 KB Output is correct
17 Correct 430 ms 11836 KB Output is correct
18 Correct 323 ms 10932 KB Output is correct
19 Correct 580 ms 11756 KB Output is correct
20 Correct 567 ms 11824 KB Output is correct
21 Correct 578 ms 14400 KB Output is correct
22 Correct 361 ms 12924 KB Output is correct
23 Correct 361 ms 11060 KB Output is correct
24 Correct 257 ms 10296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 12 ms 776 KB Output is correct
8 Correct 11 ms 776 KB Output is correct
9 Correct 11 ms 716 KB Output is correct
10 Correct 10 ms 728 KB Output is correct
11 Correct 10 ms 716 KB Output is correct
12 Correct 8 ms 588 KB Output is correct
13 Correct 10 ms 716 KB Output is correct
14 Correct 10 ms 716 KB Output is correct
15 Correct 11 ms 748 KB Output is correct
16 Correct 8 ms 716 KB Output is correct
17 Correct 8 ms 732 KB Output is correct
18 Correct 7 ms 588 KB Output is correct
19 Correct 544 ms 11440 KB Output is correct
20 Correct 530 ms 11448 KB Output is correct
21 Correct 522 ms 11316 KB Output is correct
22 Correct 458 ms 11176 KB Output is correct
23 Correct 409 ms 11360 KB Output is correct
24 Correct 325 ms 10384 KB Output is correct
25 Correct 507 ms 13864 KB Output is correct
26 Correct 462 ms 11244 KB Output is correct
27 Correct 487 ms 13740 KB Output is correct
28 Correct 362 ms 12852 KB Output is correct
29 Correct 360 ms 10992 KB Output is correct
30 Correct 255 ms 10368 KB Output is correct
31 Correct 568 ms 11788 KB Output is correct
32 Correct 557 ms 11828 KB Output is correct
33 Correct 541 ms 11444 KB Output is correct
34 Correct 481 ms 11956 KB Output is correct
35 Correct 430 ms 11836 KB Output is correct
36 Correct 323 ms 10932 KB Output is correct
37 Correct 580 ms 11756 KB Output is correct
38 Correct 567 ms 11824 KB Output is correct
39 Correct 578 ms 14400 KB Output is correct
40 Correct 361 ms 12924 KB Output is correct
41 Correct 361 ms 11060 KB Output is correct
42 Correct 257 ms 10296 KB Output is correct
43 Correct 586 ms 13816 KB Output is correct
44 Correct 612 ms 13800 KB Output is correct
45 Correct 564 ms 13876 KB Output is correct
46 Correct 472 ms 12592 KB Output is correct
47 Correct 436 ms 13168 KB Output is correct
48 Correct 330 ms 10932 KB Output is correct
49 Correct 559 ms 16172 KB Output is correct
50 Correct 541 ms 14184 KB Output is correct
51 Correct 565 ms 15916 KB Output is correct
52 Correct 376 ms 14492 KB Output is correct
53 Correct 367 ms 11824 KB Output is correct