#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, l, r) for(int i=l; i<r; i++)
#define frange(i, l) forr(i, 0, l)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long long lli;
typedef vector<vi> vvi;
typedef vector<lli> vll;
typedef vector<bool> vb;
typedef set<int> seti;
typedef multiset<int> mseti;
void usaco()
{
freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
// freopen("problem.out", "w", stdout);
}
const int MAXN = 1e5 + 5;
vector<int> tree1[4*MAXN], tree2[4*MAXN];
vii vec;
void build(int x, int l, int r) {
if(l == r) {
// printf("%d %d\n", x, l);
tree1[x].pb(vec[l].s);
tree2[x].pb(vec[l].f + vec[l].s);
return;
}
int mid = (l+r)/2;
build(2*x+1, l, mid);
build(2*x+2, mid+1, r);
merge(all(tree1[2*x+1]), all(tree1[2*x+2]), back_inserter(tree1[x]));
merge(all(tree2[2*x+1]), all(tree2[2*x+2]), back_inserter(tree2[x]));
}
int query1(int x, int l, int r, int lx, int rx, int v) {
if(l > rx || r < lx) return 0;
if(lx <= l && r <= rx) {
return tree1[x].end() - lower_bound(all(tree1[x]), v);
}
int mid = (l+r)/2;
return query1(2*x+1, l, mid, lx, rx, v) + query1(2*x+2, mid+1, r, lx, rx, v);
}
int query2(int x, int l, int r, int lx, int rx, int v) {
if(l > rx || r < lx) return 0;
if(lx <= l && r <= rx) {
return tree2[x].end() - lower_bound(all(tree2[x]), v);
}
int mid = (l+r)/2;
return query2(2*x+1, l, mid, lx, rx, v) + query2(2*x+2, mid+1, r, lx, rx, v);
}
int main() {
// usaco();
int n, q;
scd(n);
scd(q);
vec = vii(n);
frange(i, n) {
scd(vec[i].f);
scd(vec[i].s);
}
sort(all(vec));
build(0, 0, n-1);
frange(_, q) {
int x, y, z;
scd(x);
scd(y);
scd(z);
int d = z - y;
int out = 0;
if(d >= x) {
int l = lower_bound(all(vec), mp(x, 0)) - vec.begin();
int r = lower_bound(all(vec), mp(d+1, 0)) - vec.begin() - 1;
out += query2(0, 0, n-1, l, r, z);
x = d+1;
}
int l = lower_bound(all(vec), mp(x, 0)) - vec.begin();
// int r = lower_bound(all(vec), mp(d+1, 0)) - vec.begin() - 1;
out += query1(0, 0, n-1, l, n-1, y);
printf("%d\n", out);
}
}
Compilation message
examination.cpp: In function 'void usaco()':
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("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
examination.cpp:71:5: note: in expansion of macro 'scd'
71 | scd(n);
| ^~~
examination.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
examination.cpp:72:5: note: in expansion of macro 'scd'
72 | scd(q);
| ^~~
examination.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
examination.cpp:76:9: note: in expansion of macro 'scd'
76 | scd(vec[i].f);
| ^~~
examination.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
examination.cpp:77:9: note: in expansion of macro 'scd'
77 | scd(vec[i].s);
| ^~~
examination.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
examination.cpp:85:9: note: in expansion of macro 'scd'
85 | scd(x);
| ^~~
examination.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
examination.cpp:86:9: note: in expansion of macro 'scd'
86 | scd(y);
| ^~~
examination.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
examination.cpp:87:9: note: in expansion of macro 'scd'
87 | scd(z);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
19032 KB |
Output is correct |
2 |
Correct |
4 ms |
19036 KB |
Output is correct |
3 |
Correct |
4 ms |
19036 KB |
Output is correct |
4 |
Correct |
4 ms |
19036 KB |
Output is correct |
5 |
Correct |
5 ms |
19036 KB |
Output is correct |
6 |
Correct |
4 ms |
19036 KB |
Output is correct |
7 |
Correct |
12 ms |
20060 KB |
Output is correct |
8 |
Correct |
9 ms |
20056 KB |
Output is correct |
9 |
Correct |
10 ms |
20060 KB |
Output is correct |
10 |
Correct |
9 ms |
19804 KB |
Output is correct |
11 |
Correct |
8 ms |
20000 KB |
Output is correct |
12 |
Correct |
8 ms |
19800 KB |
Output is correct |
13 |
Correct |
9 ms |
20216 KB |
Output is correct |
14 |
Correct |
10 ms |
20060 KB |
Output is correct |
15 |
Correct |
9 ms |
20060 KB |
Output is correct |
16 |
Correct |
7 ms |
19804 KB |
Output is correct |
17 |
Correct |
9 ms |
19984 KB |
Output is correct |
18 |
Correct |
7 ms |
19724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
253 ms |
49376 KB |
Output is correct |
2 |
Correct |
249 ms |
49292 KB |
Output is correct |
3 |
Correct |
263 ms |
49368 KB |
Output is correct |
4 |
Correct |
209 ms |
48520 KB |
Output is correct |
5 |
Correct |
158 ms |
48524 KB |
Output is correct |
6 |
Correct |
142 ms |
47748 KB |
Output is correct |
7 |
Correct |
248 ms |
49468 KB |
Output is correct |
8 |
Correct |
236 ms |
49748 KB |
Output is correct |
9 |
Correct |
215 ms |
49292 KB |
Output is correct |
10 |
Correct |
123 ms |
48456 KB |
Output is correct |
11 |
Correct |
185 ms |
48376 KB |
Output is correct |
12 |
Correct |
114 ms |
47692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
253 ms |
49376 KB |
Output is correct |
2 |
Correct |
249 ms |
49292 KB |
Output is correct |
3 |
Correct |
263 ms |
49368 KB |
Output is correct |
4 |
Correct |
209 ms |
48520 KB |
Output is correct |
5 |
Correct |
158 ms |
48524 KB |
Output is correct |
6 |
Correct |
142 ms |
47748 KB |
Output is correct |
7 |
Correct |
248 ms |
49468 KB |
Output is correct |
8 |
Correct |
236 ms |
49748 KB |
Output is correct |
9 |
Correct |
215 ms |
49292 KB |
Output is correct |
10 |
Correct |
123 ms |
48456 KB |
Output is correct |
11 |
Correct |
185 ms |
48376 KB |
Output is correct |
12 |
Correct |
114 ms |
47692 KB |
Output is correct |
13 |
Correct |
293 ms |
49716 KB |
Output is correct |
14 |
Correct |
303 ms |
49804 KB |
Output is correct |
15 |
Correct |
247 ms |
49248 KB |
Output is correct |
16 |
Correct |
296 ms |
49428 KB |
Output is correct |
17 |
Correct |
172 ms |
48924 KB |
Output is correct |
18 |
Correct |
150 ms |
47752 KB |
Output is correct |
19 |
Correct |
293 ms |
49644 KB |
Output is correct |
20 |
Correct |
332 ms |
49872 KB |
Output is correct |
21 |
Correct |
323 ms |
49824 KB |
Output is correct |
22 |
Correct |
142 ms |
48444 KB |
Output is correct |
23 |
Correct |
186 ms |
48336 KB |
Output is correct |
24 |
Correct |
117 ms |
47776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
19032 KB |
Output is correct |
2 |
Correct |
4 ms |
19036 KB |
Output is correct |
3 |
Correct |
4 ms |
19036 KB |
Output is correct |
4 |
Correct |
4 ms |
19036 KB |
Output is correct |
5 |
Correct |
5 ms |
19036 KB |
Output is correct |
6 |
Correct |
4 ms |
19036 KB |
Output is correct |
7 |
Correct |
12 ms |
20060 KB |
Output is correct |
8 |
Correct |
9 ms |
20056 KB |
Output is correct |
9 |
Correct |
10 ms |
20060 KB |
Output is correct |
10 |
Correct |
9 ms |
19804 KB |
Output is correct |
11 |
Correct |
8 ms |
20000 KB |
Output is correct |
12 |
Correct |
8 ms |
19800 KB |
Output is correct |
13 |
Correct |
9 ms |
20216 KB |
Output is correct |
14 |
Correct |
10 ms |
20060 KB |
Output is correct |
15 |
Correct |
9 ms |
20060 KB |
Output is correct |
16 |
Correct |
7 ms |
19804 KB |
Output is correct |
17 |
Correct |
9 ms |
19984 KB |
Output is correct |
18 |
Correct |
7 ms |
19724 KB |
Output is correct |
19 |
Correct |
253 ms |
49376 KB |
Output is correct |
20 |
Correct |
249 ms |
49292 KB |
Output is correct |
21 |
Correct |
263 ms |
49368 KB |
Output is correct |
22 |
Correct |
209 ms |
48520 KB |
Output is correct |
23 |
Correct |
158 ms |
48524 KB |
Output is correct |
24 |
Correct |
142 ms |
47748 KB |
Output is correct |
25 |
Correct |
248 ms |
49468 KB |
Output is correct |
26 |
Correct |
236 ms |
49748 KB |
Output is correct |
27 |
Correct |
215 ms |
49292 KB |
Output is correct |
28 |
Correct |
123 ms |
48456 KB |
Output is correct |
29 |
Correct |
185 ms |
48376 KB |
Output is correct |
30 |
Correct |
114 ms |
47692 KB |
Output is correct |
31 |
Correct |
293 ms |
49716 KB |
Output is correct |
32 |
Correct |
303 ms |
49804 KB |
Output is correct |
33 |
Correct |
247 ms |
49248 KB |
Output is correct |
34 |
Correct |
296 ms |
49428 KB |
Output is correct |
35 |
Correct |
172 ms |
48924 KB |
Output is correct |
36 |
Correct |
150 ms |
47752 KB |
Output is correct |
37 |
Correct |
293 ms |
49644 KB |
Output is correct |
38 |
Correct |
332 ms |
49872 KB |
Output is correct |
39 |
Correct |
323 ms |
49824 KB |
Output is correct |
40 |
Correct |
142 ms |
48444 KB |
Output is correct |
41 |
Correct |
186 ms |
48336 KB |
Output is correct |
42 |
Correct |
117 ms |
47776 KB |
Output is correct |
43 |
Correct |
304 ms |
51680 KB |
Output is correct |
44 |
Correct |
305 ms |
51760 KB |
Output is correct |
45 |
Correct |
302 ms |
51528 KB |
Output is correct |
46 |
Correct |
304 ms |
50240 KB |
Output is correct |
47 |
Correct |
191 ms |
50016 KB |
Output is correct |
48 |
Correct |
138 ms |
47752 KB |
Output is correct |
49 |
Correct |
356 ms |
51700 KB |
Output is correct |
50 |
Correct |
326 ms |
51732 KB |
Output is correct |
51 |
Correct |
454 ms |
51632 KB |
Output is correct |
52 |
Correct |
143 ms |
50052 KB |
Output is correct |
53 |
Correct |
227 ms |
49192 KB |
Output is correct |