#include <bits/stdc++.h>
//#include "secret.h"
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
int maxsz = 400005;
struct query {
int a;
int b;
int sum;
int ind;
};
struct BIT{
int n;
vi bit;
BIT(int n_now){
n = n_now;
bit = vi(n_now+1);
}
void add(int x, int delta){
for(; x <= n; x += x & -x)
bit[x] += delta;
}
int get(int x){
int sum = 0;
for(; x > 0; x -= x & -x)
sum += bit[x];
return sum;
}
int get(int l, int r){
return get(r) - get(l-1);
}
};
bool cmp(query a, query b){
if(a.sum != b.sum)
return a.sum > b.sum;
return a.ind < b.ind;
}
void solve(){
int n, q;
cin >> n >> q;
vector<query> queries;
vi ans(q);
vi vals;
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
vals.pb(a);
vals.pb(b);
queries.pb({a, b, a+b, -1});
}
for(int i = 0; i < q; i++){
int a, b, c;
cin >> a >> b >> c;
vals.pb(a);
vals.pb(b);
queries.pb({a, b, max(a+b, c), i});
}
sort(vals.begin(), vals.end());
auto compress = [&](int a){
return lower_bound(vals.begin(), vals.end(), a) - vals.begin() + 1;
};
int people = 0;
BIT a(maxsz), b(maxsz);
sort(queries.begin(), queries.end(), cmp);
for(auto x : queries){
if(x.ind == -1){
a.add(compress(x.a), 1);
b.add(compress(x.b), 1);
people++;
} else {
ans[x.ind] = a.get(compress(x.a), maxsz) + b.get(compress(x.b), maxsz) - people;
}
}
for(int i = 0; i < q; i++)
cout << ans[i] << '\n';
}
int main(){
//freopen("input.txt", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3396 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3392 KB |
Output is correct |
7 |
Correct |
7 ms |
3916 KB |
Output is correct |
8 |
Correct |
9 ms |
3924 KB |
Output is correct |
9 |
Correct |
7 ms |
3924 KB |
Output is correct |
10 |
Correct |
5 ms |
3800 KB |
Output is correct |
11 |
Correct |
5 ms |
3796 KB |
Output is correct |
12 |
Correct |
4 ms |
3796 KB |
Output is correct |
13 |
Correct |
6 ms |
3792 KB |
Output is correct |
14 |
Correct |
6 ms |
3796 KB |
Output is correct |
15 |
Correct |
6 ms |
3796 KB |
Output is correct |
16 |
Correct |
4 ms |
3808 KB |
Output is correct |
17 |
Correct |
5 ms |
3796 KB |
Output is correct |
18 |
Correct |
6 ms |
3796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
176 ms |
11592 KB |
Output is correct |
2 |
Correct |
160 ms |
11576 KB |
Output is correct |
3 |
Correct |
175 ms |
11556 KB |
Output is correct |
4 |
Correct |
109 ms |
10904 KB |
Output is correct |
5 |
Correct |
112 ms |
10820 KB |
Output is correct |
6 |
Correct |
81 ms |
10080 KB |
Output is correct |
7 |
Correct |
171 ms |
11456 KB |
Output is correct |
8 |
Correct |
156 ms |
11484 KB |
Output is correct |
9 |
Correct |
157 ms |
11420 KB |
Output is correct |
10 |
Correct |
102 ms |
10668 KB |
Output is correct |
11 |
Correct |
103 ms |
10792 KB |
Output is correct |
12 |
Correct |
81 ms |
9716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
176 ms |
11592 KB |
Output is correct |
2 |
Correct |
160 ms |
11576 KB |
Output is correct |
3 |
Correct |
175 ms |
11556 KB |
Output is correct |
4 |
Correct |
109 ms |
10904 KB |
Output is correct |
5 |
Correct |
112 ms |
10820 KB |
Output is correct |
6 |
Correct |
81 ms |
10080 KB |
Output is correct |
7 |
Correct |
171 ms |
11456 KB |
Output is correct |
8 |
Correct |
156 ms |
11484 KB |
Output is correct |
9 |
Correct |
157 ms |
11420 KB |
Output is correct |
10 |
Correct |
102 ms |
10668 KB |
Output is correct |
11 |
Correct |
103 ms |
10792 KB |
Output is correct |
12 |
Correct |
81 ms |
9716 KB |
Output is correct |
13 |
Correct |
167 ms |
12020 KB |
Output is correct |
14 |
Correct |
178 ms |
11968 KB |
Output is correct |
15 |
Correct |
176 ms |
11488 KB |
Output is correct |
16 |
Correct |
116 ms |
11164 KB |
Output is correct |
17 |
Correct |
120 ms |
11224 KB |
Output is correct |
18 |
Correct |
92 ms |
10080 KB |
Output is correct |
19 |
Correct |
172 ms |
11932 KB |
Output is correct |
20 |
Correct |
161 ms |
11992 KB |
Output is correct |
21 |
Correct |
204 ms |
11944 KB |
Output is correct |
22 |
Correct |
114 ms |
10696 KB |
Output is correct |
23 |
Correct |
106 ms |
10664 KB |
Output is correct |
24 |
Correct |
128 ms |
9672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3396 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3392 KB |
Output is correct |
7 |
Correct |
7 ms |
3916 KB |
Output is correct |
8 |
Correct |
9 ms |
3924 KB |
Output is correct |
9 |
Correct |
7 ms |
3924 KB |
Output is correct |
10 |
Correct |
5 ms |
3800 KB |
Output is correct |
11 |
Correct |
5 ms |
3796 KB |
Output is correct |
12 |
Correct |
4 ms |
3796 KB |
Output is correct |
13 |
Correct |
6 ms |
3792 KB |
Output is correct |
14 |
Correct |
6 ms |
3796 KB |
Output is correct |
15 |
Correct |
6 ms |
3796 KB |
Output is correct |
16 |
Correct |
4 ms |
3808 KB |
Output is correct |
17 |
Correct |
5 ms |
3796 KB |
Output is correct |
18 |
Correct |
6 ms |
3796 KB |
Output is correct |
19 |
Correct |
176 ms |
11592 KB |
Output is correct |
20 |
Correct |
160 ms |
11576 KB |
Output is correct |
21 |
Correct |
175 ms |
11556 KB |
Output is correct |
22 |
Correct |
109 ms |
10904 KB |
Output is correct |
23 |
Correct |
112 ms |
10820 KB |
Output is correct |
24 |
Correct |
81 ms |
10080 KB |
Output is correct |
25 |
Correct |
171 ms |
11456 KB |
Output is correct |
26 |
Correct |
156 ms |
11484 KB |
Output is correct |
27 |
Correct |
157 ms |
11420 KB |
Output is correct |
28 |
Correct |
102 ms |
10668 KB |
Output is correct |
29 |
Correct |
103 ms |
10792 KB |
Output is correct |
30 |
Correct |
81 ms |
9716 KB |
Output is correct |
31 |
Correct |
167 ms |
12020 KB |
Output is correct |
32 |
Correct |
178 ms |
11968 KB |
Output is correct |
33 |
Correct |
176 ms |
11488 KB |
Output is correct |
34 |
Correct |
116 ms |
11164 KB |
Output is correct |
35 |
Correct |
120 ms |
11224 KB |
Output is correct |
36 |
Correct |
92 ms |
10080 KB |
Output is correct |
37 |
Correct |
172 ms |
11932 KB |
Output is correct |
38 |
Correct |
161 ms |
11992 KB |
Output is correct |
39 |
Correct |
204 ms |
11944 KB |
Output is correct |
40 |
Correct |
114 ms |
10696 KB |
Output is correct |
41 |
Correct |
106 ms |
10664 KB |
Output is correct |
42 |
Correct |
128 ms |
9672 KB |
Output is correct |
43 |
Correct |
214 ms |
13892 KB |
Output is correct |
44 |
Correct |
227 ms |
14028 KB |
Output is correct |
45 |
Correct |
182 ms |
13888 KB |
Output is correct |
46 |
Correct |
133 ms |
12368 KB |
Output is correct |
47 |
Correct |
172 ms |
12368 KB |
Output is correct |
48 |
Correct |
85 ms |
9892 KB |
Output is correct |
49 |
Correct |
183 ms |
13792 KB |
Output is correct |
50 |
Correct |
201 ms |
13856 KB |
Output is correct |
51 |
Correct |
189 ms |
13700 KB |
Output is correct |
52 |
Correct |
116 ms |
12224 KB |
Output is correct |
53 |
Correct |
149 ms |
11464 KB |
Output is correct |