답안 #259518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259518 2020-08-08T00:34:07 Z ChrisT Examination (JOI19_examination) C++17
100 / 100
403 ms 40156 KB
#include <bits/stdc++.h>
using namespace std;
const int MN = 2e5 + 5;
int ans[MN], bit[MN];
vector<int> xs;
void getx (int &x) {x = lower_bound(xs.begin(),xs.end(),x) - xs.begin() + 1;}
void inc (int i) {
	for (i=MN-i;i<MN;i+=i&-i) ++bit[i];
}
void dec (int i) {
	for (i=MN-i;i<MN;i+=i&-i) --bit[i];
}
int query (int i) {
	int ret = 0;
	for (i=MN-i;i;i^=i&-i) ret += bit[i];
	return ret;
}
struct Event {
	int x,y,z,id;
};
void cdq (int l, int r, vector<Event> &events) { //over z
	if (events.empty()) return;
	if (l==r) {
		for (Event &e : events) {
			if (e.id<0)inc(e.y);
			else ans[e.id] += query(e.y);
		}
		for (Event &e : events) if (e.id<0) dec(e.y);
		return;
	}
	vector<Event> lq,rq;
	int mid = (l + r) / 2;
	for (Event &e : events) {
		if (e.z > mid) {
			rq.push_back(e);
			if (e.id<0) inc(e.y);
		} else {
			lq.push_back(e);
			if (e.id>0) ans[e.id] += query(e.y);
		}
	}
	for (Event &e : rq) if (e.id<0) dec(e.y);
	if (l < r) {
		cdq(l,mid,lq);
		cdq(mid+1,r,rq);
	}
}
int main () {
	int n,q;
	scanf ("%d %d",&n,&q);
	vector<Event> events;
	for (int i = 1; i <= n; i++) {
		int s,t;
		scanf ("%d %d",&s,&t); xs.push_back(t);
		events.push_back({s,t,s+t,-i});
	}
	for (int i = 1; i <= q; i++) {
		int x,y,z;
		scanf ("%d %d %d",&x,&y,&z); xs.push_back(y);
		events.push_back({x,y,z,i});
	}
	sort(xs.begin(),xs.end()); xs.erase(unique(xs.begin(),xs.end()),xs.end());
	for (auto &au : events) getx(au.y);
	xs.clear();
	for (auto &au : events) xs.push_back(au.z);
	sort(xs.begin(),xs.end()); xs.erase(unique(xs.begin(),xs.end()),xs.end());
	for (auto &au : events) getx(au.z);
	sort(events.begin(),events.end(),[](const Event &a, const Event &b) {return a.x > b.x || (a.x == b.x && a.id < b.id);});
	cdq(1,xs.size(),events);
	for (int i = 1; i <= q; i++) printf ("%d\n",ans[i]);
	return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d %d",&n,&q);
  ~~~~~~^~~~~~~~~~~~~~~
examination.cpp:54:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d",&s,&t); xs.push_back(t);
   ~~~~~~^~~~~~~~~~~~~~~
examination.cpp:59:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d %d",&x,&y,&z); xs.push_back(y);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 10 ms 896 KB Output is correct
8 Correct 10 ms 896 KB Output is correct
9 Correct 12 ms 896 KB Output is correct
10 Correct 8 ms 768 KB Output is correct
11 Correct 10 ms 816 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 9 ms 1408 KB Output is correct
14 Correct 9 ms 1408 KB Output is correct
15 Correct 9 ms 1408 KB Output is correct
16 Correct 8 ms 1408 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 339 ms 37752 KB Output is correct
2 Correct 321 ms 37724 KB Output is correct
3 Correct 335 ms 37852 KB Output is correct
4 Correct 240 ms 35932 KB Output is correct
5 Correct 324 ms 36572 KB Output is correct
6 Correct 136 ms 18396 KB Output is correct
7 Correct 313 ms 39900 KB Output is correct
8 Correct 313 ms 40028 KB Output is correct
9 Correct 306 ms 39772 KB Output is correct
10 Correct 290 ms 37600 KB Output is correct
11 Correct 203 ms 37596 KB Output is correct
12 Correct 88 ms 6876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 339 ms 37752 KB Output is correct
2 Correct 321 ms 37724 KB Output is correct
3 Correct 335 ms 37852 KB Output is correct
4 Correct 240 ms 35932 KB Output is correct
5 Correct 324 ms 36572 KB Output is correct
6 Correct 136 ms 18396 KB Output is correct
7 Correct 313 ms 39900 KB Output is correct
8 Correct 313 ms 40028 KB Output is correct
9 Correct 306 ms 39772 KB Output is correct
10 Correct 290 ms 37600 KB Output is correct
11 Correct 203 ms 37596 KB Output is correct
12 Correct 88 ms 6876 KB Output is correct
13 Correct 370 ms 15312 KB Output is correct
14 Correct 363 ms 15324 KB Output is correct
15 Correct 318 ms 40156 KB Output is correct
16 Correct 272 ms 13920 KB Output is correct
17 Correct 338 ms 14044 KB Output is correct
18 Correct 132 ms 15068 KB Output is correct
19 Correct 366 ms 15528 KB Output is correct
20 Correct 365 ms 15200 KB Output is correct
21 Correct 371 ms 15196 KB Output is correct
22 Correct 300 ms 37468 KB Output is correct
23 Correct 214 ms 37724 KB Output is correct
24 Correct 88 ms 6876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 10 ms 896 KB Output is correct
8 Correct 10 ms 896 KB Output is correct
9 Correct 12 ms 896 KB Output is correct
10 Correct 8 ms 768 KB Output is correct
11 Correct 10 ms 816 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 9 ms 1408 KB Output is correct
14 Correct 9 ms 1408 KB Output is correct
15 Correct 9 ms 1408 KB Output is correct
16 Correct 8 ms 1408 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 339 ms 37752 KB Output is correct
20 Correct 321 ms 37724 KB Output is correct
21 Correct 335 ms 37852 KB Output is correct
22 Correct 240 ms 35932 KB Output is correct
23 Correct 324 ms 36572 KB Output is correct
24 Correct 136 ms 18396 KB Output is correct
25 Correct 313 ms 39900 KB Output is correct
26 Correct 313 ms 40028 KB Output is correct
27 Correct 306 ms 39772 KB Output is correct
28 Correct 290 ms 37600 KB Output is correct
29 Correct 203 ms 37596 KB Output is correct
30 Correct 88 ms 6876 KB Output is correct
31 Correct 370 ms 15312 KB Output is correct
32 Correct 363 ms 15324 KB Output is correct
33 Correct 318 ms 40156 KB Output is correct
34 Correct 272 ms 13920 KB Output is correct
35 Correct 338 ms 14044 KB Output is correct
36 Correct 132 ms 15068 KB Output is correct
37 Correct 366 ms 15528 KB Output is correct
38 Correct 365 ms 15200 KB Output is correct
39 Correct 371 ms 15196 KB Output is correct
40 Correct 300 ms 37468 KB Output is correct
41 Correct 214 ms 37724 KB Output is correct
42 Correct 88 ms 6876 KB Output is correct
43 Correct 401 ms 17456 KB Output is correct
44 Correct 403 ms 17372 KB Output is correct
45 Correct 394 ms 17632 KB Output is correct
46 Correct 295 ms 14820 KB Output is correct
47 Correct 371 ms 16348 KB Output is correct
48 Correct 138 ms 16220 KB Output is correct
49 Correct 388 ms 17256 KB Output is correct
50 Correct 397 ms 17536 KB Output is correct
51 Correct 382 ms 16988 KB Output is correct
52 Correct 363 ms 16348 KB Output is correct
53 Correct 213 ms 40156 KB Output is correct