답안 #845979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
845979 2023-09-07T01:53:27 Z NK_ Examination (JOI19_examination) C++17
100 / 100
199 ms 20928 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define pb push_back
#define pf push_front
 
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
 
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
 
using db = long double;
 
template<class T> using pq = priority_queue<T, V<T>, less<T>>;
 
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 19;
 
struct BIT {
	int N; V<ll> data;
	void init(int _N) { N = _N; data = V<ll>(N, 0); }
	void add(int p, ll x) { for (++p;p<=N;p+=p&-p) data[p-1] += x; }
	ll sum(int l, int r) { return sum(r+1)-sum(l); }
	ll sum(int r) { ll s = 0; for(;r;r-=r&-r)s+=data[r-1]; return s; }
};
 
int main() {
	cin.tie(0)->sync_with_stdio(0);
 
	int N, Q; cin >> N >> Q;
 
	vl A(N), B(N); for(int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
	}
 
	vi I(N); iota(begin(I), end(I), 0);
 
	sort(begin(I), end(I), [&](int a, int b) {
		return A[a] > A[b];
	}); 
 
	V<V<array<ll, 3>>> QQ(N); vi ans(Q);
 
	auto find = [&](ll x) {
		int lo = -1, hi = N - 1;
		while(lo < hi) {
			int mid = (lo + hi + 1) / 2;
			if (x <= A[I[mid]]) lo = mid;
			else hi = mid - 1;
		}
		return lo;
	};
 
	for(int i = 0; i < Q; i++) {
		ll a, b, c; cin >> a >> b >> c; 
		// cout << a << " " << b << " " << c << endl;
 
		// c-query
		int cq = find(a);
		if (cq != -1) {
			QQ[cq].pb({c, 1, i});
			// cout << i << " " << cq << endl;
		}
 
		// everything after is a b-query
		int bq = min(find(c - b), cq);
		if (bq != -1) {
			QQ[bq].pb({c, -1, i});
			QQ[bq].pb({b, 0, i});
			// cout << i << " " << bq << endl;
		}
	}
 
	// cout << endl;
 
	vl COOR = {INFL};
	for(int i = 0; i < N; i++) { 
		COOR.pb(A[i] + B[i]);
		COOR.pb(B[i]);
	}
 
	sort(begin(COOR), end(COOR));
	COOR.erase(unique(begin(COOR), end(COOR)), end(COOR));
 
	int M = sz(COOR);
	BIT ct, bt; ct.init(M + 1), bt.init(M + 1);
	for(int i = 0; i < N; i++) {
		int ab = lower_bound(begin(COOR), end(COOR), A[I[i]] + B[I[i]]) - begin(COOR);
		int b = lower_bound(begin(COOR), end(COOR), B[I[i]]) - begin(COOR);
 
		ct.add(ab, 1);
		bt.add(b, 1);
 
		for(auto q : QQ[i]) {
			if (q[1] == 0) {
				int x = lower_bound(begin(COOR), end(COOR), q[0]) - begin(COOR);
				ans[q[2]] += bt.sum(x, M - 1);
			} else {
				int x = lower_bound(begin(COOR), end(COOR), q[0]) - begin(COOR);
				ans[q[2]] += q[1] * ct.sum(x, M - 1);
			}
		}
	}
 
	for(int i = 0; i < Q; i++) cout << ans[i] << nl;
 
	exit(0-0);
} 			
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 4 ms 856 KB Output is correct
8 Correct 4 ms 856 KB Output is correct
9 Correct 4 ms 856 KB Output is correct
10 Correct 4 ms 856 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 3 ms 856 KB Output is correct
14 Correct 3 ms 856 KB Output is correct
15 Correct 3 ms 856 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 3 ms 856 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 20028 KB Output is correct
2 Correct 146 ms 19920 KB Output is correct
3 Correct 156 ms 19816 KB Output is correct
4 Correct 110 ms 19520 KB Output is correct
5 Correct 101 ms 15588 KB Output is correct
6 Correct 55 ms 14828 KB Output is correct
7 Correct 130 ms 20160 KB Output is correct
8 Correct 148 ms 19908 KB Output is correct
9 Correct 129 ms 20388 KB Output is correct
10 Correct 81 ms 14348 KB Output is correct
11 Correct 103 ms 19016 KB Output is correct
12 Correct 39 ms 10816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 20028 KB Output is correct
2 Correct 146 ms 19920 KB Output is correct
3 Correct 156 ms 19816 KB Output is correct
4 Correct 110 ms 19520 KB Output is correct
5 Correct 101 ms 15588 KB Output is correct
6 Correct 55 ms 14828 KB Output is correct
7 Correct 130 ms 20160 KB Output is correct
8 Correct 148 ms 19908 KB Output is correct
9 Correct 129 ms 20388 KB Output is correct
10 Correct 81 ms 14348 KB Output is correct
11 Correct 103 ms 19016 KB Output is correct
12 Correct 39 ms 10816 KB Output is correct
13 Correct 174 ms 17348 KB Output is correct
14 Correct 182 ms 19460 KB Output is correct
15 Correct 146 ms 19904 KB Output is correct
16 Correct 147 ms 18428 KB Output is correct
17 Correct 112 ms 13324 KB Output is correct
18 Correct 58 ms 14828 KB Output is correct
19 Correct 176 ms 17760 KB Output is correct
20 Correct 178 ms 18660 KB Output is correct
21 Correct 172 ms 16320 KB Output is correct
22 Correct 81 ms 12724 KB Output is correct
23 Correct 101 ms 18880 KB Output is correct
24 Correct 35 ms 10696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 4 ms 856 KB Output is correct
8 Correct 4 ms 856 KB Output is correct
9 Correct 4 ms 856 KB Output is correct
10 Correct 4 ms 856 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 3 ms 856 KB Output is correct
14 Correct 3 ms 856 KB Output is correct
15 Correct 3 ms 856 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 3 ms 856 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 151 ms 20028 KB Output is correct
20 Correct 146 ms 19920 KB Output is correct
21 Correct 156 ms 19816 KB Output is correct
22 Correct 110 ms 19520 KB Output is correct
23 Correct 101 ms 15588 KB Output is correct
24 Correct 55 ms 14828 KB Output is correct
25 Correct 130 ms 20160 KB Output is correct
26 Correct 148 ms 19908 KB Output is correct
27 Correct 129 ms 20388 KB Output is correct
28 Correct 81 ms 14348 KB Output is correct
29 Correct 103 ms 19016 KB Output is correct
30 Correct 39 ms 10816 KB Output is correct
31 Correct 174 ms 17348 KB Output is correct
32 Correct 182 ms 19460 KB Output is correct
33 Correct 146 ms 19904 KB Output is correct
34 Correct 147 ms 18428 KB Output is correct
35 Correct 112 ms 13324 KB Output is correct
36 Correct 58 ms 14828 KB Output is correct
37 Correct 176 ms 17760 KB Output is correct
38 Correct 178 ms 18660 KB Output is correct
39 Correct 172 ms 16320 KB Output is correct
40 Correct 81 ms 12724 KB Output is correct
41 Correct 101 ms 18880 KB Output is correct
42 Correct 35 ms 10696 KB Output is correct
43 Correct 191 ms 18840 KB Output is correct
44 Correct 196 ms 18880 KB Output is correct
45 Correct 195 ms 20928 KB Output is correct
46 Correct 157 ms 18860 KB Output is correct
47 Correct 123 ms 15516 KB Output is correct
48 Correct 53 ms 11648 KB Output is correct
49 Correct 184 ms 20420 KB Output is correct
50 Correct 180 ms 17352 KB Output is correct
51 Correct 199 ms 20168 KB Output is correct
52 Correct 96 ms 11460 KB Output is correct
53 Correct 112 ms 19480 KB Output is correct