답안 #482465

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482465 2021-10-24T15:47:32 Z S2speed Examination (JOI19_examination) C++17
100 / 100
174 ms 19004 KB
#include<bits/stdc++.h>

using namespace std;

#pragma GCC optimize ("Ofast")

#define all(x) x.begin() , x.end()
#define sze(x) (ll)(x.size())
#define mp(x , y) make_pair(x , y)
#define wall cerr<<"--------------------------------------"<<endl
typedef long long int ll;
typedef pair<ll , ll> pll;
typedef pair<int , int> pii;
typedef long double db;
typedef pair<pll , ll> plll;
typedef pair<int , pii> piii;
typedef pair<pll , pll> pllll;

const ll maxn = 1e5 + 16 , md = 1e9 + 7 , inf = 2e16;

ll gcd(ll a , ll b){
	if(a < b) swap(a , b);
	if(b == 0) return a;
	return gcd(b , a % b);
}

ll tav(ll n , ll k){
	ll res = 1;
	while(k > 0){
		if(k & 1){
			res *= n; res %= md;
		}
		n *= n; n %= md;
		k >>= 1;
	}
	return res;
}

struct fentree {

	ll sz;
	vector<ll> val;

	void init(ll n){
		sz = n;
		val.assign(sz , 0);
		return;
	}

	void add(ll i){
		ll h = i;
		while(h < sz){
			val[h]++;
			h |= (h + 1);
		}
		return;
	}

	ll cal(ll i){
		ll res = 0 , h = i;
		while(h > -1){
			res += val[h];
			h &= (h + 1); h--;
		}
		return res;
	}

	void clear(){
		val.clear();
		return;
	}

};

