답안 #378056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378056 2021-03-15T21:48:39 Z penguinhacker Examination (JOI19_examination) C++14
100 / 100
434 ms 19140 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN = 100000;
int n, q, ans[mxN], bit[2 * mxN + 1];

void upd(int i, int inc) {
	for (++i; i <= 2 * mxN; i += i & -i)
		bit[i] += inc;
}

int qry(int i) {
	int res = 0;
	for (++i; i > 0; i -= i & -i)
		res += bit[i];
	return res;
}

struct Query {
	int a, b, c, ind;
	bool operator<(const Query& o) const {
		if (a ^ o.a) return a > o.a;
		if (b ^ o.b) return b > o.b;
		if (c ^ o.c) return c > o.c;
		return ind < o.ind;
	}
} qrys[2 * mxN];

void solve(int l = 0, int r = n + q - 1) {
	if (l == r)
		return;
	int mid = (l + r) / 2;
	solve(l, mid);
	solve(mid + 1, r);
	vector<Query> tmp;
	vector<int> rb;
	int i = l, j = mid + 1;
	for (; j <= r; ++j) {
		while(i <= mid && qrys[i].b >= qrys[j].b) {
			if (qrys[i].ind == -1) {
				upd(qrys[i].c, 1);
				rb.push_back(qrys[i].c);
			}
			tmp.push_back(qrys[i++]);
		}
		if (qrys[j].ind != -1)
			ans[qrys[j].ind] += qry(2 * mxN - 1) - qry(qrys[j].c - 1);
		tmp.push_back(qrys[j]);
	}
	while(i <= mid)
		tmp.push_back(qrys[i++]);
	assert(tmp.size() == r - l + 1);
	for (int i = l; i <= r; ++i)
		qrys[i] = tmp[i - l];
	for (int i : rb)
		upd(i, -1);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n; ++i) {
		int a, b; cin >> a >> b;
		qrys[i] = {a, b, a + b, -1};
	}
	for (int i = 0; i < q; ++i) {
		int a, b, c; cin >> a >> b >> c;
		qrys[i + n] = {a, b, c, i};
	}
	vector<int> da(n + q), db(n + q), dc(n + q);
	for (int i = 0; i < n + q; ++i)
		da[i] = qrys[i].a, db[i] = qrys[i].b, dc[i] = qrys[i].c;
	sort(da.begin(), da.end());
	sort(db.begin(), db.end());
	sort(dc.begin(), dc.end());
	for (int i = 0; i < n + q; ++i) {
		qrys[i].a = lower_bound(da.begin(), da.end(), qrys[i].a) - da.begin();
		qrys[i].b = lower_bound(db.begin(), db.end(), qrys[i].b) - db.begin();
		qrys[i].c = lower_bound(dc.begin(), dc.end(), qrys[i].c) - dc.begin();
	}
	sort(qrys, qrys + n + q);
	solve();
	for (int i = 0; i < q; ++i)
		cout << ans[i] << "\n";
	return 0;
}

Compilation message

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from examination.cpp:1:
examination.cpp: In function 'void solve(int, int)':
examination.cpp:55:20: warning: comparison of integer expressions of different signedness: 'std::vector<Query>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |  assert(tmp.size() == r - l + 1);
      |         ~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 10 ms 908 KB Output is correct
