#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define piii pair<int, pii>
#define pllll pair<ll, ll>
#define plli pair<ll, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define size(v) v.size()
#define INF 1e9
#define f first
#define s second
#define ln "\n"
using namespace std;
vector<pii>p;
void Sub1(int n, int q){
p.resize(n + 1);
for(int i = 1; i <= n; ++i){
cin >> p[i].f >> p[i].s;
}
while(q--){
int x, y, z;
cin >> x >> y >> z;
int cnt = 0;
for(int i = 1; i <= n; i++){
if(p[i].f >= x && p[i].s >= y && p[i].f + p[i].s >= z){
cnt++;
}
}
cout << cnt << "\n";
}
}
const int up = 1e5 + 5;
vector<int>st[up << 2];
void build(int v, int l, int r){
if(l == r){
st[v].pb(p[l - 1].s);
}else{
int mid = (l + r) >> 1;
build(v << 1, l, mid);
build((v << 1) | 1, mid + 1, r);
st[v].resize(r - l + 1);
merge(all(st[v << 1]), all(st[(v << 1) | 1]), st[v].begin());
}
}
int query(int v, int l, int r, int ql, int qr, int val){
if(r < ql || qr < l) return 0;
else if(ql <= l && r <= qr){
int pos = lower_bound(all(st[v]), val) - st[v].begin();
return size(st[v]) - pos;
}else{
int mid = (l + r) >> 1;
return query(v << 1, l, mid, ql, qr, val) + query((v << 1) | 1, mid + 1, r, ql, qr, val);
}
}
void Sub2(int n, int q){
p.resize(n);
for(int i = 0; i < n; ++i){
cin >> p[i].f >> p[i].s;
}
sort(all(p));
build(1, 1, n);
while(q--){
int x, y, z;
cin >> x >> y >> z;
pii P = {x, 0};
int pos = lower_bound(all(p), P) - p.begin();
if(pos != n){
cout << query(1, 1, n, pos + 1, n, y) << "\n";
}
}
}
void solve(){
int n, q;
cin >> n >> q;
if(n <= 3000 && q <= 3000){
Sub1(n, q);
}else{
Sub2(n, q);
}
}
int main(){
int t;
t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
5 ms |
9592 KB |
Output is correct |
7 |
Correct |
52 ms |
9684 KB |
Output is correct |
8 |
Correct |
51 ms |
9720 KB |
Output is correct |
9 |
Correct |
52 ms |
9704 KB |
Output is correct |
10 |
Correct |
53 ms |
9724 KB |
Output is correct |
11 |
Correct |
51 ms |
9708 KB |
Output is correct |
12 |
Correct |
51 ms |
9716 KB |
Output is correct |
13 |
Correct |
52 ms |
9804 KB |
Output is correct |
14 |
Correct |
52 ms |
9712 KB |
Output is correct |
15 |
Correct |
52 ms |
9604 KB |
Output is correct |
16 |
Correct |
29 ms |
9720 KB |
Output is correct |
17 |
Correct |
39 ms |
9684 KB |
Output is correct |
18 |
Correct |
17 ms |
9720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
398 ms |
22524 KB |
Output is correct |
2 |
Correct |
406 ms |
22484 KB |
Output is correct |
3 |
Correct |
399 ms |
22500 KB |
Output is correct |
4 |
Correct |
371 ms |
22500 KB |
Output is correct |
5 |
Correct |
297 ms |
22476 KB |
Output is correct |
6 |
Correct |
254 ms |
22604 KB |
Output is correct |
7 |
Correct |
379 ms |
22584 KB |
Output is correct |
8 |
Correct |
364 ms |
22504 KB |
Output is correct |
9 |
Correct |
354 ms |
22656 KB |
Output is correct |
10 |
Incorrect |
193 ms |
22276 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
398 ms |
22524 KB |
Output is correct |
2 |
Correct |
406 ms |
22484 KB |
Output is correct |
3 |
Correct |
399 ms |
22500 KB |
Output is correct |
4 |
Correct |
371 ms |
22500 KB |
Output is correct |
5 |
Correct |
297 ms |
22476 KB |
Output is correct |
6 |
Correct |
254 ms |
22604 KB |
Output is correct |
7 |
Correct |
379 ms |
22584 KB |
Output is correct |
8 |
Correct |
364 ms |
22504 KB |
Output is correct |
9 |
Correct |
354 ms |
22656 KB |
Output is correct |
10 |
Incorrect |
193 ms |
22276 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
5 ms |
9592 KB |
Output is correct |
7 |
Correct |
52 ms |
9684 KB |
Output is correct |
8 |
Correct |
51 ms |
9720 KB |
Output is correct |
9 |
Correct |
52 ms |
9704 KB |
Output is correct |
10 |
Correct |
53 ms |
9724 KB |
Output is correct |
11 |
Correct |
51 ms |
9708 KB |
Output is correct |
12 |
Correct |
51 ms |
9716 KB |
Output is correct |
13 |
Correct |
52 ms |
9804 KB |
Output is correct |
14 |
Correct |
52 ms |
9712 KB |
Output is correct |
15 |
Correct |
52 ms |
9604 KB |
Output is correct |
16 |
Correct |
29 ms |
9720 KB |
Output is correct |
17 |
Correct |
39 ms |
9684 KB |
Output is correct |
18 |
Correct |
17 ms |
9720 KB |
Output is correct |
19 |
Correct |
398 ms |
22524 KB |
Output is correct |
20 |
Correct |
406 ms |
22484 KB |
Output is correct |
21 |
Correct |
399 ms |
22500 KB |
Output is correct |
22 |
Correct |
371 ms |
22500 KB |
Output is correct |
23 |
Correct |
297 ms |
22476 KB |
Output is correct |
24 |
Correct |
254 ms |
22604 KB |
Output is correct |
25 |
Correct |
379 ms |
22584 KB |
Output is correct |
26 |
Correct |
364 ms |
22504 KB |
Output is correct |
27 |
Correct |
354 ms |
22656 KB |
Output is correct |
28 |
Incorrect |
193 ms |
22276 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |