#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
// #define int long long
// #define int unsigned long long
#define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>
void open_file(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
// const ll mod = 1e9 + 7;
// const ll mod = 998244353;
const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 2 * 1e5 + 25;
int tim;
struct node {
int a, b, c, id;
};
bool comp(node x, node y) {
return (x.a == y.a ? x.id > y.id : x.a < y.a);
}
node arr[maxN];
ordered_set(pii) bit[maxN];
void update(int x, int val) {
for ( ; x; x -= (x & -x)) bit[x].insert({val, ++tim});
}
int query(int x, int val) {
int ans = 0;
for ( ; x < maxN; x += (x & -x))
ans += bit[x].size() - bit[x].order_of_key({val, -1});
return ans;
}
void solve() {
int n, q;
cin >> n >> q;
int ans[q + 1];
for (int i = 1; i <= n; i++) {
cin >> arr[i].a >> arr[i].b;
arr[i].c = arr[i].a + arr[i].b; arr[i].id = 0;
} for (int i = 1; i <= q; i++) {
cin >> arr[n + i].a >> arr[n + i].b >> arr[n + i].c; arr[n + i].id = i;
} sort(arr + 1, arr + n + q + 1, comp);
vector<int> x;
for (int i = 1; i <= n + q; i++) x.pb(arr[i].b);
sort(x.begin(), x.end());
x.resize(unique(all(x)) - x.begin());
for (int i = 1; i <= n + q; i++)
arr[i].b = lower_bound(all(x), arr[i].b) - x.begin() + 1;
for (int i = n + q; i >= 1; i--) {
ans[arr[i].id] = query(arr[i].b, arr[i].c);
if (arr[i].id == 0) update(arr[i].b, arr[i].c);
} for (int i = 1; i <= q; i++) cout << ans[i] << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
Compilation message
examination.cpp: In function 'void open_file(std::string)':
examination.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen((filename + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen((filename + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
19292 KB |
Output is correct |
2 |
Correct |
8 ms |
19184 KB |
Output is correct |
3 |
Correct |
10 ms |
19124 KB |
Output is correct |
4 |
Correct |
8 ms |
19292 KB |
Output is correct |
5 |
Correct |
8 ms |
19292 KB |
Output is correct |
6 |
Correct |
10 ms |
19292 KB |
Output is correct |
7 |
Correct |
13 ms |
22620 KB |
Output is correct |
8 |
Correct |
13 ms |
22616 KB |
Output is correct |
9 |
Correct |
13 ms |
22612 KB |
Output is correct |
10 |
Correct |
13 ms |
21848 KB |
Output is correct |
11 |
Correct |
15 ms |
22616 KB |
Output is correct |
12 |
Correct |
11 ms |
21596 KB |
Output is correct |
13 |
Correct |
14 ms |
22456 KB |
Output is correct |
14 |
Correct |
13 ms |
22620 KB |
Output is correct |
15 |
Correct |
13 ms |
22440 KB |
Output is correct |
16 |
Correct |
13 ms |
22620 KB |
Output is correct |
17 |
Correct |
10 ms |
21632 KB |
Output is correct |
18 |
Correct |
10 ms |
21596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
459 ms |
74336 KB |
Output is correct |
2 |
Correct |
429 ms |
74180 KB |
Output is correct |
3 |
Correct |
444 ms |
74180 KB |
Output is correct |
4 |
Correct |
118 ms |
35264 KB |
Output is correct |
5 |
Correct |
338 ms |
74084 KB |
Output is correct |
6 |
Correct |
114 ms |
35420 KB |
Output is correct |
7 |
Correct |
457 ms |
74336 KB |
Output is correct |
8 |
Correct |
413 ms |
74436 KB |
Output is correct |
9 |
Correct |
412 ms |
74344 KB |
Output is correct |
10 |
Correct |
304 ms |
73956 KB |
Output is correct |
11 |
Correct |
76 ms |
30148 KB |
Output is correct |
12 |
Correct |
96 ms |
29888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
459 ms |
74336 KB |
Output is correct |
2 |
Correct |
429 ms |
74180 KB |
Output is correct |
3 |
Correct |
444 ms |
74180 KB |
Output is correct |
4 |
Correct |
118 ms |
35264 KB |
Output is correct |
5 |
Correct |
338 ms |
74084 KB |
Output is correct |
6 |
Correct |
114 ms |
35420 KB |
Output is correct |
7 |
Correct |
457 ms |
74336 KB |
Output is correct |
8 |
Correct |
413 ms |
74436 KB |
Output is correct |
9 |
Correct |
412 ms |
74344 KB |
Output is correct |
10 |
Correct |
304 ms |
73956 KB |
Output is correct |
11 |
Correct |
76 ms |
30148 KB |
Output is correct |
12 |
Correct |
96 ms |
29888 KB |
Output is correct |
13 |
Correct |
472 ms |
74104 KB |
Output is correct |
14 |
Correct |
438 ms |
77224 KB |
Output is correct |
15 |
Correct |
439 ms |
76520 KB |
Output is correct |
16 |
Correct |
168 ms |
37572 KB |
Output is correct |
17 |
Correct |
397 ms |
76208 KB |
Output is correct |
18 |
Correct |
142 ms |
36288 KB |
Output is correct |
19 |
Correct |
530 ms |
77056 KB |
Output is correct |
20 |
Correct |
521 ms |
77020 KB |
Output is correct |
21 |
Correct |
633 ms |
77232 KB |
Output is correct |
22 |
Correct |
339 ms |
75728 KB |
Output is correct |
23 |
Correct |
76 ms |
31688 KB |
Output is correct |
24 |
Correct |
95 ms |
30868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
19292 KB |
Output is correct |
2 |
Correct |
8 ms |
19184 KB |
Output is correct |
3 |
Correct |
10 ms |
19124 KB |
Output is correct |
4 |
Correct |
8 ms |
19292 KB |
Output is correct |
5 |
Correct |
8 ms |
19292 KB |
Output is correct |
6 |
Correct |
10 ms |
19292 KB |
Output is correct |
7 |
Correct |
13 ms |
22620 KB |
Output is correct |
8 |
Correct |
13 ms |
22616 KB |
Output is correct |
9 |
Correct |
13 ms |
22612 KB |
Output is correct |
10 |
Correct |
13 ms |
21848 KB |
Output is correct |
11 |
Correct |
15 ms |
22616 KB |
Output is correct |
12 |
Correct |
11 ms |
21596 KB |
Output is correct |
13 |
Correct |
14 ms |
22456 KB |
Output is correct |
14 |
Correct |
13 ms |
22620 KB |
Output is correct |
15 |
Correct |
13 ms |
22440 KB |
Output is correct |
16 |
Correct |
13 ms |
22620 KB |
Output is correct |
17 |
Correct |
10 ms |
21632 KB |
Output is correct |
18 |
Correct |
10 ms |
21596 KB |
Output is correct |
19 |
Correct |
459 ms |
74336 KB |
Output is correct |
20 |
Correct |
429 ms |
74180 KB |
Output is correct |
21 |
Correct |
444 ms |
74180 KB |
Output is correct |
22 |
Correct |
118 ms |
35264 KB |
Output is correct |
23 |
Correct |
338 ms |
74084 KB |
Output is correct |
24 |
Correct |
114 ms |
35420 KB |
Output is correct |
25 |
Correct |
457 ms |
74336 KB |
Output is correct |
26 |
Correct |
413 ms |
74436 KB |
Output is correct |
27 |
Correct |
412 ms |
74344 KB |
Output is correct |
28 |
Correct |
304 ms |
73956 KB |
Output is correct |
29 |
Correct |
76 ms |
30148 KB |
Output is correct |
30 |
Correct |
96 ms |
29888 KB |
Output is correct |
31 |
Correct |
472 ms |
74104 KB |
Output is correct |
32 |
Correct |
438 ms |
77224 KB |
Output is correct |
33 |
Correct |
439 ms |
76520 KB |
Output is correct |
34 |
Correct |
168 ms |
37572 KB |
Output is correct |
35 |
Correct |
397 ms |
76208 KB |
Output is correct |
36 |
Correct |
142 ms |
36288 KB |
Output is correct |
37 |
Correct |
530 ms |
77056 KB |
Output is correct |
38 |
Correct |
521 ms |
77020 KB |
Output is correct |
39 |
Correct |
633 ms |
77232 KB |
Output is correct |
40 |
Correct |
339 ms |
75728 KB |
Output is correct |
41 |
Correct |
76 ms |
31688 KB |
Output is correct |
42 |
Correct |
95 ms |
30868 KB |
Output is correct |
43 |
Correct |
549 ms |
83140 KB |
Output is correct |
44 |
Correct |
532 ms |
83020 KB |
Output is correct |
45 |
Correct |
504 ms |
82888 KB |
Output is correct |
46 |
Correct |
137 ms |
38592 KB |
Output is correct |
47 |
Correct |
391 ms |
81348 KB |
Output is correct |
48 |
Correct |
121 ms |
36296 KB |
Output is correct |
49 |
Correct |
493 ms |
82888 KB |
Output is correct |
50 |
Correct |
540 ms |
85956 KB |
Output is correct |
51 |
Correct |
550 ms |
85704 KB |
Output is correct |
52 |
Correct |
365 ms |
81344 KB |
Output is correct |
53 |
Correct |
111 ms |
32704 KB |
Output is correct |