#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 1e6 + 1;
typedef tree<int,
null_type,
less_equal<int>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
int n, q;
tuple<int, int, int, int> t[maxn];
int out[100000];
void ope(int l, int r){
if(l + 1 == r)return;
int mid = l + (r - l) / 2;
ope(l, mid), ope(mid, r);
vt<tuple<int, int, int, int>> ch;
ordered_set os;
int j = mid - 1, o = r - 1;
while(j >= l && o >= mid){
if(get<3>(t[j]) == inf)j--;
else if(get<3>(t[o]) != inf)o--;
else {
if(get<1>(t[j]) <= get<1>(t[o])){
os.insert(get<2>(t[o]));
o--;
}
else {
int x = os.size() - os.order_of_key(get<2>(t[j]));
out[get<3>(t[j]) - 1] += x;
j--;
}
}
}
while(j >= l){
if(get<3>(t[j]) != inf){
int x = os.size() - os.order_of_key(get<2>(t[j]));
out[get<3>(t[j]) - 1] += x;
}
j--;
}
j = l, o = mid;
while(j < mid || o < r){
if(o == r || (j < mid && get<1>(t[j]) <= get<1>(t[o])))ch.pb(t[j++]);
else ch.pb(t[o++]);
}
for(int i = l; i < r; i++){
t[i] = ch[i - l];
}
}
void solve() {
cin >> n >> q;
for(int i = 0, a, b; i < n; i++){
cin >> a >> b;
t[i] = make_tuple(a, b, a + b, inf);
}
for(int i = 0, a, b, c; i < q; i++){
cin >> a >> b >> c;
t[i + n] = make_tuple(a, b, c, i + 1);
}
sort(t, t + n + q);
ope(0, n + q);
for(int i = 0; i < q; i++)cout << out[i] << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
6 ms |
2780 KB |
Output is correct |
8 |
Correct |
6 ms |
2888 KB |
Output is correct |
9 |
Correct |
6 ms |
2892 KB |
Output is correct |
10 |
Correct |
6 ms |
2884 KB |
Output is correct |
11 |
Correct |
5 ms |
2888 KB |
Output is correct |
12 |
Correct |
5 ms |
2764 KB |
Output is correct |
13 |
Correct |
6 ms |
2884 KB |
Output is correct |
14 |
Correct |
6 ms |
2888 KB |
Output is correct |
15 |
Correct |
6 ms |
2780 KB |
Output is correct |
16 |
Correct |
5 ms |
2788 KB |
Output is correct |
17 |
Correct |
5 ms |
2884 KB |
Output is correct |
18 |
Correct |
3 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
232 ms |
14628 KB |
Output is correct |
2 |
Correct |
269 ms |
17360 KB |
Output is correct |
3 |
Correct |
238 ms |
16628 KB |
Output is correct |
4 |
Correct |
236 ms |
16448 KB |
Output is correct |
5 |
Correct |
200 ms |
16588 KB |
Output is correct |
6 |
Correct |
171 ms |
15660 KB |
Output is correct |
7 |
Correct |
172 ms |
19156 KB |
Output is correct |
8 |
Correct |
222 ms |
16460 KB |
Output is correct |
9 |
Correct |
167 ms |
17644 KB |
Output is correct |
10 |
Correct |
188 ms |
14424 KB |
Output is correct |
11 |
Correct |
194 ms |
14832 KB |
Output is correct |
12 |
Correct |
109 ms |
14784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
232 ms |
14628 KB |
Output is correct |
2 |
Correct |
269 ms |
17360 KB |
Output is correct |
3 |
Correct |
238 ms |
16628 KB |
Output is correct |
4 |
Correct |
236 ms |
16448 KB |
Output is correct |
5 |
Correct |
200 ms |
16588 KB |
Output is correct |
6 |
Correct |
171 ms |
15660 KB |
Output is correct |
7 |
Correct |
172 ms |
19156 KB |
Output is correct |
8 |
Correct |
222 ms |
16460 KB |
Output is correct |
9 |
Correct |
167 ms |
17644 KB |
Output is correct |
10 |
Correct |
188 ms |
14424 KB |
Output is correct |
11 |
Correct |
194 ms |
14832 KB |
Output is correct |
12 |
Correct |
109 ms |
14784 KB |
Output is correct |
13 |
Correct |
255 ms |
17116 KB |
Output is correct |
14 |
Correct |
241 ms |
16868 KB |
Output is correct |
15 |
Correct |
247 ms |
16132 KB |
Output is correct |
16 |
Correct |
240 ms |
15740 KB |
Output is correct |
17 |
Correct |
215 ms |
16056 KB |
Output is correct |
18 |
Correct |
189 ms |
14608 KB |
Output is correct |
19 |
Correct |
250 ms |
17116 KB |
Output is correct |
20 |
Correct |
271 ms |
17548 KB |
Output is correct |
21 |
Correct |
220 ms |
17492 KB |
Output is correct |
22 |
Correct |
210 ms |
14924 KB |
Output is correct |
23 |
Correct |
192 ms |
16364 KB |
Output is correct |
24 |
Correct |
102 ms |
14040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
6 ms |
2780 KB |
Output is correct |
8 |
Correct |
6 ms |
2888 KB |
Output is correct |
9 |
Correct |
6 ms |
2892 KB |
Output is correct |
10 |
Correct |
6 ms |
2884 KB |
Output is correct |
11 |
Correct |
5 ms |
2888 KB |
Output is correct |
12 |
Correct |
5 ms |
2764 KB |
Output is correct |
13 |
Correct |
6 ms |
2884 KB |
Output is correct |
14 |
Correct |
6 ms |
2888 KB |
Output is correct |
15 |
Correct |
6 ms |
2780 KB |
Output is correct |
16 |
Correct |
5 ms |
2788 KB |
Output is correct |
17 |
Correct |
5 ms |
2884 KB |
Output is correct |
18 |
Correct |
3 ms |
2652 KB |
Output is correct |
19 |
Correct |
232 ms |
14628 KB |
Output is correct |
20 |
Correct |
269 ms |
17360 KB |
Output is correct |
21 |
Correct |
238 ms |
16628 KB |
Output is correct |
22 |
Correct |
236 ms |
16448 KB |
Output is correct |
23 |
Correct |
200 ms |
16588 KB |
Output is correct |
24 |
Correct |
171 ms |
15660 KB |
Output is correct |
25 |
Correct |
172 ms |
19156 KB |
Output is correct |
26 |
Correct |
222 ms |
16460 KB |
Output is correct |
27 |
Correct |
167 ms |
17644 KB |
Output is correct |
28 |
Correct |
188 ms |
14424 KB |
Output is correct |
29 |
Correct |
194 ms |
14832 KB |
Output is correct |
30 |
Correct |
109 ms |
14784 KB |
Output is correct |
31 |
Correct |
255 ms |
17116 KB |
Output is correct |
32 |
Correct |
241 ms |
16868 KB |
Output is correct |
33 |
Correct |
247 ms |
16132 KB |
Output is correct |
34 |
Correct |
240 ms |
15740 KB |
Output is correct |
35 |
Correct |
215 ms |
16056 KB |
Output is correct |
36 |
Correct |
189 ms |
14608 KB |
Output is correct |
37 |
Correct |
250 ms |
17116 KB |
Output is correct |
38 |
Correct |
271 ms |
17548 KB |
Output is correct |
39 |
Correct |
220 ms |
17492 KB |
Output is correct |
40 |
Correct |
210 ms |
14924 KB |
Output is correct |
41 |
Correct |
192 ms |
16364 KB |
Output is correct |
42 |
Correct |
102 ms |
14040 KB |
Output is correct |
43 |
Correct |
266 ms |
17912 KB |
Output is correct |
44 |
Correct |
256 ms |
18840 KB |
Output is correct |
45 |
Correct |
247 ms |
19020 KB |
Output is correct |
46 |
Correct |
232 ms |
17700 KB |
Output is correct |
47 |
Correct |
241 ms |
18132 KB |
Output is correct |
48 |
Correct |
170 ms |
14344 KB |
Output is correct |
49 |
Correct |
212 ms |
20008 KB |
Output is correct |
50 |
Correct |
295 ms |
18384 KB |
Output is correct |
51 |
Correct |
217 ms |
20964 KB |
Output is correct |
52 |
Correct |
203 ms |
16308 KB |
Output is correct |
53 |
Correct |
201 ms |
16260 KB |
Output is correct |