Submission #123679

# Submission time Handle Problem Language Result Execution time Memory
123679 2019-07-02T03:50:37 Z 구재현(#3036) Examination (JOI19_examination) C++14
100 / 100
504 ms 13464 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
using lint = long long;
using pi = pair<int, int>;

struct pnt{
	int x, y, z, idx;
	bool operator<(const pnt &p)const{
		return make_tuple(x, y, z, idx) < make_tuple(p.x, p.y, p.z, p.idx);
	}
}a[MAXN];

struct foo{
	int x, y, idx;
	bool operator<(const foo &f)const{
		return pi(x, idx) < pi(f.x, f.idx);
	}
};

struct bit{
	int tree[MAXN];
	void add(int x, int v){
		while(x < MAXN){
			tree[x] += v; 
			x += x & -x;
		}
	}
	int query(int x){
		int ret = 0;
		while(x){
			ret += tree[x];
			x -= x & -x;
		}
		return ret;
	}
}bit;

int n, q, ret[MAXN];

void solve(int s, int e){
	if(s == e) return;
	int m = (s + e) / 2;
	solve(s, m); solve(m + 1, e);
	vector<foo> v; 
	for(int i=s; i<=m; i++){
		if(a[i].idx == -1) v.push_back({a[i].y, a[i].z, -1});
	}
	for(int i=m+1; i<=e; i++){
		if(a[i].idx != -1) v.push_back({a[i].y, a[i].z, a[i].idx});
	}
	sort(v.begin(), v.end());
	for(auto &i : v){
		if(i.idx == -1) bit.add(i.y, 1);
		else ret[i.idx] += bit.query(i.y);
	}
	for(auto &i : v){
		if(i.idx == -1) bit.add(i.y, -1);
	}
}

int main(){
	scanf("%d %d",&n,&q);
	for(int i=0; i<n; i++){
		int x, y; scanf("%d %d",&x,&y);
		a[i] = {-x, -y, -x-y, -1};
	}
	for(int i=0; i<q; i++){
		int x, y, z; scanf("%d %d %d",&x,&y,&z);
		a[i + n] = {-x, -y, -z, i};
	}
	vector<int> vx, vy, vz;
	for(int i=0; i<n; i++){
		vx.push_back(a[i].x); vy.push_back(a[i].y); vz.push_back(a[i].z);
	}
	vx.push_back(-2e9);
	vy.push_back(-2e9);
	vz.push_back(-2e9);
	sort(vx.begin(), vx.end());
	sort(vy.begin(), vy.end());
	sort(vz.begin(), vz.end());
	vx.resize(unique(vx.begin(), vx.end()) - vx.begin());
	vy.resize(unique(vy.begin(), vy.end()) - vy.begin());
	vz.resize(unique(vz.begin(), vz.end()) - vz.begin());
	for(int i=0; i<n; i++){
		a[i].x = lower_bound(vx.begin(), vx.end(), a[i].x) - vx.begin();
		a[i].y = lower_bound(vy.begin(), vy.end(), a[i].y) - vy.begin();
		a[i].z = lower_bound(vz.begin(), vz.end(), a[i].z) - vz.begin();
	}
	for(int i=0; i<q; i++){
		a[i+n].x = upper_bound(vx.begin(), vx.end(), a[i+n].x) - vx.begin() - 1;
		a[i+n].y = upper_bound(vy.begin(), vy.end(), a[i+n].y) - vy.begin() - 1;
		a[i+n].z = upper_bound(vz.begin(), vz.end(), a[i+n].z) - vz.begin() - 1;
	}
	sort(a, a + n + q);
	solve(0, n + q - 1);
	for(int i=0; i<q; i++) printf("%d\n", ret[i]);
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~~
examination.cpp:65:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d %d",&x,&y);
             ~~~~~^~~~~~~~~~~~~~~
examination.cpp:69:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y, z; scanf("%d %d %d",&x,&y,&z);
                ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 13 ms 552 KB Output is correct
8 Correct 12 ms 632 KB Output is correct
9 Correct 12 ms 612 KB Output is correct
10 Correct 11 ms 604 KB Output is correct
11 Correct 11 ms 760 KB Output is correct
12 Correct 9 ms 632 KB Output is correct
13 Correct 12 ms 732 KB Output is correct
14 Correct 13 ms 760 KB Output is correct
15 Correct 12 ms 760 KB Output is correct
16 Correct 9 ms 632 KB Output is correct
17 Correct 11 ms 760 KB Output is correct
18 Correct 7 ms 628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 444 ms 7828 KB Output is correct
2 Correct 449 ms 7752 KB Output is correct
3 Correct 448 ms 7816 KB Output is correct
4 Correct 376 ms 7672 KB Output is correct
5 Correct 331 ms 7668 KB Output is correct
6 Correct 257 ms 7360 KB Output is correct
7 Correct 423 ms 11076 KB Output is correct
8 Correct 414 ms 10120 KB Output is correct
9 Correct 415 ms 10884 KB Output is correct
10 Correct 294 ms 9416 KB Output is correct
11 Correct 334 ms 9464 KB Output is correct
12 Correct 214 ms 7508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 444 ms 7828 KB Output is correct
2 Correct 449 ms 7752 KB Output is correct
3 Correct 448 ms 7816 KB Output is correct
4 Correct 376 ms 7672 KB Output is correct
5 Correct 331 ms 7668 KB Output is correct
6 Correct 257 ms 7360 KB Output is correct
7 Correct 423 ms 11076 KB Output is correct
8 Correct 414 ms 10120 KB Output is correct
9 Correct 415 ms 10884 KB Output is correct
10 Correct 294 ms 9416 KB Output is correct
11 Correct 334 ms 9464 KB Output is correct
12 Correct 214 ms 7508 KB Output is correct
13 Correct 470 ms 10600 KB Output is correct
14 Correct 471 ms 10612 KB Output is correct
15 Correct 446 ms 10276 KB Output is correct
16 Correct 400 ms 9836 KB Output is correct
17 Correct 358 ms 9736 KB Output is correct
18 Correct 275 ms 8352 KB Output is correct
19 Correct 470 ms 10596 KB Output is correct
20 Correct 475 ms 10684 KB Output is correct
21 Correct 455 ms 12940 KB Output is correct
22 Correct 289 ms 9396 KB Output is correct
23 Correct 335 ms 9340 KB Output is correct
24 Correct 216 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 13 ms 552 KB Output is correct
8 Correct 12 ms 632 KB Output is correct
9 Correct 12 ms 612 KB Output is correct
10 Correct 11 ms 604 KB Output is correct
11 Correct 11 ms 760 KB Output is correct
12 Correct 9 ms 632 KB Output is correct
13 Correct 12 ms 732 KB Output is correct
14 Correct 13 ms 760 KB Output is correct
15 Correct 12 ms 760 KB Output is correct
16 Correct 9 ms 632 KB Output is correct
17 Correct 11 ms 760 KB Output is correct
18 Correct 7 ms 628 KB Output is correct
19 Correct 444 ms 7828 KB Output is correct
20 Correct 449 ms 7752 KB Output is correct
21 Correct 448 ms 7816 KB Output is correct
22 Correct 376 ms 7672 KB Output is correct
23 Correct 331 ms 7668 KB Output is correct
24 Correct 257 ms 7360 KB Output is correct
25 Correct 423 ms 11076 KB Output is correct
26 Correct 414 ms 10120 KB Output is correct
27 Correct 415 ms 10884 KB Output is correct
28 Correct 294 ms 9416 KB Output is correct
29 Correct 334 ms 9464 KB Output is correct
30 Correct 214 ms 7508 KB Output is correct
31 Correct 470 ms 10600 KB Output is correct
32 Correct 471 ms 10612 KB Output is correct
33 Correct 446 ms 10276 KB Output is correct
34 Correct 400 ms 9836 KB Output is correct
35 Correct 358 ms 9736 KB Output is correct
36 Correct 275 ms 8352 KB Output is correct
37 Correct 470 ms 10596 KB Output is correct
38 Correct 475 ms 10684 KB Output is correct
39 Correct 455 ms 12940 KB Output is correct
40 Correct 289 ms 9396 KB Output is correct
41 Correct 335 ms 9340 KB Output is correct
42 Correct 216 ms 7516 KB Output is correct
43 Correct 500 ms 12716 KB Output is correct
44 Correct 504 ms 12668 KB Output is correct
45 Correct 504 ms 12804 KB Output is correct
46 Correct 425 ms 11264 KB Output is correct
47 Correct 383 ms 11188 KB Output is correct
48 Correct 275 ms 8444 KB Output is correct
49 Correct 485 ms 13464 KB Output is correct
50 Correct 469 ms 12536 KB Output is correct
51 Correct 460 ms 13452 KB Output is correct
52 Correct 334 ms 11028 KB Output is correct
53 Correct 346 ms 10328 KB Output is correct