Submission #1080080

# Submission time Handle Problem Language Result Execution time Memory
1080080 2024-08-29T06:50:13 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
404 ms 7376 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 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2468 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 0 ms 2652 KB Output is correct
7 Correct 8 ms 2700 KB Output is correct
8 Correct 7 ms 2652 KB Output is correct
9 Correct 8 ms 2748 KB Output is correct
10 Correct 6 ms 2652 KB Output is correct
11 Correct 6 ms 2748 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 6 ms 2652 KB Output is correct
14 Correct 7 ms 2748 KB Output is correct
15 Correct 6 ms 2652 KB Output is correct
16 Correct 5 ms 2748 KB Output is correct
17 Correct 5 ms 2652 KB Output is correct
18 Correct 4 ms 2752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 354 ms 7316 KB Output is correct
2 Correct 334 ms 7120 KB Output is correct
3 Correct 333 ms 7120 KB Output is correct
4 Correct 195 ms 7116 KB Output is correct
5 Correct 290 ms 7228 KB Output is correct
6 Correct 147 ms 7372 KB Output is correct
7 Correct 318 ms 7112 KB Output is correct
8 Correct 333 ms 7308 KB Output is correct
9 Correct 301 ms 7120 KB Output is correct
10 Correct 295 ms 6968 KB Output is correct
11 Correct 168 ms 7112 KB Output is correct
12 Correct 109 ms 6972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 354 ms 7316 KB Output is correct
2 Correct 334 ms 7120 KB Output is correct
3 Correct 333 ms 7120 KB Output is correct
4 Correct 195 ms 7116 KB Output is correct
5 Correct 290 ms 7228 KB Output is correct
6 Correct 147 ms 7372 KB Output is correct
7 Correct 318 ms 7112 KB Output is correct
8 Correct 333 ms 7308 KB Output is correct
9 Correct 301 ms 7120 KB Output is correct
10 Correct 295 ms 6968 KB Output is correct
11 Correct 168 ms 7112 KB Output is correct
12 Correct 109 ms 6972 KB Output is correct
13 Correct 390 ms 7116 KB Output is correct
14 Correct 365 ms 7120 KB Output is correct
15 Correct 349 ms 7376 KB Output is correct
16 Correct 221 ms 7116 KB Output is correct
17 Correct 362 ms 7116 KB Output is correct
18 Correct 153 ms 7376 KB Output is correct
19 Correct 365 ms 7116 KB Output is correct
20 Correct 364 ms 7116 KB Output is correct
21 Correct 347 ms 6964 KB Output is correct
22 Correct 276 ms 7116 KB Output is correct
23 Correct 170 ms 6988 KB Output is correct
24 Correct 112 ms 6984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 ms 2652 KB Output is correct
4 Correct 1 ms 2468 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 0 ms 2652 KB Output is correct
7 Correct 8 ms 2700 KB Output is correct
8 Correct 7 ms 2652 KB Output is correct
9 Correct 8 ms 2748 KB Output is correct
10 Correct 6 ms 2652 KB Output is correct
11 Correct 6 ms 2748 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 6 ms 2652 KB Output is correct
14 Correct 7 ms 2748 KB Output is correct
15 Correct 6 ms 2652 KB Output is correct
16 Correct 5 ms 2748 KB Output is correct
17 Correct 5 ms 2652 KB Output is correct
18 Correct 4 ms 2752 KB Output is correct
19 Correct 354 ms 7316 KB Output is correct
20 Correct 334 ms 7120 KB Output is correct
21 Correct 333 ms 7120 KB Output is correct
22 Correct 195 ms 7116 KB Output is correct
23 Correct 290 ms 7228 KB Output is correct
24 Correct 147 ms 7372 KB Output is correct
25 Correct 318 ms 7112 KB Output is correct
26 Correct 333 ms 7308 KB Output is correct
27 Correct 301 ms 7120 KB Output is correct
28 Correct 295 ms 6968 KB Output is correct
29 Correct 168 ms 7112 KB Output is correct
30 Correct 109 ms 6972 KB Output is correct
31 Correct 390 ms 7116 KB Output is correct
32 Correct 365 ms 7120 KB Output is correct
33 Correct 349 ms 7376 KB Output is correct
34 Correct 221 ms 7116 KB Output is correct
35 Correct 362 ms 7116 KB Output is correct
36 Correct 153 ms 7376 KB Output is correct
37 Correct 365 ms 7116 KB Output is correct
38 Correct 364 ms 7116 KB Output is correct
39 Correct 347 ms 6964 KB Output is correct
40 Correct 276 ms 7116 KB Output is correct
41 Correct 170 ms 6988 KB Output is correct
42 Correct 112 ms 6984 KB Output is correct
43 Correct 382 ms 7316 KB Output is correct
44 Correct 380 ms 7160 KB Output is correct
45 Correct 404 ms 7220 KB Output is correct
46 Correct 252 ms 7120 KB Output is correct
47 Correct 364 ms 7224 KB Output is correct
48 Correct 158 ms 7116 KB Output is correct
49 Correct 372 ms 7028 KB Output is correct
50 Correct 391 ms 7116 KB Output is correct
51 Correct 347 ms 6988 KB Output is correct
52 Correct 342 ms 6964 KB Output is correct
53 Correct 188 ms 6964 KB Output is correct