#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 query(int pos){
int res = 0;
for(int i = pos; i >= 0; i = (i & (i + 1)) - 1){
res += bit[i];
}
return res;
}
int query(int l, int r){
if(l == 0) return query(r);
return query(r) - query(l - 1);
}
struct event{
int x, y, idx, type;
};
bool f(event a, event b){
if(a.x == b.x) a.type < b.type;
return a.x < b.x;
}
int n, m;
void solve2(){
vector<event> events;
for(int i = 0; i < n; i++){
int x, y;
cin>>x>>y;
events.push_back({x, y, -1, 0});
}
for(int i = 0; i < m; i++){
int x, y, z;
cin>>x>>y>>z;
events.push_back({x, y, i, 1});
}
sort(events.begin(), events.end(), f);
int ans[m];
for (int i = m - 1; i >= 0; i--)
{
if(events[i].type == 0){
update(events[i].y, 1);
}else{
ans[events[i].idx] = query(events[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();
}
Compilation message
examination.cpp: In function 'bool f(event, event)':
examination.cpp:26:27: warning: statement has no effect [-Wunused-value]
26 | if(a.x == b.x) a.type < b.type;
| ~~~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
49 ms |
372 KB |
Output is correct |
8 |
Correct |
48 ms |
472 KB |
Output is correct |
9 |
Correct |
50 ms |
340 KB |
Output is correct |
10 |
Correct |
46 ms |
372 KB |
Output is correct |
11 |
Correct |
46 ms |
372 KB |
Output is correct |
12 |
Correct |
49 ms |
364 KB |
Output is correct |
13 |
Correct |
50 ms |
368 KB |
Output is correct |
14 |
Correct |
51 ms |
356 KB |
Output is correct |
15 |
Correct |
49 ms |
368 KB |
Output is correct |
16 |
Correct |
25 ms |
368 KB |
Output is correct |
17 |
Correct |
36 ms |
368 KB |
Output is correct |
18 |
Correct |
15 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
275 ms |
4656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
275 ms |
4656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
49 ms |
372 KB |
Output is correct |
8 |
Correct |
48 ms |
472 KB |
Output is correct |
9 |
Correct |
50 ms |
340 KB |
Output is correct |
10 |
Correct |
46 ms |
372 KB |
Output is correct |
11 |
Correct |
46 ms |
372 KB |
Output is correct |
12 |
Correct |
49 ms |
364 KB |
Output is correct |
13 |
Correct |
50 ms |
368 KB |
Output is correct |
14 |
Correct |
51 ms |
356 KB |
Output is correct |
15 |
Correct |
49 ms |
368 KB |
Output is correct |
16 |
Correct |
25 ms |
368 KB |
Output is correct |
17 |
Correct |
36 ms |
368 KB |
Output is correct |
18 |
Correct |
15 ms |
360 KB |
Output is correct |
19 |
Incorrect |
275 ms |
4656 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |