답안 #411577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411577 2021-05-25T14:33:50 Z ngpin04 Examination (JOI19_examination) C++14
100 / 100
1034 ms 57264 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N = 1e5 + 5; 

struct BIT2D {
	int n;
	vector <int> sz;
	vector <int> valx;
	vector <vector <int>> valy; 
	vector <vector <int>> bit;

	void addx(int x) {
		valx.push_back(x);
	}

	void buildx() {
		sort(valx.begin(), valx.end());
		valx.resize(unique(valx.begin(), valx.end()) - valx.begin());
		n = valx.size();
		valy.resize(n + 1);
		sz.resize(n + 1);
		bit.resize(n + 1);
	}

	void add(int x, int y) {
		x = lower_bound(valx.begin(), valx.end(), x) - valx.begin() + 1;
		for (int i = x; i <= n; i += i & -i) 
			valy[i].push_back(y);

		for (int i = x; i > 0; i -= i & -i)
			valy[i].push_back(y);
	}

	void buildy() {
		for (int i = 1; i <= n; i++) {
			sort(valy[i].begin(), valy[i].end());
			valy[i].resize(unique(valy[i].begin(), valy[i].end()) - valy[i].begin());
			sz[i] = valy[i].size();
			bit[i].resize(sz[i] + 1);			
		}
	}

	void update(int x, int y) {
		x = lower_bound(valx.begin(), valx.end(), x) - valx.begin() + 1;
		for (; x <= n; x += x & -x) {
			int st = lower_bound(valy[x].begin(), valy[x].end(), y) - valy[x].begin() + 1;
			for (int i = st; i <= sz[x]; i += i & -i) 
				bit[x][i]++;
		}
	}

	int getsum(int x, int y) {
		int res = 0;
		x = lower_bound(valx.begin(), valx.end(), x) - valx.begin() + 1;
		for (; x > 0; x -= x & -x) {
			int st = lower_bound(valy[x].begin(), valy[x].end(), y) - valy[x].begin() + 1;				
			for (int i = st; i > 0; i -= i & -i) 
				res += bit[x][i];
		}
		return res;
	}
};

pair <pair <int, int>, int> qr[N];
pair <int, int> a[N];

int ans[N];
int n,q;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q;
	BIT2D bit;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].fi >> a[i].se;
		bit.addx(-a[i].fi);
	}

	for (int i = 1; i <= q; i++) {
		cin >> qr[i].fi.fi >> qr[i].fi.se >> qr[i].se;
		bit.addx(-qr[i].fi.fi);
	}
	bit.buildx();
	for (int i = 1; i <= q; i++) 
		bit.add(-qr[i].fi.fi, -qr[i].fi.se);

	for (int i = 1; i <= n; i++)
		bit.add(-a[i].fi, -a[i].se);
	
	bit.buildy();
	vector <int> id(q);
	iota(id.begin(), id.end(), 1);
	sort(id.begin(), id.end(), [](int i, int j) {
		return qr[i].se > qr[j].se;
	});

	sort(a + 1, a + n + 1, [](auto a, auto b) {
		return a.fi + a.se > b.fi + b.se;
	});

	int j = 1;
	for (int i : id) {
		while (j <= n && a[j].fi + a[j].se >= qr[i].se) {
			bit.update(-a[j].fi, -a[j].se);
			j++;
		}		
		ans[i] = bit.getsum(-qr[i].fi.fi, -qr[i].fi.se);
	}

	for (int i = 1; i <= q; i++)
		cout << ans[i] << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 14 ms 1748 KB Output is correct
8 Correct 14 ms 1672 KB Output is correct
9 Correct 13 ms 1740 KB Output is correct
10 Correct 10 ms 1484 KB Output is correct
11 Correct 7 ms 844 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 13 ms 1684 KB Output is correct
14 Correct 13 ms 1612 KB Output is correct
15 Correct 13 ms 1616 KB Output is correct
16 Correct 5 ms 588 KB Output is correct
17 Correct 9 ms 1484 KB Output is correct
18 Correct 3 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 834 ms 44200 KB Output is correct
2 Correct 818 ms 44300 KB Output is correct
3 Correct 813 ms 44252 KB Output is correct
4 Correct 418 ms 34124 KB Output is correct
5 Correct 210 ms 11816 KB Output is correct
6 Correct 109 ms 9920 KB Output is correct
7 Correct 790 ms 39396 KB Output is correct
8 Correct 768 ms 43512 KB Output is correct
9 Correct 740 ms 37960 KB Output is correct
10 Correct 134 ms 8352 KB Output is correct
11 Correct 409 ms 33192 KB Output is correct
12 Correct 80 ms 7996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 834 ms 44200 KB Output is correct
2 Correct 818 ms 44300 KB Output is correct
3 Correct 813 ms 44252 KB Output is correct
4 Correct 418 ms 34124 KB Output is correct
5 Correct 210 ms 11816 KB Output is correct
6 Correct 109 ms 9920 KB Output is correct
7 Correct 790 ms 39396 KB Output is correct
8 Correct 768 ms 43512 KB Output is correct
9 Correct 740 ms 37960 KB Output is correct
10 Correct 134 ms 8352 KB Output is correct
11 Correct 409 ms 33192 KB Output is correct
12 Correct 80 ms 7996 KB Output is correct
13 Correct 880 ms 44648 KB Output is correct
14 Correct 866 ms 44548 KB Output is correct
15 Correct 869 ms 44152 KB Output is correct
16 Correct 461 ms 34492 KB Output is correct
17 Correct 264 ms 12464 KB Output is correct
18 Correct 115 ms 10360 KB Output is correct
19 Correct 881 ms 44604 KB Output is correct
20 Correct 863 ms 44704 KB Output is correct
21 Correct 844 ms 40508 KB Output is correct
22 Correct 135 ms 8304 KB Output is correct
23 Correct 414 ms 33268 KB Output is correct
24 Correct 88 ms 8004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 14 ms 1748 KB Output is correct
8 Correct 14 ms 1672 KB Output is correct
9 Correct 13 ms 1740 KB Output is correct
10 Correct 10 ms 1484 KB Output is correct
11 Correct 7 ms 844 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 13 ms 1684 KB Output is correct
14 Correct 13 ms 1612 KB Output is correct
15 Correct 13 ms 1616 KB Output is correct
16 Correct 5 ms 588 KB Output is correct
17 Correct 9 ms 1484 KB Output is correct
18 Correct 3 ms 588 KB Output is correct
19 Correct 834 ms 44200 KB Output is correct
20 Correct 818 ms 44300 KB Output is correct
21 Correct 813 ms 44252 KB Output is correct
22 Correct 418 ms 34124 KB Output is correct
23 Correct 210 ms 11816 KB Output is correct
24 Correct 109 ms 9920 KB Output is correct
25 Correct 790 ms 39396 KB Output is correct
26 Correct 768 ms 43512 KB Output is correct
27 Correct 740 ms 37960 KB Output is correct
28 Correct 134 ms 8352 KB Output is correct
29 Correct 409 ms 33192 KB Output is correct
30 Correct 80 ms 7996 KB Output is correct
31 Correct 880 ms 44648 KB Output is correct
32 Correct 866 ms 44548 KB Output is correct
33 Correct 869 ms 44152 KB Output is correct
34 Correct 461 ms 34492 KB Output is correct
35 Correct 264 ms 12464 KB Output is correct
36 Correct 115 ms 10360 KB Output is correct
37 Correct 881 ms 44604 KB Output is correct
38 Correct 863 ms 44704 KB Output is correct
39 Correct 844 ms 40508 KB Output is correct
40 Correct 135 ms 8304 KB Output is correct
41 Correct 414 ms 33268 KB Output is correct
42 Correct 88 ms 8004 KB Output is correct
43 Correct 1028 ms 57152 KB Output is correct
44 Correct 1010 ms 57064 KB Output is correct
45 Correct 1034 ms 56988 KB Output is correct
46 Correct 602 ms 44540 KB Output is correct
47 Correct 235 ms 14120 KB Output is correct
48 Correct 117 ms 9784 KB Output is correct
49 Correct 958 ms 57264 KB Output is correct
50 Correct 1012 ms 56876 KB Output is correct
51 Correct 941 ms 57156 KB Output is correct
52 Correct 163 ms 10264 KB Output is correct
53 Correct 466 ms 43044 KB Output is correct