답안 #682656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682656 2023-01-16T17:24:21 Z benson1029 Examination (JOI19_examination) C++14
100 / 100
662 ms 103368 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() {
	scanf("%d%d", &n, &q);
	for(int i=0; i<n; i++) {
		scanf("%d%d", &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++) printf("%d\n", ans[i]);
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:80:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |   scanf("%d%d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 14 ms 2644 KB Output is correct
8 Correct 13 ms 2624 KB Output is correct
9 Correct 13 ms 2644 KB Output is correct
10 Correct 12 ms 2388 KB Output is correct
11 Correct 12 ms 2516 KB Output is correct
12 Correct 9 ms 1364 KB Output is correct
13 Correct 12 ms 2388 KB Output is correct
14 Correct 11 ms 2388 KB Output is correct
15 Correct 11 ms 2344 KB Output is correct
16 Correct 10 ms 2032 KB Output is correct
17 Correct 11 ms 2388 KB Output is correct
18 Correct 7 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 497 ms 83540 KB Output is correct
2 Correct 533 ms 83468 KB Output is correct
3 Correct 497 ms 83556 KB Output is correct
4 Correct 445 ms 69796 KB Output is correct
5 Correct 418 ms 73568 KB Output is correct
6 Correct 355 ms 36228 KB Output is correct
7 Correct 490 ms 81156 KB Output is correct
8 Correct 481 ms 83664 KB Output is correct
9 Correct 478 ms 81128 KB Output is correct
10 Correct 417 ms 72396 KB Output is correct
11 Correct 381 ms 67312 KB Output is correct
12 Correct 243 ms 29772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 497 ms 83540 KB Output is correct
2 Correct 533 ms 83468 KB Output is correct
3 Correct 497 ms 83556 KB Output is correct
4 Correct 445 ms 69796 KB Output is correct
5 Correct 418 ms 73568 KB Output is correct
6 Correct 355 ms 36228 KB Output is correct
7 Correct 490 ms 81156 KB Output is correct
8 Correct 481 ms 83664 KB Output is correct
9 Correct 478 ms 81128 KB Output is correct
10 Correct 417 ms 72396 KB Output is correct
11 Correct 381 ms 67312 KB Output is correct
12 Correct 243 ms 29772 KB Output is correct
13 Correct 603 ms 100696 KB Output is correct
14 Correct 567 ms 98516 KB Output is correct
15 Correct 485 ms 83552 KB Output is correct
16 Correct 484 ms 70336 KB Output is correct
17 Correct 501 ms 84652 KB Output is correct
18 Correct 393 ms 36232 KB Output is correct
19 Correct 583 ms 100604 KB Output is correct
20 Correct 578 ms 102552 KB Output is correct
21 Correct 613 ms 98608 KB Output is correct
22 Correct 430 ms 72288 KB Output is correct
23 Correct 370 ms 67176 KB Output is correct
24 Correct 250 ms 29932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 14 ms 2644 KB Output is correct
8 Correct 13 ms 2624 KB Output is correct
9 Correct 13 ms 2644 KB Output is correct
10 Correct 12 ms 2388 KB Output is correct
11 Correct 12 ms 2516 KB Output is correct
12 Correct 9 ms 1364 KB Output is correct
13 Correct 12 ms 2388 KB Output is correct
14 Correct 11 ms 2388 KB Output is correct
15 Correct 11 ms 2344 KB Output is correct
16 Correct 10 ms 2032 KB Output is correct
17 Correct 11 ms 2388 KB Output is correct
18 Correct 7 ms 1108 KB Output is correct
19 Correct 497 ms 83540 KB Output is correct
20 Correct 533 ms 83468 KB Output is correct
21 Correct 497 ms 83556 KB Output is correct
22 Correct 445 ms 69796 KB Output is correct
23 Correct 418 ms 73568 KB Output is correct
24 Correct 355 ms 36228 KB Output is correct
25 Correct 490 ms 81156 KB Output is correct
26 Correct 481 ms 83664 KB Output is correct
27 Correct 478 ms 81128 KB Output is correct
28 Correct 417 ms 72396 KB Output is correct
29 Correct 381 ms 67312 KB Output is correct
30 Correct 243 ms 29772 KB Output is correct
31 Correct 603 ms 100696 KB Output is correct
32 Correct 567 ms 98516 KB Output is correct
33 Correct 485 ms 83552 KB Output is correct
34 Correct 484 ms 70336 KB Output is correct
35 Correct 501 ms 84652 KB Output is correct
36 Correct 393 ms 36232 KB Output is correct
37 Correct 583 ms 100604 KB Output is correct
38 Correct 578 ms 102552 KB Output is correct
39 Correct 613 ms 98608 KB Output is correct
40 Correct 430 ms 72288 KB Output is correct
41 Correct 370 ms 67176 KB Output is correct
42 Correct 250 ms 29932 KB Output is correct
43 Correct 662 ms 103256 KB Output is correct
44 Correct 612 ms 103368 KB Output is correct
45 Correct 591 ms 100628 KB Output is correct
46 Correct 553 ms 87412 KB Output is correct
47 Correct 540 ms 88556 KB Output is correct
48 Correct 389 ms 36012 KB Output is correct
49 Correct 612 ms 97268 KB Output is correct
50 Correct 609 ms 103276 KB Output is correct
51 Correct 639 ms 97200 KB Output is correct
52 Correct 477 ms 79052 KB Output is correct
53 Correct 436 ms 84868 KB Output is correct