8 Correct 10 ms 908 KB Output is correct
9 Correct 11 ms 908 KB Output is correct
10 Correct 9 ms 876 KB Output is correct
11 Correct 9 ms 896 KB Output is correct
12 Correct 7 ms 876 KB Output is correct
13 Correct 9 ms 876 KB Output is correct
14 Correct 11 ms 896 KB Output is correct
15 Correct 9 ms 876 KB Output is correct
16 Correct 7 ms 876 KB Output is correct
17 Correct 8 ms 876 KB Output is correct
18 Correct 6 ms 780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 360 ms 16356 KB Output is correct
2 Correct 350 ms 16408 KB Output is correct
3 Correct 365 ms 16392 KB Output is correct
4 Correct 302 ms 15640 KB Output is correct
5 Correct 298 ms 15920 KB Output is correct
6 Correct 222 ms 14788 KB Output is correct
7 Correct 339 ms 16244 KB Output is correct
8 Correct 341 ms 16280 KB Output is correct
9 Correct 338 ms 16152 KB Output is correct
10 Correct 308 ms 15680 KB Output is correct
11 Correct 309 ms 15640 KB Output is correct
12 Correct 218 ms 13376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 360 ms 16356 KB Output is correct
2 Correct 350 ms 16408 KB Output is correct
3 Correct 365 ms 16392 KB Output is correct
4 Correct 302 ms 15640 KB Output is correct
5 Correct 298 ms 15920 KB Output is correct
6 Correct 222 ms 14788 KB Output is correct
7 Correct 339 ms 16244 KB Output is correct
8 Correct 341 ms 16280 KB Output is correct
9 Correct 338 ms 16152 KB Output is correct
10 Correct 308 ms 15680 KB Output is correct
11 Correct 309 ms 15640 KB Output is correct
12 Correct 218 ms 13376 KB Output is correct
13 Correct 434 ms 17128 KB Output is correct
14 Correct 396 ms 17176 KB Output is correct
15 Correct 357 ms 16360 KB Output is correct
16 Correct 347 ms 16408 KB Output is correct
17 Correct 348 ms 16464 KB Output is correct
18 Correct 235 ms 14884 KB Output is correct
19 Correct 399 ms 17256 KB Output is correct
20 Correct 401 ms 17188 KB Output is correct
21 Correct 392 ms 17148 KB Output is correct
22 Correct 276 ms 15780 KB Output is correct
23 Correct 280 ms 15640 KB Output is correct
24 Correct 246 ms 13376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 10 ms 908 KB Output is correct
8 Correct 10 ms 908 KB Output is correct
9 Correct 11 ms 908 KB Output is correct
10 Correct 9 ms 876 KB Output is correct
11 Correct 9 ms 896 KB Output is correct
12 Correct 7 ms 876 KB Output is correct
13 Correct 9 ms 876 KB Output is correct
14 Correct 11 ms 896 KB Output is correct
15 Correct 9 ms 876 KB Output is correct
16 Correct 7 ms 876 KB Output is correct
17 Correct 8 ms 876 KB Output is correct
18 Correct 6 ms 780 KB Output is correct
19 Correct 360 ms 16356 KB Output is correct
20 Correct 350 ms 16408 KB Output is correct
21 Correct 365 ms 16392 KB Output is correct
22 Correct 302 ms 15640 KB Output is correct
23 Correct 298 ms 15920 KB Output is correct
24 Correct 222 ms 14788 KB Output is correct
25 Correct 339 ms 16244 KB Output is correct
26 Correct 341 ms 16280 KB Output is correct
27 Correct 338 ms 16152 KB Output is correct
28 Correct 308 ms 15680 KB Output is correct
29 Correct 309 ms 15640 KB Output is correct
30 Correct 218 ms 13376 KB Output is correct
31 Correct 434 ms 17128 KB Output is correct
32 Correct 396 ms 17176 KB Output is correct
33 Correct 357 ms 16360 KB Output is correct
34 Correct 347 ms 16408 KB Output is correct
35 Correct 348 ms 16464 KB Output is correct
36 Correct 235 ms 14884 KB Output is correct
37 Correct 399 ms 17256 KB Output is correct
38 Correct 401 ms 17188 KB Output is correct
39 Correct 392 ms 17148 KB Output is correct
40 Correct 276 ms 15780 KB Output is correct
41 Correct 280 ms 15640 KB Output is correct
42 Correct 246 ms 13376 KB Output is correct
43 Correct 408 ms 19140 KB Output is correct
44 Correct 421 ms 19108 KB Output is correct
45 Correct 406 ms 19088 KB Output is correct
46 Correct 351 ms 17560 KB Output is correct
47 Correct 361 ms 17752 KB Output is correct
48 Correct 232 ms 14716 KB Output is correct
49 Correct 387 ms 19020 KB Output is correct
50 Correct 396 ms 18968 KB Output is correct
51 Correct 382 ms 18928 KB Output is correct
52 Correct 338 ms 17472 KB Output is correct
53 Correct 299 ms 16408 KB Output is correct