답안 #1056634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056634 2024-08-13T10:24:27 Z vako_p Examination (JOI19_examination) C++14
100 / 100
315 ms 68796 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

const int mxN = 1e5 + 5;
ll n,q;
pair<ll,ll> a[mxN];
vector<pair<ll,ll>> vv;

struct bt{
	vector<vector<ll>> v,v1;
	ll sz = 1; 
	
	void init(){
		while(sz < n) sz *= 2;
		v.resize(2 * sz);
		v1.resize(2 * sz);
		for(int i = sz - 1; i < 2 * sz - 1; i++){
			if(i - sz + 1 < n){
				v[i].pb(a[i - sz + 1].first + a[i - sz + 1].second);
				v1[i].pb(a[i - sz + 1].second);
			}
			else{
				v[i].pb(0);
				v1[i].pb(0);
			}
		}
		for(int x = sz - 2; x >= 0; x--){
			ll l = 0;
			for(int i = 0; i < v[2 * x + 1].size(); ){
				if(l >= v[2 * x + 2].size()){
					v[x].pb(v[2 * x + 1][i++]);
					continue;
				}
				if(v[2 * x + 2][l] <= v[2 * x + 1][i]) v[x].pb(v[2 * x + 2][l++]);
				else v[x].pb(v[2 * x + 1][i++]);
			}
			for( ; l < v1[2 * x + 2].size(); l++) v[x].pb(v[2 * x + 2][l]);
			l = 0;
			for(int i = 0; i < v1[2 * x + 1].size(); ){
				if(l >= v1[2 * x + 2].size()){
					v1[x].pb(v1[2 * x + 1][i++]);
					continue;
				}
				if(v1[2 * x + 2][l] <= v1[2 * x + 1][i]) v1[x].pb(v1[2 * x + 2][l++]);
				else v1[x].pb(v1[2 * x + 1][i++]);
			}
			for( ; l < v1[2 * x + 2].size(); l++) v1[x].pb(v1[2 * x + 2][l]);
		}
	}
	
	ll find(ll val, ll l, ll r, ll x, ll lx, ll rx){
		if(lx >= r or rx <= l) return 0LL;
		if(lx >= l and rx <= r){
			auto it = lower_bound(v[x].begin(), v[x].end(), val);
			ll dis = it - v[x].begin(), siz = v[x].size();
			return (siz - dis);
		}
		ll mid = lx + (rx - lx) / 2;
		return (find(val, l, r, 2 * x + 1, lx, mid) + find(val, l, r, 2 * x + 2, mid, rx));
	}
	
	ll find(ll val, ll l, ll r){
		return find(val, l, r, 0, 0, sz);
	}
	
	ll find1(ll val, ll l, ll r, ll x, ll lx, ll rx){
		if(lx >= r or rx <= l) return 0LL;
		if(lx >= l and rx <= r){
			auto it = lower_bound(v1[x].begin(), v1[x].end(), val);
			ll dis = it - v1[x].begin(), siz = v1[x].size();
			return (siz - dis);
		}
		ll mid = lx + (rx - lx) / 2;
		return (find1(val, l, r, 2 * x + 1, lx, mid) + find1(val, l, r, 2 * x + 2, mid, rx));
	}
	
