Submission #123922

# Submission time Handle Problem Language Result Execution time Memory
123922 2019-07-02T09:41:08 Z gs14004 Examination (JOI19_examination) C++17
100 / 100
510 ms 13436 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 2 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 380 KB Output is correct
7 Correct 13 ms 760 KB Output is correct
8 Correct 12 ms 764 KB Output is correct
9 Correct 13 ms 760 KB Output is correct
10 Correct 11 ms 732 KB Output is correct
11 Correct 11 ms 760 KB Output is correct
12 Correct 10 ms 632 KB Output is correct
13 Correct 12 ms 820 KB Output is correct
14 Correct 12 ms 760 KB Output is correct
15 Correct 13 ms 888 KB Output is correct
16 Correct 9 ms 632 KB Output is correct
17 Correct 10 ms 760 KB Output is correct
18 Correct 7 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 10112 KB Output is correct
2 Correct 451 ms 10196 KB Output is correct
3 Correct 450 ms 10220 KB Output is correct
4 Correct 380 ms 9492 KB Output is correct
5 Correct 344 ms 9496 KB Output is correct
6 Correct 256 ms 8440 KB Output is correct
7 Correct 427 ms 11048 KB Output is correct
8 Correct 418 ms 10092 KB Output is correct
9 Correct 418 ms 11040 KB Output is correct
10 Correct 294 ms 9388 KB Output is correct
11 Correct 338 ms 9328 KB Output is correct
12 Correct 218 ms 7592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 10112 KB Output is correct
2 Correct 451 ms 10196 KB Output is correct
3 Correct 450 ms 10220 KB Output is correct
4 Correct 380 ms 9492 KB Output is correct
5 Correct 344 ms 9496 KB Output is correct
6 Correct 256 ms 8440 KB Output is correct
7 Correct 427 ms 11048 KB Output is correct
8 Correct 418 ms 10092 KB Output is correct
9 Correct 418 ms 11040 KB Output is correct
10 Correct 294 ms 9388 KB Output is correct
11 Correct 338 ms 9328 KB Output is correct
12 Correct 218 ms 7592 KB Output is correct
13 Correct 478 ms 10740 KB Output is correct
14 Correct 481 ms 10608 KB Output is correct
15 Correct 453 ms 10220 KB Output is correct
16 Correct 404 ms 9840 KB Output is correct
17 Correct 361 ms 9728 KB Output is correct
18 Correct 279 ms 8444 KB Output is correct
19 Correct 491 ms 10624 KB Output is correct
20 Correct 475 ms 10604 KB Output is correct
21 Correct 460 ms 12804 KB Output is correct
22 Correct 291 ms 9268 KB Output is correct
23 Correct 335 ms 9300 KB Output is correct
24 Correct 219 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 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 380 KB Output is correct
7 Correct 13 ms 760 KB Output is correct
8 Correct 12 ms 764 KB Output is correct
9 Correct 13 ms 760 KB Output is correct
10 Correct 11 ms 732 KB Output is correct
11 Correct 11 ms 760 KB Output is correct
12 Correct 10 ms 632 KB Output is correct
13 Correct 12 ms 820 KB Output is correct
14 Correct 12 ms 760 KB Output is correct
15 Correct 13 ms 888 KB Output is correct
16 Correct 9 ms 632 KB Output is correct
17 Correct 10 ms 760 KB Output is correct
18 Correct 7 ms 636 KB Output is correct
19 Correct 450 ms 10112 KB Output is correct
20 Correct 451 ms 10196 KB Output is correct
21 Correct 450 ms 10220 KB Output is correct
22 Correct 380 ms 9492 KB Output is correct
23 Correct 344 ms 9496 KB Output is correct
24 Correct 256 ms 8440 KB Output is correct
25 Correct 427 ms 11048 KB Output is correct
26 Correct 418 ms 10092 KB Output is correct
27 Correct 418 ms 11040 KB Output is correct
28 Correct 294 ms 9388 KB Output is correct
29 Correct 338 ms 9328 KB Output is correct
30 Correct 218 ms 7592 KB Output is correct
31 Correct 478 ms 10740 KB Output is correct
32 Correct 481 ms 10608 KB Output is correct
33 Correct 453 ms 10220 KB Output is correct
34 Correct 404 ms 9840 KB Output is correct
35 Correct 361 ms 9728 KB Output is correct
36 Correct 279 ms 8444 KB Output is correct
37 Correct 491 ms 10624 KB Output is correct
38 Correct 475 ms 10604 KB Output is correct
39 Correct 460 ms 12804 KB Output is correct
40 Correct 291 ms 9268 KB Output is correct
41 Correct 335 ms 9300 KB Output is correct
42 Correct 219 ms 7544 KB Output is correct
43 Correct 508 ms 12700 KB Output is correct
44 Correct 510 ms 12600 KB Output is correct
45 Correct 507 ms 12620 KB Output is correct
46 Correct 427 ms 11064 KB Output is correct
47 Correct 382 ms 11048 KB Output is correct
48 Correct 271 ms 8456 KB Output is correct
49 Correct 495 ms 13436 KB Output is correct
50 Correct 485 ms 12572 KB Output is correct
51 Correct 470 ms 13288 KB Output is correct
52 Correct 341 ms 11108 KB Output is correct
53 Correct 348 ms 10284 KB Output is correct