//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const ll INF = 1e16 + 7;
const int MAXN = 4e5 + 5;
const double eps = 1e-9;
pii a[MAXN];
struct nodeX {
vector<vi> seg;
vi arr, sm;
} seg[MAXN];
void build(int l, int r, int k, int k2, vi &sm) {
if (l == r) {
seg[k2].seg[k] = {sm[l]};
return;
}
int m = (l + r) / 2;
build(l, m, k*2, k2, sm);
build(m+1, r, k*2+1, k2, sm);
int i = 0, j = 0;
while (i < (int)seg[k2].seg[k*2].size() && j < (int)seg[k2].seg[k*2+1].size())
if (seg[k2].seg[k*2][i] < seg[k2].seg[k*2+1][j])
seg[k2].seg[k].pb(seg[k2].seg[k*2][i++]);
else
seg[k2].seg[k].pb(seg[k2].seg[k*2+1][j++]);
while (i < (int)seg[k2].seg[k*2].size())
seg[k2].seg[k].pb(seg[k2].seg[k*2][i++]);
while (j < (int)seg[k2].seg[k*2+1].size())
seg[k2].seg[k].pb(seg[k2].seg[k*2+1][j++]);
}
void build(int l, int r, int k) {
if (l == r) {
seg[k].arr = {a[l].se};
seg[k].sm = {a[l].fi + a[l].se};
seg[k].seg.resize(2);
build(0, 0, 1, k, seg[k].sm);
return;
}
seg[k].seg.resize(3*(r-l+1)+1);
int m = (l + r) / 2;
build(l, m, k * 2);
build(m + 1, r, k * 2 + 1);
int i = 0, j = 0;
while (i < (int)seg[k*2].arr.size() && j < (int)seg[k*2+1].arr.size()) {
if (seg[k*2].arr[i] < seg[k*2+1].arr[j]) {
seg[k].arr.pb(seg[k*2].arr[i]);
seg[k].sm.pb(seg[k*2].sm[i++]);
} else {
seg[k].arr.pb(seg[k*2+1].arr[j]);
seg[k].sm.pb(seg[k*2+1].sm[j++]);
}
}
while (i < (int)seg[k*2].arr.size()) {
seg[k].arr.pb(seg[k*2].arr[i]);
seg[k].sm.pb(seg[k*2].sm[i++]);
}
while (j < (int)seg[k*2+1].arr.size()) {
seg[k].arr.pb(seg[k*2+1].arr[j]);
seg[k].sm.pb(seg[k*2+1].sm[j++]);
}
build(0, r - l, 1, k, seg[k].sm);
}
int qry1(int l, int r, int k, int k2, int a, int b, int z) {
if (r < a || b < l) return 0;
if (a <= l && r <= b) {
int lo = lower_bound(seg[k2].seg[k].begin(), seg[k2].seg[k].end(), z) - seg[k2].seg[k].begin();
return (int)seg[k2].seg[k].size() - lo;
}
int m = (l + r) / 2;
return qry1(l, m, k*2, k2, a, b, z) + qry1(m+1, r, k*2+1, k2, a, b, z);
}
int qry(int l, int r, int k, int a, int b, int y, int z) {
if (r < a || b < l) return 0;
if (a <= l && r <= b) {
int lo = lower_bound(seg[k].arr.begin(), seg[k].arr.end(), y) - seg[k].arr.begin();
return qry1(0, r - l, 1, k, lo, r - l, z);
}
int m = (l + r) / 2;
return qry(l, m, k*2, a, b, y, z) + qry(m + 1, r, k*2+1, a, b, y, z);
}
int main() {
int n, q;
scanf("%d %d", &n, &q);
for (int i = 0; i < n; i++)
scanf("%d %d", &a[i].fi, &a[i].se);
sort(a, a + n);
build(0, n - 1, 1);
for (int i = 0; i < q; i++) {
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
int lo = lower_bound(a, a + n, mp(x, -1)) - a;
pri(qry(0, n - 1, 1, lo, n - 1, y, z));
}
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:118:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:120:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a[i].fi, &a[i].se);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:125:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &x, &y, &z);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
28544 KB |
Output is correct |
2 |
Correct |
26 ms |
28544 KB |
Output is correct |
3 |
Correct |
27 ms |
28544 KB |
Output is correct |
4 |
Correct |
27 ms |
28544 KB |
Output is correct |
5 |
Correct |
26 ms |
28544 KB |
Output is correct |
6 |
Correct |
26 ms |
28544 KB |
Output is correct |
7 |
Correct |
54 ms |
34936 KB |
Output is correct |
8 |
Correct |
54 ms |
34936 KB |
Output is correct |
9 |
Correct |
54 ms |
34940 KB |
Output is correct |
10 |
Correct |
51 ms |
34928 KB |
Output is correct |
11 |
Correct |
50 ms |
34936 KB |
Output is correct |
12 |
Correct |
54 ms |
34920 KB |
Output is correct |
13 |
Correct |
62 ms |
34936 KB |
Output is correct |
14 |
Correct |
55 ms |
34908 KB |
Output is correct |
15 |
Correct |
53 ms |
34936 KB |
Output is correct |
16 |
Correct |
46 ms |
34936 KB |
Output is correct |
17 |
Correct |
53 ms |
34944 KB |
Output is correct |
18 |
Correct |
47 ms |
34936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2020 ms |
341656 KB |
Output is correct |
2 |
Correct |
2027 ms |
341652 KB |
Output is correct |
3 |
Correct |
1946 ms |
341792 KB |
Output is correct |
4 |
Correct |
1687 ms |
341544 KB |
Output is correct |
5 |
Correct |
1364 ms |
341612 KB |
Output is correct |
6 |
Correct |
1178 ms |
341672 KB |
Output is correct |
7 |
Correct |
1812 ms |
341676 KB |
Output is correct |
8 |
Correct |
1914 ms |
341676 KB |
Output is correct |
9 |
Correct |
1487 ms |
341676 KB |
Output is correct |
10 |
Correct |
1087 ms |
341548 KB |
Output is correct |
11 |
Correct |
1259 ms |
341336 KB |
Output is correct |
12 |
Correct |
1052 ms |
341292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2020 ms |
341656 KB |
Output is correct |
2 |
Correct |
2027 ms |
341652 KB |
Output is correct |
3 |
Correct |
1946 ms |
341792 KB |
Output is correct |
4 |
Correct |
1687 ms |
341544 KB |
Output is correct |
5 |
Correct |
1364 ms |
341612 KB |
Output is correct |
6 |
Correct |
1178 ms |
341672 KB |
Output is correct |
7 |
Correct |
1812 ms |
341676 KB |
Output is correct |
8 |
Correct |
1914 ms |
341676 KB |
Output is correct |
9 |
Correct |
1487 ms |
341676 KB |
Output is correct |
10 |
Correct |
1087 ms |
341548 KB |
Output is correct |
11 |
Correct |
1259 ms |
341336 KB |
Output is correct |
12 |
Correct |
1052 ms |
341292 KB |
Output is correct |
13 |
Correct |
2094 ms |
341684 KB |
Output is correct |
14 |
Correct |
1985 ms |
341700 KB |
Output is correct |
15 |
Correct |
2269 ms |
341676 KB |
Output is correct |
16 |
Correct |
1799 ms |
341760 KB |
Output is correct |
17 |
Correct |
1342 ms |
341616 KB |
Output is correct |
18 |
Correct |
1202 ms |
341716 KB |
Output is correct |
19 |
Correct |
2156 ms |
341692 KB |
Output is correct |
20 |
Correct |
2013 ms |
341740 KB |
Output is correct |
21 |
Correct |
2009 ms |
341724 KB |
Output is correct |
22 |
Correct |
1138 ms |
341436 KB |
Output is correct |
23 |
Correct |
1434 ms |
341512 KB |
Output is correct |
24 |
Correct |
1123 ms |
341260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
28544 KB |
Output is correct |
2 |
Correct |
26 ms |
28544 KB |
Output is correct |
3 |
Correct |
27 ms |
28544 KB |
Output is correct |
4 |
Correct |
27 ms |
28544 KB |
Output is correct |
5 |
Correct |
26 ms |
28544 KB |
Output is correct |
6 |
Correct |
26 ms |
28544 KB |
Output is correct |
7 |
Correct |
54 ms |
34936 KB |
Output is correct |
8 |
Correct |
54 ms |
34936 KB |
Output is correct |
9 |
Correct |
54 ms |
34940 KB |
Output is correct |
10 |
Correct |
51 ms |
34928 KB |
Output is correct |
11 |
Correct |
50 ms |
34936 KB |
Output is correct |
12 |
Correct |
54 ms |
34920 KB |
Output is correct |
13 |
Correct |
62 ms |
34936 KB |
Output is correct |
14 |
Correct |
55 ms |
34908 KB |
Output is correct |
15 |
Correct |
53 ms |
34936 KB |
Output is correct |
16 |
Correct |
46 ms |
34936 KB |
Output is correct |
17 |
Correct |
53 ms |
34944 KB |
Output is correct |
18 |
Correct |
47 ms |
34936 KB |
Output is correct |
19 |
Correct |
2020 ms |
341656 KB |
Output is correct |
20 |
Correct |
2027 ms |
341652 KB |
Output is correct |
21 |
Correct |
1946 ms |
341792 KB |
Output is correct |
22 |
Correct |
1687 ms |
341544 KB |
Output is correct |
23 |
Correct |
1364 ms |
341612 KB |
Output is correct |
24 |
Correct |
1178 ms |
341672 KB |
Output is correct |
25 |
Correct |
1812 ms |
341676 KB |
Output is correct |
26 |
Correct |
1914 ms |
341676 KB |
Output is correct |
27 |
Correct |
1487 ms |
341676 KB |
Output is correct |
28 |
Correct |
1087 ms |
341548 KB |
Output is correct |
29 |
Correct |
1259 ms |
341336 KB |
Output is correct |
30 |
Correct |
1052 ms |
341292 KB |
Output is correct |
31 |
Correct |
2094 ms |
341684 KB |
Output is correct |
32 |
Correct |
1985 ms |
341700 KB |
Output is correct |
33 |
Correct |
2269 ms |
341676 KB |
Output is correct |
34 |
Correct |
1799 ms |
341760 KB |
Output is correct |
35 |
Correct |
1342 ms |
341616 KB |
Output is correct |
36 |
Correct |
1202 ms |
341716 KB |
Output is correct |
37 |
Correct |
2156 ms |
341692 KB |
Output is correct |
38 |
Correct |
2013 ms |
341740 KB |
Output is correct |
39 |
Correct |
2009 ms |
341724 KB |
Output is correct |
40 |
Correct |
1138 ms |
341436 KB |
Output is correct |
41 |
Correct |
1434 ms |
341512 KB |
Output is correct |
42 |
Correct |
1123 ms |
341260 KB |
Output is correct |
43 |
Correct |
1993 ms |
341764 KB |
Output is correct |
44 |
Correct |
1855 ms |
341728 KB |
Output is correct |
45 |
Correct |
1811 ms |
341644 KB |
Output is correct |
46 |
Correct |
1695 ms |
341732 KB |
Output is correct |
47 |
Correct |
1320 ms |
341728 KB |
Output is correct |
48 |
Correct |
1194 ms |
341420 KB |
Output is correct |
49 |
Correct |
1895 ms |
341680 KB |
Output is correct |
50 |
Correct |
1868 ms |
341804 KB |
Output is correct |
51 |
Correct |
1881 ms |
341752 KB |
Output is correct |
52 |
Correct |
1191 ms |
341452 KB |
Output is correct |
53 |
Correct |
1319 ms |
341548 KB |
Output is correct |