Submission #682655

# Submission time Handle Problem Language Result Execution time Memory
682655 2023-01-16T17:23:14 Z benson1029 Examination (JOI19_examination) C++14
100 / 100
859 ms 103520 KB
#include<bits/stdc++.h>
using namespace std;
struct entry{
	int op;
	int a,b,c;
	int id;
};
bool cmpa(entry x, entry y) {
	if(x.a == y.a) return x.op < y.op;
	return x.a > y.a;
}
bool cmpb(entry x, entry y) {
	if(x.b == y.b) return x.op < y.op;
	return x.b > y.b;
}
struct node{
	int v;
	node *l, *r;
	node(): v(0), l(NULL), r(NULL) {}
};
entry a[200005];
entry b[200005];
int ans[200005];
pair<int,int> c[200005];
int n,q;
int w,x,y;
void upd(node *x, long long l, long long r, int pos) {
	if(l == r) {
		x->v++;
	} else {
		if(x->l == NULL) {
			x -> l = new node();
			x -> r = new node();
		}
		if(pos<=(l+r)/2) upd(x->l, l, (l+r)/2, pos);
		else upd(x->r, (l+r)/2+1, r, pos);
		x->v = x->l->v + x->r->v;
	}
}
int qry(node *x, long long l, long long r, int ll, int rr) {
	if(ll > r || rr < l) return 0;
	if(ll <= l && r <= rr) return x -> v;
	if(x -> l == NULL) return x -> v;
	return qry(x->l, l, (l+r)/2, ll, rr) + qry(x->r, (l+r)/2+1, r, ll, rr);
}
void cdq(int l, int r) {
	if(l >= r) return;
	int mid = (l+r)/2;
	int ptr = 0;
	for(int i=l; i<=r; i++) {
		if(i <= mid && a[i].op == 1) {
			b[ptr] = a[i];
			c[ptr] = make_pair(a[i].c,ptr);
			ptr++;
		} else if(i > mid && a[i].op == 2) {
			b[ptr] = a[i];
			c[ptr] = make_pair(a[i].c,ptr);
			ptr++;
		}
	}
	sort(c,c+ptr);
	int temp = 0;
	for(int i=0; i<ptr; i++) {
		if(i>0 && c[i].first != c[i-1].first) temp++;
		b[c[i].second].c = temp;
	}
	sort(b,b+ptr,cmpb);
	node *rt = new node();
	for(int i=0; i<ptr; i++) {
		if(b[i].op == 1) {
			upd(rt, 0, r-l+1, b[i].c);
		} else {
			ans[b[i].id] += qry(rt, 0, r-l+1, b[i].c, r-l+1);
		}
	}
	cdq(l, mid);
	cdq(mid+1, r);
}
int main() {
	cin >> n >> q;
	for(int i=0; i<n; i++) {
		cin >> x >> y;
		a[i] = (entry){1,x,y,x+y,0};
	}
	for(int i=n; i<n+q; i++) {
		cin >> w >> x >> y;
		a[i] = (entry){2,w,x,y,i-n};
	}
	sort(a,a+n+q,cmpa);
	cdq(0,n+q-1);
	for(int i=0; i<q; i++) cout << ans[i] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 19 ms 2808 KB Output is correct
8 Correct 18 ms 2856 KB Output is correct
9 Correct 19 ms 2832 KB Output is correct
10 Correct 18 ms 2532 KB Output is correct
11 Correct 19 ms 2552 KB Output is correct
12 Correct 15 ms 1364 KB Output is correct
13 Correct 19 ms 2496 KB Output is correct
14 Correct 19 ms 2488 KB Output is correct
15 Correct 24 ms 2516 KB Output is correct
16 Correct 14 ms 2132 KB Output is correct
17 Correct 15 ms 2556 KB Output is correct
18 Correct 11 ms 1256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 704 ms 83800 KB Output is correct
2 Correct 724 ms 83832 KB Output is correct
3 Correct 668 ms 83736 KB Output is correct
4 Correct 664 ms 69952 KB Output is correct
5 Correct 579 ms 73920 KB Output is correct
6 Correct 529 ms 36384 KB Output is correct
7 Correct 666 ms 81420 KB Output is correct
8 Correct 615 ms 83892 KB Output is correct
9 Correct 622 ms 81384 KB Output is correct
10 Correct 592 ms 72804 KB Output is correct
11 Correct 512 ms 67540 KB Output is correct
12 Correct 345 ms 30180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 704 ms 83800 KB Output is correct
2 Correct 724 ms 83832 KB Output is correct
3 Correct 668 ms 83736 KB Output is correct
4 Correct 664 ms 69952 KB Output is correct
5 Correct 579 ms 73920 KB Output is correct
6 Correct 529 ms 36384 KB Output is correct
7 Correct 666 ms 81420 KB Output is correct
8 Correct 615 ms 83892 KB Output is correct
9 Correct 622 ms 81384 KB Output is correct
10 Correct 592 ms 72804 KB Output is correct
11 Correct 512 ms 67540 KB Output is correct
12 Correct 345 ms 30180 KB Output is correct
13 Correct 713 ms 100984 KB Output is correct
14 Correct 687 ms 98812 KB Output is correct
15 Correct 630 ms 83796 KB Output is correct
16 Correct 621 ms 70476 KB Output is correct
17 Correct 663 ms 84936 KB Output is correct
18 Correct 493 ms 36672 KB Output is correct
19 Correct 720 ms 100956 KB Output is correct
20 Correct 705 ms 102888 KB Output is correct
21 Correct 710 ms 98892 KB Output is correct
22 Correct 536 ms 72584 KB Output is correct
23 Correct 496 ms 67532 KB Output is correct
24 Correct 351 ms 30128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 19 ms 2808 KB Output is correct
8 Correct 18 ms 2856 KB Output is correct
9 Correct 19 ms 2832 KB Output is correct
10 Correct 18 ms 2532 KB Output is correct
11 Correct 19 ms 2552 KB Output is correct
12 Correct 15 ms 1364 KB Output is correct
13 Correct 19 ms 2496 KB Output is correct
14 Correct 19 ms 2488 KB Output is correct
15 Correct 24 ms 2516 KB Output is correct
16 Correct 14 ms 2132 KB Output is correct
17 Correct 15 ms 2556 KB Output is correct
18 Correct 11 ms 1256 KB Output is correct
19 Correct 704 ms 83800 KB Output is correct
20 Correct 724 ms 83832 KB Output is correct
21 Correct 668 ms 83736 KB Output is correct
22 Correct 664 ms 69952 KB Output is correct
23 Correct 579 ms 73920 KB Output is correct
24 Correct 529 ms 36384 KB Output is correct
25 Correct 666 ms 81420 KB Output is correct
26 Correct 615 ms 83892 KB Output is correct
27 Correct 622 ms 81384 KB Output is correct
28 Correct 592 ms 72804 KB Output is correct
29 Correct 512 ms 67540 KB Output is correct
30 Correct 345 ms 30180 KB Output is correct
31 Correct 713 ms 100984 KB Output is correct
32 Correct 687 ms 98812 KB Output is correct
33 Correct 630 ms 83796 KB Output is correct
34 Correct 621 ms 70476 KB Output is correct
35 Correct 663 ms 84936 KB Output is correct
36 Correct 493 ms 36672 KB Output is correct
37 Correct 720 ms 100956 KB Output is correct
38 Correct 705 ms 102888 KB Output is correct
39 Correct 710 ms 98892 KB Output is correct
40 Correct 536 ms 72584 KB Output is correct
41 Correct 496 ms 67532 KB Output is correct
42 Correct 351 ms 30128 KB Output is correct
43 Correct 767 ms 103520 KB Output is correct
44 Correct 770 ms 103384 KB Output is correct
45 Correct 740 ms 100640 KB Output is correct
46 Correct 662 ms 87368 KB Output is correct
47 Correct 653 ms 88596 KB Output is correct
48 Correct 526 ms 36136 KB Output is correct
49 Correct 859 ms 97132 KB Output is correct
50 Correct 792 ms 103304 KB Output is correct
51 Correct 787 ms 97128 KB Output is correct
52 Correct 608 ms 79148 KB Output is correct
53 Correct 534 ms 84752 KB Output is correct