	ll find1(ll val, ll l, ll r){
		return find1(val, l, r, 0, 0, sz);
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> q;
	bt s;
	for(int i = 0; i < n; i++){
		cin >> a[i].first >> a[i].second;
	}
	sort(a, a + n);
	s.init();
	vv.pb({a[0].first, 0});
	for(int i = 1; i < n; i++) if(a[i].first != a[i - 1].first) vv.pb({a[i].first, i}); 
	while(q--){
		ll A,B,C;
		cin >> A >> B >> C;
		pair<ll,ll> xx = {A, 0};
		auto it = lower_bound(vv.begin(), vv.end(), xx);
		if(it == vv.end()){
			cout << 0 << '\n';
			continue;
		}
		if(A + B >= C){
			cout << s.find1(B, (*it).second, n) << '\n';
		}  
		else{
			ll A1 = C - B;
			xx = {A1, 0};
			auto it1 = lower_bound(vv.begin(), vv.end(), xx);
			if(it1 == vv.end()) cout << s.find(C, (*it).second, n) << '\n';
			else cout << s.find(C, (*it).second, (*it1).second) + s.find1(B, (*it1).second, n)<< '\n';
		}
	}
}

Compilation message

examination.cpp: In member function 'void bt::init()':
examination.cpp:31:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |    for(int i = 0; i < v[2 * x + 1].size(); ){
      |                   ~~^~~~~~~~~~~~~~~~~~~~~
examination.cpp:32:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     if(l >= v[2 * x + 2].size()){
      |        ~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:39:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |    for( ; l < v1[2 * x + 2].size(); l++) v[x].pb(v[2 * x + 2][l]);
      |           ~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:41:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |    for(int i = 0; i < v1[2 * x + 1].size(); ){
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:42:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     if(l >= v1[2 * x + 2].size()){
      |        ~~^~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:49:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |    for( ; l < v1[2 * x + 2].size(); l++) v1[x].pb(v1[2 * x + 2][l]);
      |           ~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 5 ms 2140 KB Output is correct
8 Correct 5 ms 2352 KB Output is correct
9 Correct 5 ms 2140 KB Output is correct
10 Correct 4 ms 2140 KB Output is correct
11 Correct 3 ms 2140 KB Output is correct
12 Correct 5 ms 1992 KB Output is correct
13 Correct 5 ms 2140 KB Output is correct
14 Correct 4 ms 2140 KB Output is correct
15 Correct 4 ms 2316 KB Output is correct
16 Correct 2 ms 2084 KB Output is correct
17 Correct 4 ms 2140 KB Output is correct
18 Correct 2 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 65864 KB Output is correct
2 Correct 221 ms 65876 KB Output is correct
3 Correct 207 ms 65668 KB Output is correct
4 Correct 160 ms 65000 KB Output is correct
5 Correct 118 ms 64136 KB Output is correct
6 Correct 91 ms 63308 KB Output is correct
7 Correct 192 ms 65800 KB Output is correct
8 Correct 171 ms 65628 KB Output is correct
9 Correct 153 ms 65584 KB Output is correct
10 Correct 80 ms 63948 KB Output is correct
11 Correct 124 ms 64816 KB Output is correct
12 Correct 66 ms 62856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 201 ms 65864 KB Output is correct
2 Correct 221 ms 65876 KB Output is correct
3 Correct 207 ms 65668 KB Output is correct
4 Correct 160 ms 65000 KB Output is correct
5 Correct 118 ms 64136 KB Output is correct
6 Correct 91 ms 63308 KB Output is correct
7 Correct 192 ms 65800 KB Output is correct
8 Correct 171 ms 65628 KB Output is correct
9 Correct 153 ms 65584 KB Output is correct
10 Correct 80 ms 63948 KB Output is correct
11 Correct 124 ms 64816 KB Output is correct
12 Correct 66 ms 62856 KB Output is correct
13 Correct 242 ms 66112 KB Output is correct
14 Correct 234 ms 66108 KB Output is correct
15 Correct 198 ms 65856 KB Output is correct
16 Correct 206 ms 65356 KB Output is correct
17 Correct 121 ms 64404 KB Output is correct
18 Correct 105 ms 63376 KB Output is correct
19 Correct 245 ms 66312 KB Output is correct
20 Correct 262 ms 66096 KB Output is correct
21 Correct 264 ms 66120 KB Output is correct
22 Correct 81 ms 63896 KB Output is correct
23 Correct 127 ms 64840 KB Output is correct
24 Correct 66 ms 63056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 5 ms 2140 KB Output is correct
8 Correct 5 ms 2352 KB Output is correct
9 Correct 5 ms 2140 KB Output is correct
10 Correct 4 ms 2140 KB Output is correct
11 Correct 3 ms 2140 KB Output is correct
12 Correct 5 ms 1992 KB Output is correct
13 Correct 5 ms 2140 KB Output is correct
14 Correct 4 ms 2140 KB Output is correct
15 Correct 4 ms 2316 KB Output is correct
16 Correct 2 ms 2084 KB Output is correct
17 Correct 4 ms 2140 KB Output is correct
18 Correct 2 ms 1884 KB Output is correct
19 Correct 201 ms 65864 KB Output is correct
20 Correct 221 ms 65876 KB Output is correct
21 Correct 207 ms 65668 KB Output is correct
22 Correct 160 ms 65000 KB Output is correct
23 Correct 118 ms 64136 KB Output is correct
24 Correct 91 ms 63308 KB Output is correct
25 Correct 192 ms 65800 KB Output is correct
26 Correct 171 ms 65628 KB Output is correct
27 Correct 153 ms 65584 KB Output is correct
28 Correct 80 ms 63948 KB Output is correct
29 Correct 124 ms 64816 KB Output is correct
30 Correct 66 ms 62856 KB Output is correct
31 Correct 242 ms 66112 KB Output is correct
32 Correct 234 ms 66108 KB Output is correct
33 Correct 198 ms 65856 KB Output is correct
34 Correct 206 ms 65356 KB Output is correct
35 Correct 121 ms 64404 KB Output is correct
36 Correct 105 ms 63376 KB Output is correct
37 Correct 245 ms 66312 KB Output is correct
38 Correct 262 ms 66096 KB Output is correct
39 Correct 264 ms 66120 KB Output is correct
40 Correct 81 ms 63896 KB Output is correct
41 Correct 127 ms 64840 KB Output is correct
42 Correct 66 ms 63056 KB Output is correct
43 Correct 256 ms 68796 KB Output is correct
44 Correct 267 ms 68748 KB Output is correct
45 Correct 234 ms 68708 KB Output is correct
46 Correct 205 ms 67132 KB Output is correct
47 Correct 128 ms 65672 KB Output is correct
48 Correct 101 ms 63104 KB Output is correct
49 Correct 300 ms 68664 KB Output is correct
50 Correct 231 ms 68668 KB Output is correct
51 Correct 315 ms 68464 KB Output is correct
52 Correct 87 ms 65416 KB Output is correct
53 Correct 128 ms 66108 KB Output is correct