Submission #158413

# Submission time Handle Problem Language Result Execution time Memory
158413 2019-10-17T02:06:22 Z jhwest2 Examination (JOI19_examination) C++14
100 / 100
397 ms 15712 KB
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
struct Tup { int x, y, c, i; };

const int MAX = 1e5+1;
int N, Q;
int ans[MAX];
Tup A[MAX], B[MAX];
vector<int> v;

struct PEN {
	int tree[8*MAX];

	void update(int x) { for(; x<8*MAX; x+=x&-x) ++tree[x]; }
	int query(int a, int b) {
		int ret = 0; --a;
		for (; b; b-=b&-b) ret += tree[b];
		for (; a; a-=a&-a) ret -= tree[a];
		return ret;
	}
} seg;

void compress() {
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());

	for (int i=0; i<N; i++) {
		A[i].x = lower_bound(v.begin(), v.end(), A[i].x)-v.begin()+1;
		A[i].y = lower_bound(v.begin(), v.end(), A[i].y)-v.begin()+1;
	}
	for (int i=0; i<Q; i++) {
		B[i].x = lower_bound(v.begin(), v.end(), B[i].x)-v.begin()+1;
		B[i].y = lower_bound(v.begin(), v.end(), B[i].y)-v.begin()+1;
		B[i].c = lower_bound(v.begin(), v.end(), B[i].c)-v.begin()+1;
	}
}
bool cmp1(Tup &a, Tup &b) { return a.x<b.x; }
bool cmp2(Tup &a, Tup &b) { return v[a.x-1]+v[a.y-1]<v[b.x-1]+v[b.y-1]; }

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);

	cin >> N >> Q;
	for (int i=0; i<N; i++) {
		cin >> A[i].x >> A[i].y;
		v.push_back(A[i].x); v.push_back(A[i].y);
		v.push_back(A[i].x+A[i].y);
	}
	for (int i=0; i<Q; i++) {
		cin >> B[i].x >> B[i].y >> B[i].c; B[i].i = i;
		v.push_back(B[i].x); v.push_back(B[i].y);
		v.push_back(B[i].x+B[i].y); v.push_back(B[i].c);
		if (B[i].c > B[i].x) v.push_back(B[i].c-B[i].x);
	}
	compress();

	sort(A, A+N, cmp1); sort(B, B+Q, cmp1);

	int ap=-1, bp=-1;
	for (int i=0; i<v.size(); i++) {
		while (bp+1 < Q && B[bp+1].x == i+1) {
			++bp;
			ans[B[bp].i] -= seg.query(B[bp].y, 8*MAX-1);
			if (v[B[bp].x-1] + v[B[bp].y-1] < v[B[bp].c-1]) {
				int idx = lower_bound(v.begin(), v.end(), v[B[bp].c-1]-v[B[bp].x-1]) - v.begin()+1;
				ans[B[bp].i] += seg.query(B[bp].y, idx);
			}
		}
		while (ap+1 < N && A[ap+1].x == i+1) {
			seg.update(A[ap+1].y); ++ap;
		}
	}
	for (int i=0; i<Q; i++) ans[B[i].i] += seg.query(B[i].y, 8*MAX-1);

	sort(A, A+N, cmp2);
	sort(B, B+Q, [&](Tup a, Tup b) { return a.c < b.c;});
	for (int i=1; i<8*MAX; i++) seg.tree[i] = 0;

	ap = -1; bp = -1;
	for (int i=0; i<v.size(); i++) {
		while (bp+1 < Q && B[bp+1].c == i+1) {
			++bp;
			if (v[B[bp].c-1] > v[B[bp].x-1] + v[B[bp].y-1]) {
				int idx = lower_bound(v.begin(), v.end(), v[B[bp].c-1]-v[B[bp].x-1]) - v.begin()+1;
				ans[B[bp].i] -= seg.query(B[bp].y, idx);
			}
		}

		while (ap+1 < N && v[A[ap+1].x-1] + v[A[ap+1].y-1] == v[i]) {
			seg.update(A[ap+1].y); ++ap;
		}
	}

	for (int i=0; i<Q; i++) cout << ans[i] << '\n';
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:65:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<v.size(); i++) {
                ~^~~~~~~~~
examination.cpp:85:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<v.size(); i++) {
                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 4 ms 3448 KB Output is correct
3 Correct 5 ms 3448 KB Output is correct
4 Correct 5 ms 3448 KB Output is correct
5 Correct 5 ms 3448 KB Output is correct
6 Correct 4 ms 3448 KB Output is correct
7 Correct 13 ms 3960 KB Output is correct
8 Correct 13 ms 3960 KB Output is correct
9 Correct 13 ms 3960 KB Output is correct
10 Correct 11 ms 3960 KB Output is correct
11 Correct 11 ms 3960 KB Output is correct
12 Correct 9 ms 3832 KB Output is correct
13 Correct 12 ms 3960 KB Output is correct
14 Correct 11 ms 3960 KB Output is correct
15 Correct 11 ms 3960 KB Output is correct
16 Correct 9 ms 3960 KB Output is correct
17 Correct 11 ms 3960 KB Output is correct
18 Correct 8 ms 3832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 254 ms 10376 KB Output is correct
2 Correct 249 ms 10532 KB Output is correct
3 Correct 250 ms 10464 KB Output is correct
4 Correct 199 ms 10372 KB Output is correct
5 Correct 192 ms 10468 KB Output is correct
6 Correct 132 ms 10444 KB Output is correct
7 Correct 240 ms 10532 KB Output is correct
8 Correct 243 ms 10440 KB Output is correct
9 Correct 233 ms 10528 KB Output is correct
10 Correct 180 ms 10336 KB Output is correct
11 Correct 192 ms 10368 KB Output is correct
12 Correct 110 ms 10080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 254 ms 10376 KB Output is correct
2 Correct 249 ms 10532 KB Output is correct
3 Correct 250 ms 10464 KB Output is correct
4 Correct 199 ms 10372 KB Output is correct
5 Correct 192 ms 10468 KB Output is correct
6 Correct 132 ms 10444 KB Output is correct
7 Correct 240 ms 10532 KB Output is correct
8 Correct 243 ms 10440 KB Output is correct
9 Correct 233 ms 10528 KB Output is correct
10 Correct 180 ms 10336 KB Output is correct
11 Correct 192 ms 10368 KB Output is correct
12 Correct 110 ms 10080 KB Output is correct
13 Correct 319 ms 10676 KB Output is correct
14 Correct 304 ms 13536 KB Output is correct
15 Correct 253 ms 13004 KB Output is correct
16 Correct 256 ms 12768 KB Output is correct
17 Correct 260 ms 13024 KB Output is correct
18 Correct 145 ms 11588 KB Output is correct
19 Correct 319 ms 13660 KB Output is correct
20 Correct 309 ms 13796 KB Output is correct
21 Correct 334 ms 13812 KB Output is correct
22 Correct 180 ms 12000 KB Output is correct
23 Correct 192 ms 12128 KB Output is correct
24 Correct 110 ms 11104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 4 ms 3448 KB Output is correct
3 Correct 5 ms 3448 KB Output is correct
4 Correct 5 ms 3448 KB Output is correct
5 Correct 5 ms 3448 KB Output is correct
6 Correct 4 ms 3448 KB Output is correct
7 Correct 13 ms 3960 KB Output is correct
8 Correct 13 ms 3960 KB Output is correct
9 Correct 13 ms 3960 KB Output is correct
10 Correct 11 ms 3960 KB Output is correct
11 Correct 11 ms 3960 KB Output is correct
12 Correct 9 ms 3832 KB Output is correct
13 Correct 12 ms 3960 KB Output is correct
14 Correct 11 ms 3960 KB Output is correct
15 Correct 11 ms 3960 KB Output is correct
16 Correct 9 ms 3960 KB Output is correct
17 Correct 11 ms 3960 KB Output is correct
18 Correct 8 ms 3832 KB Output is correct
19 Correct 254 ms 10376 KB Output is correct
20 Correct 249 ms 10532 KB Output is correct
21 Correct 250 ms 10464 KB Output is correct
22 Correct 199 ms 10372 KB Output is correct
23 Correct 192 ms 10468 KB Output is correct
24 Correct 132 ms 10444 KB Output is correct
25 Correct 240 ms 10532 KB Output is correct
26 Correct 243 ms 10440 KB Output is correct
27 Correct 233 ms 10528 KB Output is correct
28 Correct 180 ms 10336 KB Output is correct
29 Correct 192 ms 10368 KB Output is correct
30 Correct 110 ms 10080 KB Output is correct
31 Correct 319 ms 10676 KB Output is correct
32 Correct 304 ms 13536 KB Output is correct
33 Correct 253 ms 13004 KB Output is correct
34 Correct 256 ms 12768 KB Output is correct
35 Correct 260 ms 13024 KB Output is correct
36 Correct 145 ms 11588 KB Output is correct
37 Correct 319 ms 13660 KB Output is correct
38 Correct 309 ms 13796 KB Output is correct
39 Correct 334 ms 13812 KB Output is correct
40 Correct 180 ms 12000 KB Output is correct
41 Correct 192 ms 12128 KB Output is correct
42 Correct 110 ms 11104 KB Output is correct
43 Correct 386 ms 15680 KB Output is correct
44 Correct 396 ms 15556 KB Output is correct
45 Correct 359 ms 15452 KB Output is correct
46 Correct 297 ms 13920 KB Output is correct
47 Correct 289 ms 14048 KB Output is correct
48 Correct 152 ms 11616 KB Output is correct
49 Correct 376 ms 15712 KB Output is correct
50 Correct 395 ms 15488 KB Output is correct
51 Correct 397 ms 15516 KB Output is correct
52 Correct 278 ms 14092 KB Output is correct
53 Correct 207 ms 12768 KB Output is correct