#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX = 5e5;
struct fenwick_tree{
int bit[MAX + 1] = {0};
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, z, idx, type;
bool operator<(event other){
if(z == other.z) return type < other.type;
return z > other.z;
}
};
int n, m;
void solve(){
vector<event> events;
map<int, int> mm;
for(int i = 0; i < n; i++){
int x, y;
cin>>x>>y;
mm[x]; mm[y];
events.push_back({x, y, x + y, -1, 0});
}
for(int i = 0; i < m; i++){
int x, y, z;
cin>>x>>y>>z;
mm[x]; mm[y];
events.push_back({x, y, max(x + y, z), i, 1});
}
int idx = 0;
for(auto& i : mm) i.second = idx++;
sort(events.begin(), events.end());
int ans[m];
fenwick_tree X, Y;
int cnt = 0;
for (auto i : events)
{
if(i.type == 0){
Y.update(mm[i.y], 1);
X.update(mm[i.x], 1);
cnt++;
}else{
ans[i.idx] = Y.query(mm[i.y], MAX) + X.query(mm[i.x], MAX) - cnt;
}
}
for (int i = 0; i < m; i++) cout<<ans[i]<<endl;
}
signed main(){
cin>>n>>m;
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8020 KB |
Output is correct |
2 |
Correct |
4 ms |
8020 KB |
Output is correct |
3 |
Correct |
4 ms |
8020 KB |
Output is correct |
4 |
Correct |
4 ms |
8020 KB |
Output is correct |
5 |
Correct |
4 ms |
8020 KB |
Output is correct |
6 |
Correct |
4 ms |
8020 KB |
Output is correct |
7 |
Correct |
19 ms |
9132 KB |
Output is correct |
8 |
Correct |
20 ms |
9068 KB |
Output is correct |
9 |
Correct |
19 ms |
9136 KB |
Output is correct |
10 |
Correct |
15 ms |
8752 KB |
Output is correct |
11 |
Correct |
15 ms |
8752 KB |
Output is correct |
12 |
Correct |
11 ms |
8500 KB |
Output is correct |
13 |
Correct |
20 ms |
9136 KB |
Output is correct |
14 |
Correct |
18 ms |
9148 KB |
Output is correct |
15 |
Correct |
22 ms |
9148 KB |
Output is correct |
16 |
Correct |
13 ms |
8776 KB |
Output is correct |
17 |
Correct |
14 ms |
8756 KB |
Output is correct |
18 |
Correct |
12 ms |
8500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
520 ms |
24100 KB |
Output is correct |
2 |
Correct |
513 ms |
24164 KB |
Output is correct |
3 |
Correct |
496 ms |
24164 KB |
Output is correct |
4 |
Correct |
351 ms |
22944 KB |
Output is correct |
5 |
Correct |
368 ms |
22860 KB |
Output is correct |
6 |
Correct |
223 ms |
18500 KB |
Output is correct |
7 |
Correct |
610 ms |
24032 KB |
Output is correct |
8 |
Correct |
597 ms |
23988 KB |
Output is correct |
9 |
Correct |
519 ms |
23800 KB |
Output is correct |
10 |
Correct |
337 ms |
22960 KB |
Output is correct |
11 |
Correct |
355 ms |
22932 KB |
Output is correct |
12 |
Correct |
217 ms |
18484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
520 ms |
24100 KB |
Output is correct |
2 |
Correct |
513 ms |
24164 KB |
Output is correct |
3 |
Correct |
496 ms |
24164 KB |
Output is correct |
4 |
Correct |
351 ms |
22944 KB |
Output is correct |
5 |
Correct |
368 ms |
22860 KB |
Output is correct |
6 |
Correct |
223 ms |
18500 KB |
Output is correct |
7 |
Correct |
610 ms |
24032 KB |
Output is correct |
8 |
Correct |
597 ms |
23988 KB |
Output is correct |
9 |
Correct |
519 ms |
23800 KB |
Output is correct |
10 |
Correct |
337 ms |
22960 KB |
Output is correct |
11 |
Correct |
355 ms |
22932 KB |
Output is correct |
12 |
Correct |
217 ms |
18484 KB |
Output is correct |
13 |
Correct |
593 ms |
24136 KB |
Output is correct |
14 |
Correct |
492 ms |
24072 KB |
Output is correct |
15 |
Correct |
588 ms |
24084 KB |
Output is correct |
16 |
Correct |
373 ms |
22948 KB |
Output is correct |
17 |
Correct |
402 ms |
22912 KB |
Output is correct |
18 |
Correct |
218 ms |
18488 KB |
Output is correct |
19 |
Correct |
576 ms |
24152 KB |
Output is correct |
20 |
Correct |
510 ms |
24168 KB |
Output is correct |
21 |
Correct |
516 ms |
24020 KB |
Output is correct |
22 |
Correct |
362 ms |
22836 KB |
Output is correct |
23 |
Correct |
360 ms |
22876 KB |
Output is correct |
24 |
Correct |
214 ms |
18488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8020 KB |
Output is correct |
2 |
Correct |
4 ms |
8020 KB |
Output is correct |
3 |
Correct |
4 ms |
8020 KB |
Output is correct |
4 |
Correct |
4 ms |
8020 KB |
Output is correct |
5 |
Correct |
4 ms |
8020 KB |
Output is correct |
6 |
Correct |
4 ms |
8020 KB |
Output is correct |
7 |
Correct |
19 ms |
9132 KB |
Output is correct |
8 |
Correct |
20 ms |
9068 KB |
Output is correct |
9 |
Correct |
19 ms |
9136 KB |
Output is correct |
10 |
Correct |
15 ms |
8752 KB |
Output is correct |
11 |
Correct |
15 ms |
8752 KB |
Output is correct |
12 |
Correct |
11 ms |
8500 KB |
Output is correct |
13 |
Correct |
20 ms |
9136 KB |
Output is correct |
14 |
Correct |
18 ms |
9148 KB |
Output is correct |
15 |
Correct |
22 ms |
9148 KB |
Output is correct |
16 |
Correct |
13 ms |
8776 KB |
Output is correct |
17 |
Correct |
14 ms |
8756 KB |
Output is correct |
18 |
Correct |
12 ms |
8500 KB |
Output is correct |
19 |
Correct |
520 ms |
24100 KB |
Output is correct |
20 |
Correct |
513 ms |
24164 KB |
Output is correct |
21 |
Correct |
496 ms |
24164 KB |
Output is correct |
22 |
Correct |
351 ms |
22944 KB |
Output is correct |
23 |
Correct |
368 ms |
22860 KB |
Output is correct |
24 |
Correct |
223 ms |
18500 KB |
Output is correct |
25 |
Correct |
610 ms |
24032 KB |
Output is correct |
26 |
Correct |
597 ms |
23988 KB |
Output is correct |
27 |
Correct |
519 ms |
23800 KB |
Output is correct |
28 |
Correct |
337 ms |
22960 KB |
Output is correct |
29 |
Correct |
355 ms |
22932 KB |
Output is correct |
30 |
Correct |
217 ms |
18484 KB |
Output is correct |
31 |
Correct |
593 ms |
24136 KB |
Output is correct |
32 |
Correct |
492 ms |
24072 KB |
Output is correct |
33 |
Correct |
588 ms |
24084 KB |
Output is correct |
34 |
Correct |
373 ms |
22948 KB |
Output is correct |
35 |
Correct |
402 ms |
22912 KB |
Output is correct |
36 |
Correct |
218 ms |
18488 KB |
Output is correct |
37 |
Correct |
576 ms |
24152 KB |
Output is correct |
38 |
Correct |
510 ms |
24168 KB |
Output is correct |
39 |
Correct |
516 ms |
24020 KB |
Output is correct |
40 |
Correct |
362 ms |
22836 KB |
Output is correct |
41 |
Correct |
360 ms |
22876 KB |
Output is correct |
42 |
Correct |
214 ms |
18488 KB |
Output is correct |
43 |
Correct |
1004 ms |
42292 KB |
Output is correct |
44 |
Correct |
1018 ms |
47364 KB |
Output is correct |
45 |
Correct |
963 ms |
47196 KB |
Output is correct |
46 |
Correct |
533 ms |
33072 KB |
Output is correct |
47 |
Correct |
522 ms |
33140 KB |
Output is correct |
48 |
Correct |
243 ms |
19280 KB |
Output is correct |
49 |
Correct |
942 ms |
47144 KB |
Output is correct |
50 |
Correct |
970 ms |
47068 KB |
Output is correct |
51 |
Correct |
924 ms |
46932 KB |
Output is correct |
52 |
Correct |
516 ms |
33040 KB |
Output is correct |
53 |
Correct |
489 ms |
32164 KB |
Output is correct |