#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define N 100005
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n,q;
pii niz[N];
struct upit{
int x,y,z;
int idx;
}kv[N];
map<int, int>slika;
bool cmp(pii a, pii b){
return a.xx > b.xx;
}
int ans[N];
int br;
int bit[6 * N][2];
void dodaj(int x, int idx){
for(;x > 0; x-=(x&-x))bit[x][idx]++;
}
int query(int x, int idx){
int sol = 0;
for(;x <= br; x+=(x&-x))sol += bit[x][idx];
return sol;
}
struct fw{
int idx;
int poz;
int znk;
int val;
int zakoju;
};
bool cmp2(fw a, fw b){
return a.poz < b.poz;
}
int dokle(int x){
if(x > niz[1].xx)return 0;
if(x <= niz[n].xx)return n;
int l = 1;
int r = n;
while(l < r){
int mid = (l + r + 1) / 2;
if(niz[mid].xx >= x)l = mid;
else r = mid - 1;
}
return l;
}
vector<fw> v;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
vector<int> svi;
cin >> n >> q;
ff(i,1,n){
cin >> niz[i].xx >> niz[i].yy;
svi.pb(niz[i].xx);
svi.pb(niz[i].yy);
svi.pb(niz[i].xx + niz[i].yy);
}
sort(niz + 1, niz + n + 1, cmp);
ff(i,1,q){
int a,b,c;
cin >> a >> b >> c;
int prvi = dokle(a);
int drugi = dokle(c - b);
if(c - b <= a){
v.pb({0,prvi,1,b,i});
}
else{
v.pb({0,drugi,1,b,i});
if(drugi < prvi){
v.pb({1,drugi,-1,c,i});
v.pb({1,prvi,1,c,i});
}
}
kv[i].x = a;
kv[i].y = b;
kv[i].z = c;
svi.pb(a);
svi.pb(b);
svi.pb(c);
}
sort(svi.begin(), svi.end());
int last = -1;
for(auto c:svi){
if(c == last)continue;
br++;
slika[c] = br;
last = c;
}
sort(v.begin(), v.end(), cmp2);
int tr = 0;
ff(i,1,n){
dodaj(slika[niz[i].yy], 0);
dodaj(slika[niz[i].xx + niz[i].yy], 1);
while(1){
int sta = v.size();
if(tr == sta)break;
while(v[tr].poz < i)tr++;
if(v[tr].poz > i)break;
ans[v[tr].zakoju] += (v[tr].znk)*query(slika[v[tr].val],v[tr].idx);
tr++;
}
}
ff(i,1,q)cout << ans[i] << "\n";
return 0;
}
/*
5 1
35 100
70 70
45 15
80 40
20 95
20 50 120
*/
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
examination.cpp:85:5: note: in expansion of macro 'ff'
85 | ff(i,1,n){
| ^~
examination.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
examination.cpp:92:5: note: in expansion of macro 'ff'
92 | ff(i,1,q){
| ^~
examination.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
examination.cpp:126:5: note: in expansion of macro 'ff'
126 | ff(i,1,n){
| ^~
examination.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
| ^
examination.cpp:138:5: note: in expansion of macro 'ff'
138 | ff(i,1,q)cout << ans[i] << "\n";
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
12 ms |
1900 KB |
Output is correct |
8 |
Correct |
11 ms |
1900 KB |
Output is correct |
9 |
Correct |
13 ms |
1900 KB |
Output is correct |
10 |
Correct |
8 ms |
1516 KB |
Output is correct |
11 |
Correct |
8 ms |
1516 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
9 ms |
1516 KB |
Output is correct |
14 |
Correct |
9 ms |
1516 KB |
Output is correct |
15 |
Correct |
11 ms |
1516 KB |
Output is correct |
16 |
Correct |
5 ms |
1004 KB |
Output is correct |
17 |
Correct |
9 ms |
1260 KB |
Output is correct |
18 |
Correct |
3 ms |
804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
317 ms |
15448 KB |
Output is correct |
2 |
Correct |
337 ms |
15448 KB |
Output is correct |
3 |
Correct |
322 ms |
15448 KB |
Output is correct |
4 |
Correct |
187 ms |
13144 KB |
Output is correct |
5 |
Correct |
240 ms |
13216 KB |
Output is correct |
6 |
Correct |
97 ms |
9304 KB |
Output is correct |
7 |
Correct |
320 ms |
15388 KB |
Output is correct |
8 |
Correct |
316 ms |
15320 KB |
Output is correct |
9 |
Correct |
284 ms |
15192 KB |
Output is correct |
10 |
Correct |
193 ms |
12504 KB |
Output is correct |
11 |
Correct |
194 ms |
12632 KB |
Output is correct |
12 |
Correct |
78 ms |
9184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
317 ms |
15448 KB |
Output is correct |
2 |
Correct |
337 ms |
15448 KB |
Output is correct |
3 |
Correct |
322 ms |
15448 KB |
Output is correct |
4 |
Correct |
187 ms |
13144 KB |
Output is correct |
5 |
Correct |
240 ms |
13216 KB |
Output is correct |
6 |
Correct |
97 ms |
9304 KB |
Output is correct |
7 |
Correct |
320 ms |
15388 KB |
Output is correct |
8 |
Correct |
316 ms |
15320 KB |
Output is correct |
9 |
Correct |
284 ms |
15192 KB |
Output is correct |
10 |
Correct |
193 ms |
12504 KB |
Output is correct |
11 |
Correct |
194 ms |
12632 KB |
Output is correct |
12 |
Correct |
78 ms |
9184 KB |
Output is correct |
13 |
Correct |
446 ms |
20352 KB |
Output is correct |
14 |
Correct |
384 ms |
19024 KB |
Output is correct |
15 |
Correct |
333 ms |
18008 KB |
Output is correct |
16 |
Correct |
287 ms |
17488 KB |
Output is correct |
17 |
Correct |
281 ms |
17488 KB |
Output is correct |
18 |
Correct |
128 ms |
12508 KB |
Output is correct |
19 |
Correct |
424 ms |
21712 KB |
Output is correct |
20 |
Correct |
453 ms |
20432 KB |
Output is correct |
21 |
Correct |
481 ms |
22756 KB |
Output is correct |
22 |
Correct |
189 ms |
14424 KB |
Output is correct |
23 |
Correct |
181 ms |
14456 KB |
Output is correct |
24 |
Correct |
85 ms |
10208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
12 ms |
1900 KB |
Output is correct |
8 |
Correct |
11 ms |
1900 KB |
Output is correct |
9 |
Correct |
13 ms |
1900 KB |
Output is correct |
10 |
Correct |
8 ms |
1516 KB |
Output is correct |
11 |
Correct |
8 ms |
1516 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
9 ms |
1516 KB |
Output is correct |
14 |
Correct |
9 ms |
1516 KB |
Output is correct |
15 |
Correct |
11 ms |
1516 KB |
Output is correct |
16 |
Correct |
5 ms |
1004 KB |
Output is correct |
17 |
Correct |
9 ms |
1260 KB |
Output is correct |
18 |
Correct |
3 ms |
804 KB |
Output is correct |
19 |
Correct |
317 ms |
15448 KB |
Output is correct |
20 |
Correct |
337 ms |
15448 KB |
Output is correct |
21 |
Correct |
322 ms |
15448 KB |
Output is correct |
22 |
Correct |
187 ms |
13144 KB |
Output is correct |
23 |
Correct |
240 ms |
13216 KB |
Output is correct |
24 |
Correct |
97 ms |
9304 KB |
Output is correct |
25 |
Correct |
320 ms |
15388 KB |
Output is correct |
26 |
Correct |
316 ms |
15320 KB |
Output is correct |
27 |
Correct |
284 ms |
15192 KB |
Output is correct |
28 |
Correct |
193 ms |
12504 KB |
Output is correct |
29 |
Correct |
194 ms |
12632 KB |
Output is correct |
30 |
Correct |
78 ms |
9184 KB |
Output is correct |
31 |
Correct |
446 ms |
20352 KB |
Output is correct |
32 |
Correct |
384 ms |
19024 KB |
Output is correct |
33 |
Correct |
333 ms |
18008 KB |
Output is correct |
34 |
Correct |
287 ms |
17488 KB |
Output is correct |
35 |
Correct |
281 ms |
17488 KB |
Output is correct |
36 |
Correct |
128 ms |
12508 KB |
Output is correct |
37 |
Correct |
424 ms |
21712 KB |
Output is correct |
38 |
Correct |
453 ms |
20432 KB |
Output is correct |
39 |
Correct |
481 ms |
22756 KB |
Output is correct |
40 |
Correct |
189 ms |
14424 KB |
Output is correct |
41 |
Correct |
181 ms |
14456 KB |
Output is correct |
42 |
Correct |
85 ms |
10208 KB |
Output is correct |
43 |
Correct |
747 ms |
47824 KB |
Output is correct |
44 |
Correct |
738 ms |
47824 KB |
Output is correct |
45 |
Correct |
705 ms |
46392 KB |
Output is correct |
46 |
Correct |
379 ms |
34660 KB |
Output is correct |
47 |
Correct |
436 ms |
34640 KB |
Output is correct |
48 |
Correct |
131 ms |
13264 KB |
Output is correct |
49 |
Correct |
747 ms |
47696 KB |
Output is correct |
50 |
Correct |
780 ms |
48764 KB |
Output is correct |
51 |
Correct |
873 ms |
49280 KB |
Output is correct |
52 |
Correct |
337 ms |
28528 KB |
Output is correct |
53 |
Correct |
217 ms |
21336 KB |
Output is correct |