#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define SZ(x) ll(x.size())
const ll MAXN = 1e5 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;
int n , q , A[MAXN] , B[MAXN] , C[MAXN] , ans[MAXN] , fen[2][MAXN];
vector<pii> sortA , sortB , sortC;
vector<pair<int , pii>> Q[MAXN];
void add(int ind , int x , int val){
for(x++; x < MAXN ; x += x & -x) fen[ind][x] += val;
}
int get(int ind , int x){
int ans = 0;
for(; x ; x -= x & -x) ans += fen[ind][x];
return ans;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> q;
for(int i = 0 ; i < n ; i++){
cin >> A[i] >> B[i];
C[i] = A[i] + B[i];
sortA.push_back({A[i] , i});
sortB.push_back({B[i] , i});
sortC.push_back({C[i] , i});
}
sort(all(sortA));
sort(all(sortB));
sort(all(sortC));
for(int i = 0 ; i < n ; i++){
A[i] = lower_bound(all(sortA) , pii(A[i] , -MOD)) - sortA.begin();
B[i] = lower_bound(all(sortB) , pii(B[i] , -MOD)) - sortB.begin();
C[i] = lower_bound(all(sortC) , pii(C[i] , -MOD)) - sortC.begin();
}
for(int i = 0 ; i < q ; i++){
int x , y , z;
cin >> x >> y >> z;
z = max(z , x + y);
int indx = lower_bound(all(sortA) , pii(x , -MOD)) - sortA.begin();
int indy = lower_bound(all(sortB) , pii(y , -MOD)) - sortB.begin();
int indz = lower_bound(all(sortC) , pii(z , -MOD)) - sortC.begin();
ans[i] = n - indx - indy - indz;
Q[indz].push_back({i , {0 , indx}});
Q[indz].push_back({i , {1 , indy}});
}
for(int i = 0 ; i <= n ; i++){
for(pair<int , pii> j : Q[i]){
ans[j.X] += get(j.Y.X , j.Y.Y);
}
add(0 , A[sortC[i].Y] , 1);
add(1 , B[sortC[i].Y] , 1);
}
for(int i = 0 ; i < q ; i++){
cout << ans[i] << endl;
}
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
7 ms |
3172 KB |
Output is correct |
8 |
Correct |
6 ms |
3156 KB |
Output is correct |
9 |
Correct |
7 ms |
3088 KB |
Output is correct |
10 |
Correct |
6 ms |
3076 KB |
Output is correct |
11 |
Correct |
6 ms |
3100 KB |
Output is correct |
12 |
Correct |
5 ms |
2948 KB |
Output is correct |
13 |
Correct |
6 ms |
3028 KB |
Output is correct |
14 |
Correct |
5 ms |
3028 KB |
Output is correct |
15 |
Correct |
5 ms |
3076 KB |
Output is correct |
16 |
Correct |
5 ms |
3028 KB |
Output is correct |
17 |
Correct |
5 ms |
3080 KB |
Output is correct |
18 |
Correct |
3 ms |
3076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
11192 KB |
Output is correct |
2 |
Correct |
205 ms |
11196 KB |
Output is correct |
3 |
Correct |
185 ms |
11216 KB |
Output is correct |
4 |
Correct |
206 ms |
12840 KB |
Output is correct |
5 |
Correct |
179 ms |
12728 KB |
Output is correct |
6 |
Correct |
113 ms |
11980 KB |
Output is correct |
7 |
Correct |
217 ms |
13648 KB |
Output is correct |
8 |
Correct |
180 ms |
13620 KB |
Output is correct |
9 |
Correct |
159 ms |
13744 KB |
Output is correct |
10 |
Correct |
175 ms |
12472 KB |
Output is correct |
11 |
Correct |
148 ms |
12544 KB |
Output is correct |
12 |
Correct |
67 ms |
11312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
11192 KB |
Output is correct |
2 |
Correct |
205 ms |
11196 KB |
Output is correct |
3 |
Correct |
185 ms |
11216 KB |
Output is correct |
4 |
Correct |
206 ms |
12840 KB |
Output is correct |
5 |
Correct |
179 ms |
12728 KB |
Output is correct |
6 |
Correct |
113 ms |
11980 KB |
Output is correct |
7 |
Correct |
217 ms |
13648 KB |
Output is correct |
8 |
Correct |
180 ms |
13620 KB |
Output is correct |
9 |
Correct |
159 ms |
13744 KB |
Output is correct |
10 |
Correct |
175 ms |
12472 KB |
Output is correct |
11 |
Correct |
148 ms |
12544 KB |
Output is correct |
12 |
Correct |
67 ms |
11312 KB |
Output is correct |
13 |
Correct |
206 ms |
14116 KB |
Output is correct |
14 |
Correct |
199 ms |
14004 KB |
Output is correct |
15 |
Correct |
188 ms |
13632 KB |
Output is correct |
16 |
Correct |
175 ms |
13108 KB |
Output is correct |
17 |
Correct |
164 ms |
13108 KB |
Output is correct |
18 |
Correct |
104 ms |
11812 KB |
Output is correct |
19 |
Correct |
250 ms |
14140 KB |
Output is correct |
20 |
Correct |
249 ms |
14080 KB |
Output is correct |
21 |
Correct |
202 ms |
14140 KB |
Output is correct |
22 |
Correct |
157 ms |
12392 KB |
Output is correct |
23 |
Correct |
146 ms |
12428 KB |
Output is correct |
24 |
Correct |
62 ms |
11252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
7 ms |
3172 KB |
Output is correct |
8 |
Correct |
6 ms |
3156 KB |
Output is correct |
9 |
Correct |
7 ms |
3088 KB |
Output is correct |
10 |
Correct |
6 ms |
3076 KB |
Output is correct |
11 |
Correct |
6 ms |
3100 KB |
Output is correct |
12 |
Correct |
5 ms |
2948 KB |
Output is correct |
13 |
Correct |
6 ms |
3028 KB |
Output is correct |
14 |
Correct |
5 ms |
3028 KB |
Output is correct |
15 |
Correct |
5 ms |
3076 KB |
Output is correct |
16 |
Correct |
5 ms |
3028 KB |
Output is correct |
17 |
Correct |
5 ms |
3080 KB |
Output is correct |
18 |
Correct |
3 ms |
3076 KB |
Output is correct |
19 |
Correct |
198 ms |
11192 KB |
Output is correct |
20 |
Correct |
205 ms |
11196 KB |
Output is correct |
21 |
Correct |
185 ms |
11216 KB |
Output is correct |
22 |
Correct |
206 ms |
12840 KB |
Output is correct |
23 |
Correct |
179 ms |
12728 KB |
Output is correct |
24 |
Correct |
113 ms |
11980 KB |
Output is correct |
25 |
Correct |
217 ms |
13648 KB |
Output is correct |
26 |
Correct |
180 ms |
13620 KB |
Output is correct |
27 |
Correct |
159 ms |
13744 KB |
Output is correct |
28 |
Correct |
175 ms |
12472 KB |
Output is correct |
29 |
Correct |
148 ms |
12544 KB |
Output is correct |
30 |
Correct |
67 ms |
11312 KB |
Output is correct |
31 |
Correct |
206 ms |
14116 KB |
Output is correct |
32 |
Correct |
199 ms |
14004 KB |
Output is correct |
33 |
Correct |
188 ms |
13632 KB |
Output is correct |
34 |
Correct |
175 ms |
13108 KB |
Output is correct |
35 |
Correct |
164 ms |
13108 KB |
Output is correct |
36 |
Correct |
104 ms |
11812 KB |
Output is correct |
37 |
Correct |
250 ms |
14140 KB |
Output is correct |
38 |
Correct |
249 ms |
14080 KB |
Output is correct |
39 |
Correct |
202 ms |
14140 KB |
Output is correct |
40 |
Correct |
157 ms |
12392 KB |
Output is correct |
41 |
Correct |
146 ms |
12428 KB |
Output is correct |
42 |
Correct |
62 ms |
11252 KB |
Output is correct |
43 |
Correct |
219 ms |
16036 KB |
Output is correct |
44 |
Correct |
212 ms |
16060 KB |
Output is correct |
45 |
Correct |
211 ms |
16048 KB |
Output is correct |
46 |
Correct |
179 ms |
14244 KB |
Output is correct |
47 |
Correct |
169 ms |
14172 KB |
Output is correct |
48 |
Correct |
116 ms |
10984 KB |
Output is correct |
49 |
Correct |
212 ms |
15928 KB |
Output is correct |
50 |
Correct |
230 ms |
15940 KB |
Output is correct |
51 |
Correct |
199 ms |
15912 KB |
Output is correct |
52 |
Correct |
157 ms |
13972 KB |
Output is correct |
53 |
Correct |
146 ms |
13152 KB |
Output is correct |