ll a[maxn] , b[maxn] , ap[maxn] , bp[maxn] , x[maxn] , y[maxn] , z[maxn] , ans[maxn];
vector<pll> t , r , v;
vector<ll> ca , cb;
fentree s , f;

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

	ll n , q;
	cin>>n>>q;
	for(ll i = 0 ; i < n ; i++){
		cin>>a[i]>>b[i];
		v.push_back({a[i] + b[i] , i});
	}
	for(ll i = 0 ; i < n ; i++){
		ca.push_back(a[i]);
	}
	sort(all(ca));
	ca.resize(distance(ca.begin() , unique(all(ca))));
	for(ll i = 0 ; i < n ; i++){
		ap[i] = lower_bound(all(ca) , a[i]) - ca.begin();
	}
	for(ll i = 0 ; i < n ; i++){
		cb.push_back(b[i]);
	}
	sort(all(cb));
	cb.resize(distance(cb.begin() , unique(all(cb))));
	for(ll i = 0 ; i < n ; i++){
		bp[i] = lower_bound(all(cb) , b[i]) - cb.begin();
	}
	for(ll i = 0 ; i < q ; i++){
		cin>>x[i]>>y[i]>>z[i];
		if(x[i] + y[i] >= z[i]){
			t.push_back({y[i] , i});
		} else {
			r.push_back({z[i] , i});
		}
	}
	sort(all(r) , greater<pll>());
	sort(all(v) , greater<pll>()); v.push_back({-1 , -1});
	ll p = 0;
	s.init(n); f.init(n);
	for(auto u : r){
		while(v[p].first >= u.first){
			ll j = v[p++].second;
			s.add(ap[j]); f.add(bp[j]);
		}
		ll i = u.second , j = lower_bound(all(ca) , x[i]) - ca.begin() - 1;
		ans[i] = p - s.cal(j);
		j = lower_bound(all(cb) , y[i]) - cb.begin() - 1;
		ans[i] -= f.cal(j);
	}
	s.clear();
	v.clear();
	p = 0;
	for(ll i = 0 ; i < n ; i++){
		v.push_back({b[i] , i});
	}
	sort(all(t) , greater<pll>());
	sort(all(v) , greater<pll>()); v.push_back({-1 , -1});
	s.init(n);
	for(auto u : t){
		while(v[p].first >= u.first){
			ll j = v[p++].second;
			s.add(ap[j]);
		}
		ll i = u.second , j = lower_bound(all(ca) , x[i]) - ca.begin() - 1;
		ans[i] = p - s.cal(j);
	}
	for(ll i = 0 ; i < q ; i++){
		cout<<ans[i]<<'\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 5 ms 844 KB Output is correct
8 Correct 4 ms 844 KB Output is correct
9 Correct 4 ms 844 KB Output is correct
10 Correct 4 ms 844 KB Output is correct
11 Correct 3 ms 844 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 4 ms 844 KB Output is correct
14 Correct 4 ms 844 KB Output is correct
15 Correct 4 ms 844 KB Output is correct
16 Correct 3 ms 844 KB Output is correct
17 Correct 3 ms 844 KB Output is correct
18 Correct 2 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 16336 KB Output is correct
2 Correct 132 ms 16348 KB Output is correct
3 Correct 155 ms 16368 KB Output is correct
4 Correct 104 ms 15576 KB Output is correct
5 Correct 93 ms 15608 KB Output is correct
6 Correct 86 ms 14896 KB Output is correct
7 Correct 119 ms 16224 KB Output is correct
8 Correct 125 ms 16268 KB Output is correct
9 Correct 131 ms 16184 KB Output is correct
10 Correct 93 ms 15440 KB Output is correct
11 Correct 89 ms 15372 KB Output is correct
12 Correct 56 ms 14524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 16336 KB Output is correct
2 Correct 132 ms 16348 KB Output is correct
3 Correct 155 ms 16368 KB Output is correct
4 Correct 104 ms 15576 KB Output is correct
5 Correct 93 ms 15608 KB Output is correct
6 Correct 86 ms 14896 KB Output is correct
7 Correct 119 ms 16224 KB Output is correct
8 Correct 125 ms 16268 KB Output is correct
9 Correct 131 ms 16184 KB Output is correct
10 Correct 93 ms 15440 KB Output is correct
11 Correct 89 ms 15372 KB Output is correct
12 Correct 56 ms 14524 KB Output is correct
13 Correct 144 ms 17064 KB Output is correct
14 Correct 139 ms 17080 KB Output is correct
15 Correct 123 ms 16336 KB Output is correct
16 Correct 118 ms 16188 KB Output is correct
17 Correct 112 ms 16296 KB Output is correct
18 Correct 86 ms 15168 KB Output is correct
19 Correct 149 ms 16784 KB Output is correct
20 Correct 149 ms 17004 KB Output is correct
21 Correct 156 ms 16904 KB Output is correct
22 Correct 97 ms 15512 KB Output is correct
23 Correct 96 ms 15416 KB Output is correct
24 Correct 64 ms 14520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 5 ms 844 KB Output is correct
8 Correct 4 ms 844 KB Output is correct
9 Correct 4 ms 844 KB Output is correct
10 Correct 4 ms 844 KB Output is correct
11 Correct 3 ms 844 KB Output is correct
12 Correct 3 ms 716 KB Output is correct
13 Correct 4 ms 844 KB Output is correct
14 Correct 4 ms 844 KB Output is correct
15 Correct 4 ms 844 KB Output is correct
16 Correct 3 ms 844 KB Output is correct
17 Correct 3 ms 844 KB Output is correct
18 Correct 2 ms 716 KB Output is correct
19 Correct 122 ms 16336 KB Output is correct
20 Correct 132 ms 16348 KB Output is correct
21 Correct 155 ms 16368 KB Output is correct
22 Correct 104 ms 15576 KB Output is correct
23 Correct 93 ms 15608 KB Output is correct
24 Correct 86 ms 14896 KB Output is correct
25 Correct 119 ms 16224 KB Output is correct
26 Correct 125 ms 16268 KB Output is correct
27 Correct 131 ms 16184 KB Output is correct
28 Correct 93 ms 15440 KB Output is correct
29 Correct 89 ms 15372 KB Output is correct
30 Correct 56 ms 14524 KB Output is correct
31 Correct 144 ms 17064 KB Output is correct
32 Correct 139 ms 17080 KB Output is correct
33 Correct 123 ms 16336 KB Output is correct
34 Correct 118 ms 16188 KB Output is correct
35 Correct 112 ms 16296 KB Output is correct
36 Correct 86 ms 15168 KB Output is correct
37 Correct 149 ms 16784 KB Output is correct
38 Correct 149 ms 17004 KB Output is correct
39 Correct 156 ms 16904 KB Output is correct
40 Correct 97 ms 15512 KB Output is correct
41 Correct 96 ms 15416 KB Output is correct
42 Correct 64 ms 14520 KB Output is correct
43 Correct 170 ms 18680 KB Output is correct
44 Correct 174 ms 18952 KB Output is correct
45 Correct 146 ms 18980 KB Output is correct
46 Correct 122 ms 17432 KB Output is correct
47 Correct 123 ms 17444 KB Output is correct
48 Correct 103 ms 14964 KB Output is correct
49 Correct 158 ms 19004 KB Output is correct
50 Correct 165 ms 18684 KB Output is correct
51 Correct 152 ms 18872 KB Output is correct
52 Correct 114 ms 17252 KB Output is correct
53 Correct 113 ms 16196 KB Output is correct