#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 1e5;
int bit[MAX + 1];
void update(int pos, int val){
for(int i = pos; i <= MAX; i = i | (i + 1)){
bit[i] += val;
}
}
int ask(int pos){
int res = 0;
for(int i = pos; i >= 0; i = (i & (i + 1)) - 1){
res += bit[i];
}
return res;
}
int ask(int l, int r){
if(l == 0) return ask(r);
return ask(r) - ask(l - 1);
}
struct query{
int x, y, idx;
bool operator<(query other){
return x < other.x;
}
};
int n, m;
void solve2(){
vector<pair<int, int>> p;
for(int i = 0; i < n; i++){
int x, y;
cin>>x>>y;
p.push_back({x, y});
}
sort(p.begin(), p.end());
vector<query> queries;
for(int i = 0; i < m; i++){
int x, y, z;
cin>>x>>y>>z;
queries.push_back({x, y, i});
}
sort(queries.begin(), queries.end());
int ans[m];
int idx = n - 1;
for (int i = m - 1; i >= 0; i--)
{
while(idx >= 0 && queries[i].x <= p[idx].first){
update(p[idx].second, 1);
idx--;
}
ans[queries[i].idx] = ask(queries[i].y, MAX);
}
for (int i = 0; i < m; i++) cout<<ans[i]<<endl;
}
void solve1(){
vector<pair<int, int>> p;
for(int i = 0; i < n; i++){
int x, y;
cin>>x>>y;
p.push_back({x, y});
}
for(int i = 0; i < m; i++){
int x, y, z;
cin>>x>>y>>z;
int cnt = 0;
for(int i = 0; i < n; i++){
if(p[i].first >= x && p[i].second >= y && p[i].first + p[i].second >= z) cnt++;
}
cout<<cnt<<endl;
}
}
int main(){
cin>>n>>m;
if(n <= 3000 && m <= 3000) solve1();
else solve2();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
48 ms |
364 KB |
Output is correct |
8 |
Correct |
47 ms |
372 KB |
Output is correct |
9 |
Correct |
60 ms |
340 KB |
Output is correct |
10 |
Correct |
47 ms |
340 KB |
Output is correct |
11 |
Correct |
48 ms |
372 KB |
Output is correct |
12 |
Correct |
47 ms |
364 KB |
Output is correct |
13 |
Correct |
51 ms |
476 KB |
Output is correct |
14 |
Correct |
49 ms |
368 KB |
Output is correct |
15 |
Correct |
51 ms |
368 KB |
Output is correct |
16 |
Correct |
25 ms |
368 KB |
Output is correct |
17 |
Correct |
37 ms |
360 KB |
Output is correct |
18 |
Correct |
13 ms |
372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
256 ms |
4320 KB |
Output is correct |
2 |
Correct |
265 ms |
4284 KB |
Output is correct |
3 |
Correct |
247 ms |
4332 KB |
Output is correct |
4 |
Correct |
233 ms |
3924 KB |
Output is correct |
5 |
Correct |
219 ms |
4252 KB |
Output is correct |
6 |
Correct |
198 ms |
3924 KB |
Output is correct |
7 |
Correct |
244 ms |
4352 KB |
Output is correct |
8 |
Correct |
249 ms |
4296 KB |
Output is correct |
9 |
Correct |
241 ms |
4384 KB |
Output is correct |
10 |
Correct |
222 ms |
4160 KB |
Output is correct |
11 |
Correct |
224 ms |
3836 KB |
Output is correct |
12 |
Correct |
194 ms |
3676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
256 ms |
4320 KB |
Output is correct |
2 |
Correct |
265 ms |
4284 KB |
Output is correct |
3 |
Correct |
247 ms |
4332 KB |
Output is correct |
4 |
Correct |
233 ms |
3924 KB |
Output is correct |
5 |
Correct |
219 ms |
4252 KB |
Output is correct |
6 |
Correct |
198 ms |
3924 KB |
Output is correct |
7 |
Correct |
244 ms |
4352 KB |
Output is correct |
8 |
Correct |
249 ms |
4296 KB |
Output is correct |
9 |
Correct |
241 ms |
4384 KB |
Output is correct |
10 |
Correct |
222 ms |
4160 KB |
Output is correct |
11 |
Correct |
224 ms |
3836 KB |
Output is correct |
12 |
Correct |
194 ms |
3676 KB |
Output is correct |
13 |
Incorrect |
269 ms |
4372 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
48 ms |
364 KB |
Output is correct |
8 |
Correct |
47 ms |
372 KB |
Output is correct |
9 |
Correct |
60 ms |
340 KB |
Output is correct |
10 |
Correct |
47 ms |
340 KB |
Output is correct |
11 |
Correct |
48 ms |
372 KB |
Output is correct |
12 |
Correct |
47 ms |
364 KB |
Output is correct |
13 |
Correct |
51 ms |
476 KB |
Output is correct |
14 |
Correct |
49 ms |
368 KB |
Output is correct |
15 |
Correct |
51 ms |
368 KB |
Output is correct |
16 |
Correct |
25 ms |
368 KB |
Output is correct |
17 |
Correct |
37 ms |
360 KB |
Output is correct |
18 |
Correct |
13 ms |
372 KB |
Output is correct |
19 |
Correct |
256 ms |
4320 KB |
Output is correct |
20 |
Correct |
265 ms |
4284 KB |
Output is correct |
21 |
Correct |
247 ms |
4332 KB |
Output is correct |
22 |
Correct |
233 ms |
3924 KB |
Output is correct |
23 |
Correct |
219 ms |
4252 KB |
Output is correct |
24 |
Correct |
198 ms |
3924 KB |
Output is correct |
25 |
Correct |
244 ms |
4352 KB |
Output is correct |
26 |
Correct |
249 ms |
4296 KB |
Output is correct |
27 |
Correct |
241 ms |
4384 KB |
Output is correct |
28 |
Correct |
222 ms |
4160 KB |
Output is correct |
29 |
Correct |
224 ms |
3836 KB |
Output is correct |
30 |
Correct |
194 ms |
3676 KB |
Output is correct |
31 |
Incorrect |
269 ms |
4372 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |