Submission #1080078

# Submission time Handle Problem Language Result Execution time Memory
1080078 2024-08-29T06:49:49 Z BuzzyBeez Examination (JOI19_examination) C++17
100 / 100
408 ms 12120 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5;

vector<int> tbc;

void compress() {sort(tbc.begin(), tbc.end()); tbc.resize(unique(tbc.begin(), tbc.end()) - tbc.begin());}
int order(int key) {return lower_bound(tbc.begin(), tbc.end(), key) - tbc.begin() + 1;}

struct point {
	int Ox, Oy, Oz; char op; int id;
	
	point() {}
	
	friend istream& operator >> (istream& in, point& o) {
		in >> o.Ox >> o.Oy >> o.Oz;
		tbc.push_back(o.Oz); o.op = '?';
		return in;
	}
	
	friend ostream& operator << (ostream& out, const point& o) {
		out << o.op << ' ' << o.Ox << ' ' << o.Oy << ' ' << o.Oz;
		return out;
	}
} S[N + 8];
int ans[100008];

bool by_Ox(point& a, point& b) {
	if (a.Ox == b.Ox) return a.op < b.op;
	return a.Ox > b.Ox;
}
bool by_Oy(point& a, point& b) {return a.Oy > b.Oy;}

struct Binary_Indexed_Tree {
	int BIT[N + 8];
	
	Binary_Indexed_Tree() {memset(BIT, 0, sizeof BIT);}
	
	int pt, res;
	
	void update(int u, int v) {
	    pt = u;
	    while (pt <= N) {
	    	BIT[pt] += v;
	        pt += pt & -pt;
	    }
	}
	
	int pf(int p) {
		if (p <= 0) return 0;
	    pt = p; res = 0;
	    while (pt) {
	        res += BIT[pt];
	        pt -= pt & -pt;
	    }
	    return res;
	}
	
	int range(int l, int r) {
		if (l > r) return 0;
		return pf(r) - pf(l - 1);
	}
	
	int query(int i) {return range(i, N);}
} tree;

void dnc(int l, int r) {
	if (l >= r) return;
	int mid = (l + r) / 2, pt1, pt2 = l - 1;
	dnc(l, mid); dnc(mid + 1, r);
	vector<int> del;
	for (pt1 = mid + 1; pt1 <= r; ++pt1) if (S[pt1].op == '?') {
		while (pt2 < mid && S[pt2 + 1].Oy >= S[pt1].Oy) {
			++pt2;
			if (S[pt2].op == '+') tree.update(S[pt2].Oz, +1), del.push_back(S[pt2].Oz);
		}
		ans[S[pt1].id] += tree.query(S[pt1].Oz);
	}
	for (int i : del) tree.update(i, -1);
	del.clear();
	sort(S + l, S + r + 1, by_Oy);
	// cout << l << ' ' << r << '\n';
	// for (int i = l; i <= r; ++i) cout << S[i] << '\n';
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	for (int i = 1; i <= n; ++i) {
		cin >> S[i].Ox >> S[i].Oy; S[i].Oz = S[i].Ox + S[i].Oy;
		S[i].op = '+'; tbc.push_back(S[i].Oz);
	}
	for (int i = 1; i <= q; ++i) cin >> S[n + i], S[n + i].id = i;
	compress(); sort(S + 1, S + n + q + 1, by_Ox);
	for (int i = 1; i <= n + q; ++i) S[i].Oz = order(S[i].Oz);
	dnc(1, n + q);
	for (int i = 1; i <= q; ++i) cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 0 ms 2652 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 7 ms 2652 KB Output is correct
8 Correct 7 ms 2648 KB Output is correct
9 Correct 7 ms 2752 KB Output is correct
10 Correct 5 ms 2652 KB Output is correct
11 Correct 6 ms 2652 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 7 ms 2652 KB Output is correct
14 Correct 7 ms 2876 KB Output is correct
15 Correct 6 ms 2872 KB Output is correct
16 Correct 5 ms 2652 KB Output is correct
17 Correct 5 ms 2652 KB Output is correct
18 Correct 3 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 7112 KB Output is correct
2 Correct 341 ms 9716 KB Output is correct
3 Correct 349 ms 9676 KB Output is correct
4 Correct 200 ms 8904 KB Output is correct
5 Correct 290 ms 8980 KB Output is correct
6 Correct 165 ms 8144 KB Output is correct
7 Correct 295 ms 9408 KB Output is correct
8 Correct 338 ms 9628 KB Output is correct
9 Correct 314 ms 9420 KB Output is correct
10 Correct 293 ms 8760 KB Output is correct
11 Correct 166 ms 8872 KB Output is correct
12 Correct 113 ms 7940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 7112 KB Output is correct
2 Correct 341 ms 9716 KB Output is correct
3 Correct 349 ms 9676 KB Output is correct
4 Correct 200 ms 8904 KB Output is correct
5 Correct 290 ms 8980 KB Output is correct
6 Correct 165 ms 8144 KB Output is correct
7 Correct 295 ms 9408 KB Output is correct
8 Correct 338 ms 9628 KB Output is correct
9 Correct 314 ms 9420 KB Output is correct
10 Correct 293 ms 8760 KB Output is correct
11 Correct 166 ms 8872 KB Output is correct
12 Correct 113 ms 7940 KB Output is correct
13 Correct 375 ms 10188 KB Output is correct
14 Correct 381 ms 10188 KB Output is correct
15 Correct 335 ms 9676 KB Output is correct
16 Correct 223 ms 9420 KB Output is correct
17 Correct 352 ms 9356 KB Output is correct
18 Correct 151 ms 8396 KB Output is correct
19 Correct 408 ms 10184 KB Output is correct
20 Correct 387 ms 10236 KB Output is correct
21 Correct 354 ms 10112 KB Output is correct
22 Correct 275 ms 8792 KB Output is correct
23 Correct 166 ms 8908 KB Output is correct
24 Correct 107 ms 7960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 0 ms 2652 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 7 ms 2652 KB Output is correct
8 Correct 7 ms 2648 KB Output is correct
9 Correct 7 ms 2752 KB Output is correct
10 Correct 5 ms 2652 KB Output is correct
11 Correct 6 ms 2652 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 7 ms 2652 KB Output is correct
14 Correct 7 ms 2876 KB Output is correct
15 Correct 6 ms 2872 KB Output is correct
16 Correct 5 ms 2652 KB Output is correct
17 Correct 5 ms 2652 KB Output is correct
18 Correct 3 ms 2652 KB Output is correct
19 Correct 357 ms 7112 KB Output is correct
20 Correct 341 ms 9716 KB Output is correct
21 Correct 349 ms 9676 KB Output is correct
22 Correct 200 ms 8904 KB Output is correct
23 Correct 290 ms 8980 KB Output is correct
24 Correct 165 ms 8144 KB Output is correct
25 Correct 295 ms 9408 KB Output is correct
26 Correct 338 ms 9628 KB Output is correct
27 Correct 314 ms 9420 KB Output is correct
28 Correct 293 ms 8760 KB Output is correct
29 Correct 166 ms 8872 KB Output is correct
30 Correct 113 ms 7940 KB Output is correct
31 Correct 375 ms 10188 KB Output is correct
32 Correct 381 ms 10188 KB Output is correct
33 Correct 335 ms 9676 KB Output is correct
34 Correct 223 ms 9420 KB Output is correct
35 Correct 352 ms 9356 KB Output is correct
36 Correct 151 ms 8396 KB Output is correct
37 Correct 408 ms 10184 KB Output is correct
38 Correct 387 ms 10236 KB Output is correct
39 Correct 354 ms 10112 KB Output is correct
40 Correct 275 ms 8792 KB Output is correct
41 Correct 166 ms 8908 KB Output is correct
42 Correct 107 ms 7960 KB Output is correct
43 Correct 376 ms 11984 KB Output is correct
44 Correct 403 ms 12120 KB Output is correct
45 Correct 373 ms 11984 KB Output is correct
46 Correct 233 ms 10448 KB Output is correct
47 Correct 333 ms 10532 KB Output is correct
48 Correct 155 ms 8140 KB Output is correct
49 Correct 353 ms 11752 KB Output is correct
50 Correct 388 ms 11980 KB Output is correct
51 Correct 357 ms 11684 KB Output is correct
52 Correct 323 ms 10332 KB Output is correct
53 Correct 178 ms 9676 KB Output is correct