#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Общий файл.
#include <ext/pb_ds/tree_policy.hpp> // Содержит класс tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define long unsigned long
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define PI 2*acos(0.0)
void solve(int test) {
int n, q;
cin >> n >> q;
vector <int> a(n), b(n);
vector <pair <pii, pii>> queries(q);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < q; i++) {
auto &to = queries[i];
cin >> to.first.first >> to.first.second >> to.second.first;
to.second.second = i;
}
if (n <= 3000 && q <= 3000) {
for (auto to : queries) {
auto x = to.first.first, y = to.first.second, z = to.second.first;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] >= x && b[i] >= y && a[i] + b[i] >= z) {
cnt++;
}
}
cout << cnt << endl;
}
}
else {
vector <int> inds(n);
iota(all(inds), 0);
sort(all(inds), [&](int i, int j) {
return a[i] < a[j];
});
int i = n - 1;
ordered_set st;
sort(rall(queries));
vector <int> ans(q);
for (auto to : queries) {
auto x = to.first.first, y = to.first.second, z = to.second.first;
auto ind = to.second.second;
while (i >= 0 && a[inds[i]] >= x) {
st.insert(b[inds[i--]]);
}
ans[ind] = sz(st) - st.order_of_key(y);
}
for (auto to : ans) cout << to << endl;
}
}
int main() {
do_not_disturb
int t = 1;
//~ cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
}
return 0;
}
Compilation message
examination.cpp: In function 'void solve(int)':
examination.cpp:61:59: warning: unused variable 'z' [-Wunused-variable]
61 | auto x = to.first.first, y = to.first.second, z = to.second.first;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
51 ms |
536 KB |
Output is correct |
8 |
Correct |
45 ms |
520 KB |
Output is correct |
9 |
Correct |
45 ms |
536 KB |
Output is correct |
10 |
Correct |
47 ms |
488 KB |
Output is correct |
11 |
Correct |
47 ms |
484 KB |
Output is correct |
12 |
Correct |
51 ms |
428 KB |
Output is correct |
13 |
Correct |
42 ms |
468 KB |
Output is correct |
14 |
Correct |
54 ms |
516 KB |
Output is correct |
15 |
Correct |
48 ms |
508 KB |
Output is correct |
16 |
Correct |
21 ms |
468 KB |
Output is correct |
17 |
Correct |
35 ms |
492 KB |
Output is correct |
18 |
Correct |
9 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
11096 KB |
Output is correct |
2 |
Correct |
162 ms |
11188 KB |
Output is correct |
3 |
Correct |
193 ms |
11092 KB |
Output is correct |
4 |
Correct |
154 ms |
10452 KB |
Output is correct |
5 |
Correct |
127 ms |
10464 KB |
Output is correct |
6 |
Correct |
107 ms |
9684 KB |
Output is correct |
7 |
Correct |
187 ms |
11096 KB |
Output is correct |
8 |
Correct |
154 ms |
11044 KB |
Output is correct |
9 |
Correct |
145 ms |
10972 KB |
Output is correct |
10 |
Correct |
111 ms |
10252 KB |
Output is correct |
11 |
Correct |
124 ms |
10232 KB |
Output is correct |
12 |
Correct |
99 ms |
9268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
11096 KB |
Output is correct |
2 |
Correct |
162 ms |
11188 KB |
Output is correct |
3 |
Correct |
193 ms |
11092 KB |
Output is correct |
4 |
Correct |
154 ms |
10452 KB |
Output is correct |
5 |
Correct |
127 ms |
10464 KB |
Output is correct |
6 |
Correct |
107 ms |
9684 KB |
Output is correct |
7 |
Correct |
187 ms |
11096 KB |
Output is correct |
8 |
Correct |
154 ms |
11044 KB |
Output is correct |
9 |
Correct |
145 ms |
10972 KB |
Output is correct |
10 |
Correct |
111 ms |
10252 KB |
Output is correct |
11 |
Correct |
124 ms |
10232 KB |
Output is correct |
12 |
Correct |
99 ms |
9268 KB |
Output is correct |
13 |
Incorrect |
158 ms |
11616 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
51 ms |
536 KB |
Output is correct |
8 |
Correct |
45 ms |
520 KB |
Output is correct |
9 |
Correct |
45 ms |
536 KB |
Output is correct |
10 |
Correct |
47 ms |
488 KB |
Output is correct |
11 |
Correct |
47 ms |
484 KB |
Output is correct |
12 |
Correct |
51 ms |
428 KB |
Output is correct |
13 |
Correct |
42 ms |
468 KB |
Output is correct |
14 |
Correct |
54 ms |
516 KB |
Output is correct |
15 |
Correct |
48 ms |
508 KB |
Output is correct |
16 |
Correct |
21 ms |
468 KB |
Output is correct |
17 |
Correct |
35 ms |
492 KB |
Output is correct |
18 |
Correct |
9 ms |
336 KB |
Output is correct |
19 |
Correct |
169 ms |
11096 KB |
Output is correct |
20 |
Correct |
162 ms |
11188 KB |
Output is correct |
21 |
Correct |
193 ms |
11092 KB |
Output is correct |
22 |
Correct |
154 ms |
10452 KB |
Output is correct |
23 |
Correct |
127 ms |
10464 KB |
Output is correct |
24 |
Correct |
107 ms |
9684 KB |
Output is correct |
25 |
Correct |
187 ms |
11096 KB |
Output is correct |
26 |
Correct |
154 ms |
11044 KB |
Output is correct |
27 |
Correct |
145 ms |
10972 KB |
Output is correct |
28 |
Correct |
111 ms |
10252 KB |
Output is correct |
29 |
Correct |
124 ms |
10232 KB |
Output is correct |
30 |
Correct |
99 ms |
9268 KB |
Output is correct |
31 |
Incorrect |
158 ms |
11616 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |