#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll int
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
#define maxn 400005
struct tupl{
ll x,y,sum,id;
} v[maxn];
ll n,q;
pll a[maxn];
bool ok[maxn];
bool cmp(pll x,pll y){return x.fi+x.sc<y.fi+y.sc;}
bool cmp2(tupl x,tupl y){return x.sum<y.sum;}
bool cmp3(tupl x,tupl y){
if(x.x!=y.x) return x.x<y.x;
return x.y<y.y;
}
ll ans[maxn];
void tc(){
cin >> n >> q;
for(ll i = 1;i<=n;i++) cin >> a[i].fi >> a[i].sc;
for(ll i = 1;i<=q;i++) cin >> v[i].x >> v[i].y >> v[i].sum;
for(ll i = 1;i<=q;i++) v[i].id = i;
sort(a+1,a+1+n,cmp);
sort(v+1,v+1+q,cmp2);
ll k = n;
ordered_multiset sx,sy;
for(ll j = q;j>=1;j--){
if(v[j].x+v[j].y>=v[j].sum){
ok[v[j].id] = 1;
continue;
}
while(k>=1&&a[k].fi+a[k].sc>=v[j].sum){
sx.insert(a[k].fi); sy.insert(a[k].sc);
k--;
}
ans[v[j].id] = sz(sx) - sx.order_of_key(v[j].x) - sy.order_of_key(v[j].y);
}
sort(v+1,v+1+q,cmp3);
sort(a+1,a+1+n);
sy.clear();
k = n;
for(ll i = q;i>=1;i--){
if(!ok[v[i].id]) continue;
while(k>=1&&a[k].fi>=v[i].x){
sy.insert(a[k].sc);
k--;
}
ans[v[i].id] = sz(sy) - sy.order_of_key(v[i].y);
}
for(ll i = 1;i<=q;i++) cout<<ans[i]<<endl;
}
int main(){
daj_mi_malo_vremena
int t; t = 1;
while(t--){
tc();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
6 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
7 ms |
724 KB |
Output is correct |
11 |
Correct |
6 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
712 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
6 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
8384 KB |
Output is correct |
2 |
Correct |
120 ms |
8404 KB |
Output is correct |
3 |
Correct |
128 ms |
8432 KB |
Output is correct |
4 |
Correct |
108 ms |
8416 KB |
Output is correct |
5 |
Correct |
96 ms |
8416 KB |
Output is correct |
6 |
Correct |
81 ms |
8428 KB |
Output is correct |
7 |
Correct |
132 ms |
8436 KB |
Output is correct |
8 |
Correct |
119 ms |
8388 KB |
Output is correct |
9 |
Correct |
121 ms |
8452 KB |
Output is correct |
10 |
Correct |
94 ms |
8232 KB |
Output is correct |
11 |
Correct |
114 ms |
8256 KB |
Output is correct |
12 |
Correct |
91 ms |
8024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
8384 KB |
Output is correct |
2 |
Correct |
120 ms |
8404 KB |
Output is correct |
3 |
Correct |
128 ms |
8432 KB |
Output is correct |
4 |
Correct |
108 ms |
8416 KB |
Output is correct |
5 |
Correct |
96 ms |
8416 KB |
Output is correct |
6 |
Correct |
81 ms |
8428 KB |
Output is correct |
7 |
Correct |
132 ms |
8436 KB |
Output is correct |
8 |
Correct |
119 ms |
8388 KB |
Output is correct |
9 |
Correct |
121 ms |
8452 KB |
Output is correct |
10 |
Correct |
94 ms |
8232 KB |
Output is correct |
11 |
Correct |
114 ms |
8256 KB |
Output is correct |
12 |
Correct |
91 ms |
8024 KB |
Output is correct |
13 |
Correct |
280 ms |
13068 KB |
Output is correct |
14 |
Correct |
251 ms |
13004 KB |
Output is correct |
15 |
Correct |
124 ms |
8416 KB |
Output is correct |
16 |
Correct |
243 ms |
13064 KB |
Output is correct |
17 |
Correct |
184 ms |
13044 KB |
Output is correct |
18 |
Correct |
162 ms |
12996 KB |
Output is correct |
19 |
Correct |
296 ms |
13080 KB |
Output is correct |
20 |
Correct |
250 ms |
13108 KB |
Output is correct |
21 |
Correct |
271 ms |
13036 KB |
Output is correct |
22 |
Correct |
90 ms |
8268 KB |
Output is correct |
23 |
Correct |
123 ms |
8224 KB |
Output is correct |
24 |
Correct |
90 ms |
8080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
5 ms |
724 KB |
Output is correct |
8 |
Correct |
6 ms |
724 KB |
Output is correct |
9 |
Correct |
5 ms |
724 KB |
Output is correct |
10 |
Correct |
7 ms |
724 KB |
Output is correct |
11 |
Correct |
6 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
712 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
6 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
129 ms |
8384 KB |
Output is correct |
20 |
Correct |
120 ms |
8404 KB |
Output is correct |
21 |
Correct |
128 ms |
8432 KB |
Output is correct |
22 |
Correct |
108 ms |
8416 KB |
Output is correct |
23 |
Correct |
96 ms |
8416 KB |
Output is correct |
24 |
Correct |
81 ms |
8428 KB |
Output is correct |
25 |
Correct |
132 ms |
8436 KB |
Output is correct |
26 |
Correct |
119 ms |
8388 KB |
Output is correct |
27 |
Correct |
121 ms |
8452 KB |
Output is correct |
28 |
Correct |
94 ms |
8232 KB |
Output is correct |
29 |
Correct |
114 ms |
8256 KB |
Output is correct |
30 |
Correct |
91 ms |
8024 KB |
Output is correct |
31 |
Correct |
280 ms |
13068 KB |
Output is correct |
32 |
Correct |
251 ms |
13004 KB |
Output is correct |
33 |
Correct |
124 ms |
8416 KB |
Output is correct |
34 |
Correct |
243 ms |
13064 KB |
Output is correct |
35 |
Correct |
184 ms |
13044 KB |
Output is correct |
36 |
Correct |
162 ms |
12996 KB |
Output is correct |
37 |
Correct |
296 ms |
13080 KB |
Output is correct |
38 |
Correct |
250 ms |
13108 KB |
Output is correct |
39 |
Correct |
271 ms |
13036 KB |
Output is correct |
40 |
Correct |
90 ms |
8268 KB |
Output is correct |
41 |
Correct |
123 ms |
8224 KB |
Output is correct |
42 |
Correct |
90 ms |
8080 KB |
Output is correct |
43 |
Correct |
274 ms |
13176 KB |
Output is correct |
44 |
Correct |
285 ms |
13068 KB |
Output is correct |
45 |
Correct |
255 ms |
13260 KB |
Output is correct |
46 |
Correct |
225 ms |
13060 KB |
Output is correct |
47 |
Correct |
217 ms |
12988 KB |
Output is correct |
48 |
Correct |
169 ms |
12936 KB |
Output is correct |
49 |
Correct |
358 ms |
13172 KB |
Output is correct |
50 |
Correct |
251 ms |
13076 KB |
Output is correct |
51 |
Correct |
286 ms |
13080 KB |
Output is correct |
52 |
Correct |
202 ms |
12928 KB |
Output is correct |
53 |
Correct |
122 ms |
8228 KB |
Output is correct |