답안 #375272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
375272 2021-03-09T05:58:39 Z casperwang Examination (JOI19_examination) C++14
100 / 100
673 ms 24388 KB
#include <bits/stdc++.h>
#define pb emplace_back
#define All(x) x.begin(), x.end()
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

struct node {
	int a, b, c, id;
	node(int _a, int _b, int _c, int i) {
		a = _a, b = _b, c = _c, id = i;
	}
};

const int MAXN = 100000;
int N, Q;
int a, b, c;
vector <node> qry;
vector <int> cpy;
int ans[MAXN];

class Bit {
	private:
		int arr[MAXN*6+1];
		inline int lb(int a) {
			return a &- a;
		}
	public:
		void mdy(int a, int k) {
			for (int i = a; i <= MAXN*6+1; i+=lb(i))
				arr[i] += k;
		}
		int qry(int a) {
			int s = 0;
			for (int i = a; i; i-=lb(i))
				s += arr[i];
			return s;
		}
} bit;

void solve(vector <node> arr) {
	int len = arr.size();
	vector <node> L, R;
	for (int i = 0; i < len/2; i++)
		L.pb(arr[i]);
	for (int i = len/2; i < len; i++)
		R.pb(arr[i]);
	if (L.size() > 1) solve(L);
	if (R.size() > 1) solve(R);
	sort(All(L), [](const node x, const node y) {
		return x.b > y.b;
	});
	sort(All(R), [](const node x, const node y) {
		return x.b > y.b;
	});
	int nowL = 0, nowR = 0, cnt = 0;
	vector <int> del;
	while (nowR < R.size()) {
		int v = nowL < L.size() ? L[nowL].b : 0;
		while (nowR < R.size() && R[nowR].b > v) {
			if (R[nowR].id >= 0) {
				ans[R[nowR].id] += cnt - bit.qry(R[nowR].c-1);
			}
			nowR++;
		}
		while (nowL < L.size() && L[nowL].b == v) {
			if (L[nowL].id == -1) {
				del.pb(L[nowL].c);
				bit.mdy(L[nowL].c, 1);
				cnt++;
			}
			nowL++;
		}
	}
	for (int i : del)
		bit.mdy(i, -1);
	return;
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> N >> Q;
	for (int i = 0; i < N; i++) {
		cin >> a >> b;
		qry.pb(a, b, a+b, -1);
		cpy.pb(a);
		cpy.pb(b);
		cpy.pb(a+b);
	}
	for (int i = 0; i < Q; i++) {
		cin >> a >> b >> c;
		qry.pb(a, b, c, i);
		cpy.pb(a);
		cpy.pb(b);
		cpy.pb(c);
	}
	sort(All(cpy));
	for (int i = 0; i < N+Q; i++) {
		auto &[a, b, c, _] = qry[i];
		a = lower_bound(All(cpy), a) - cpy.begin() + 1;
		b = lower_bound(All(cpy), b) - cpy.begin() + 1;
		c = lower_bound(All(cpy), c) - cpy.begin() + 1;
	}
	sort(All(qry), [](const node x, const node y){
		if (x.a != y.a) return x.a > y.a;
		if (x.b != y.b) return x.b > y.b;
		if (x.c != y.c) return x.c > y.c;
		return x.id < y.id;
	});
	solve(qry);
	for (int i = 0; i < Q; i++)
		cout << ans[i] << '\n';
}

Compilation message

examination.cpp: In function 'void solve(std::vector<node>)':
examination.cpp:60:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  while (nowR < R.size()) {
      |         ~~~~~^~~~~~~~~~
examination.cpp:61:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   int v = nowL < L.size() ? L[nowL].b : 0;
      |           ~~~~~^~~~~~~~~~
examination.cpp:62:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   while (nowR < R.size() && R[nowR].b > v) {
      |          ~~~~~^~~~~~~~~~
examination.cpp:68:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   while (nowL < L.size() && L[nowL].b == v) {
      |          ~~~~~^~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:101:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  101 |   auto &[a, b, c, _] = qry[i];
      |         ^
# 결과 실행 시간 메모리 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 21 ms 1260 KB Output is correct
8 Correct 14 ms 1260 KB Output is correct
9 Correct 14 ms 1260 KB Output is correct
10 Correct 12 ms 1132 KB Output is correct
11 Correct 13 ms 1132 KB Output is correct
12 Correct 9 ms 1260 KB Output is correct
13 Correct 14 ms 1260 KB Output is correct
14 Correct 14 ms 1212 KB Output is correct
15 Correct 13 ms 1260 KB Output is correct
16 Correct 10 ms 1196 KB Output is correct
17 Correct 10 ms 1132 KB Output is correct
18 Correct 8 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 673 ms 23236 KB Output is correct
2 Correct 637 ms 22724 KB Output is correct
3 Correct 560 ms 22852 KB Output is correct
4 Correct 441 ms 21956 KB Output is correct
5 Correct 405 ms 22084 KB Output is correct
6 Correct 279 ms 20484 KB Output is correct
7 Correct 541 ms 22724 KB Output is correct
8 Correct 542 ms 22852 KB Output is correct
9 Correct 530 ms 22832 KB Output is correct
10 Correct 387 ms 21956 KB Output is correct
11 Correct 385 ms 21956 KB Output is correct
12 Correct 311 ms 20164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 673 ms 23236 KB Output is correct
2 Correct 637 ms 22724 KB Output is correct
3 Correct 560 ms 22852 KB Output is correct
4 Correct 441 ms 21956 KB Output is correct
5 Correct 405 ms 22084 KB Output is correct
6 Correct 279 ms 20484 KB Output is correct
7 Correct 541 ms 22724 KB Output is correct
8 Correct 542 ms 22852 KB Output is correct
9 Correct 530 ms 22832 KB Output is correct
10 Correct 387 ms 21956 KB Output is correct
11 Correct 385 ms 21956 KB Output is correct
12 Correct 311 ms 20164 KB Output is correct
13 Correct 624 ms 23688 KB Output is correct
14 Correct 593 ms 24260 KB Output is correct
15 Correct 567 ms 23492 KB Output is correct
16 Correct 479 ms 22824 KB Output is correct
17 Correct 460 ms 22892 KB Output is correct
18 Correct 293 ms 20292 KB Output is correct
19 Correct 612 ms 24388 KB Output is correct
20 Correct 601 ms 24128 KB Output is correct
21 Correct 596 ms 24244 KB Output is correct
22 Correct 364 ms 21828 KB Output is correct
23 Correct 367 ms 22112 KB Output is correct
24 Correct 316 ms 20184 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 21 ms 1260 KB Output is correct
8 Correct 14 ms 1260 KB Output is correct
9 Correct 14 ms 1260 KB Output is correct
10 Correct 12 ms 1132 KB Output is correct
11 Correct 13 ms 1132 KB Output is correct
12 Correct 9 ms 1260 KB Output is correct
13 Correct 14 ms 1260 KB Output is correct
14 Correct 14 ms 1212 KB Output is correct
15 Correct 13 ms 1260 KB Output is correct
16 Correct 10 ms 1196 KB Output is correct
17 Correct 10 ms 1132 KB Output is correct
18 Correct 8 ms 1260 KB Output is correct
19 Correct 673 ms 23236 KB Output is correct
20 Correct 637 ms 22724 KB Output is correct
21 Correct 560 ms 22852 KB Output is correct
22 Correct 441 ms 21956 KB Output is correct
23 Correct 405 ms 22084 KB Output is correct
24 Correct 279 ms 20484 KB Output is correct
25 Correct 541 ms 22724 KB Output is correct
26 Correct 542 ms 22852 KB Output is correct
27 Correct 530 ms 22832 KB Output is correct
28 Correct 387 ms 21956 KB Output is correct
29 Correct 385 ms 21956 KB Output is correct
30 Correct 311 ms 20164 KB Output is correct
31 Correct 624 ms 23688 KB Output is correct
32 Correct 593 ms 24260 KB Output is correct
33 Correct 567 ms 23492 KB Output is correct
34 Correct 479 ms 22824 KB Output is correct
35 Correct 460 ms 22892 KB Output is correct
36 Correct 293 ms 20292 KB Output is correct
37 Correct 612 ms 24388 KB Output is correct
38 Correct 601 ms 24128 KB Output is correct
39 Correct 596 ms 24244 KB Output is correct
40 Correct 364 ms 21828 KB Output is correct
41 Correct 367 ms 22112 KB Output is correct
42 Correct 316 ms 20184 KB Output is correct
43 Correct 630 ms 24132 KB Output is correct
44 Correct 639 ms 24020 KB Output is correct
45 Correct 621 ms 24004 KB Output is correct
46 Correct 478 ms 23364 KB Output is correct
47 Correct 457 ms 23492 KB Output is correct
48 Correct 313 ms 20420 KB Output is correct
49 Correct 615 ms 24004 KB Output is correct
50 Correct 603 ms 24136 KB Output is correct
51 Correct 593 ms 24004 KB Output is correct
52 Correct 422 ms 23364 KB Output is correct
53 Correct 381 ms 22724 KB Output is correct