#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct BIT{
int n;
int val[1000000];
int get(int x){
int res = 0;
while(x){
res += val[x];
x -= x & -x;
}
return res;
}
void add(int x, int vrd){
while(x <= n){
val[x] += vrd;
x += x & -x;
}
}
};
struct query{
int x, y, z, ind;
};
bool cmp1(query a, query b){
if(a.x == b.x) return a.ind > b.ind;
return a.x < b.x;
}
bool cmp2(query a, query b){
if(a.z == b.z) return a.ind > b.ind;
return a.z < b.z;
}
pair <int, int> niz[100005];
map <int, int> compr;
int tcomp;
query queries1[200005], queries2[200005];
int res[100005];
int main(){
ios_base::sync_with_stdio(false);
int n, q;
cin >> n >> q;
vector <int> compvec;
for(int i=1; i<=n; i++){
cin >> niz[i].first >> niz[i].second;
compvec.push_back(niz[i].first);
compvec.push_back(niz[i].second);
compvec.push_back(niz[i].first+niz[i].second);
}
int q1 = 0, q2 = 0;
for(int i=1; i<=q; i++){
int x, y, z;
cin >> x >> y >> z;
compvec.push_back(x);
compvec.push_back(y);
compvec.push_back(z);
query tq;
tq.x = x, tq.y = y, tq.z = z, tq.ind = i;
if(z <= x+y) queries1[++q1] = tq;
else queries2[++q2] = tq;
}
for(int i=1; i<=n; i++){
query tq;
tq.x = niz[i].first;
tq.y = niz[i].second;
tq.ind = tq.z = 0;
queries1[++q1] = tq;
}
sort(compvec.begin(), compvec.end());
for(auto c : compvec){
if(!compr[c]) compr[c] = ++tcomp;
}
sort(queries1+1, queries1+1+q1, cmp1);
int bilo = 0;
BIT sam;
sam.n = tcomp;
for(int i=q1; i>=1; i--){
if(queries1[i].ind == 0){
bilo++;
sam.add(compr[queries1[i].y], 1);
}
else{
res[queries1[i].ind] += bilo - sam.get(compr[queries1[i].y]-1);
}
}
for(int i=1; i<=n; i++){
query tq;
tq.x = niz[i].first;
tq.y = niz[i].second;
tq.z = niz[i].first + niz[i].second;
tq.ind = 0;
queries2[++q2] = tq;
}
sort(queries2+1, queries2+1+q2, cmp2);
BIT prvo, drugo;
bilo = 0;
prvo.n = drugo.n = tcomp;
for(int i=q2; i>=1; i--){
if(queries2[i].ind == 0){
bilo++;
prvo.add(compr[queries2[i].x], 1);
drugo.add(compr[queries2[i].y], 1);
}
else{
res[queries2[i].ind] += bilo - prvo.get(compr[queries2[i].x]-1) - drugo.get(compr[queries2[i].y]-1);
}
}
for(int i=1; i<=q; i++) cout << res[i] << "\n";
return 0;
}
# |
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 |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
15 ms |
1900 KB |
Output is correct |
8 |
Correct |
12 ms |
1900 KB |
Output is correct |
9 |
Correct |
15 ms |
1900 KB |
Output is correct |
10 |
Correct |
8 ms |
1388 KB |
Output is correct |
11 |
Correct |
9 ms |
1388 KB |
Output is correct |
12 |
Correct |
4 ms |
804 KB |
Output is correct |
13 |
Correct |
11 ms |
1644 KB |
Output is correct |
14 |
Correct |
10 ms |
1644 KB |
Output is correct |
15 |
Correct |
11 ms |
1664 KB |
Output is correct |
16 |
Correct |
7 ms |
1144 KB |
Output is correct |
17 |
Correct |
7 ms |
1260 KB |
Output is correct |
18 |
Correct |
3 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
410 ms |
19164 KB |
Output is correct |
2 |
Correct |
384 ms |
18140 KB |
Output is correct |
3 |
Correct |
407 ms |
18012 KB |
Output is correct |
4 |
Correct |
217 ms |
15404 KB |
Output is correct |
5 |
Correct |
279 ms |
15728 KB |
Output is correct |
6 |
Correct |
113 ms |
10480 KB |
Output is correct |
7 |
Correct |
400 ms |
18140 KB |
Output is correct |
8 |
Correct |
385 ms |
17884 KB |
Output is correct |
9 |
Correct |
344 ms |
17704 KB |
Output is correct |
10 |
Correct |
281 ms |
15196 KB |
Output is correct |
11 |
Correct |
208 ms |
14684 KB |
Output is correct |
12 |
Correct |
98 ms |
10020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
410 ms |
19164 KB |
Output is correct |
2 |
Correct |
384 ms |
18140 KB |
Output is correct |
3 |
Correct |
407 ms |
18012 KB |
Output is correct |
4 |
Correct |
217 ms |
15404 KB |
Output is correct |
5 |
Correct |
279 ms |
15728 KB |
Output is correct |
6 |
Correct |
113 ms |
10480 KB |
Output is correct |
7 |
Correct |
400 ms |
18140 KB |
Output is correct |
8 |
Correct |
385 ms |
17884 KB |
Output is correct |
9 |
Correct |
344 ms |
17704 KB |
Output is correct |
10 |
Correct |
281 ms |
15196 KB |
Output is correct |
11 |
Correct |
208 ms |
14684 KB |
Output is correct |
12 |
Correct |
98 ms |
10020 KB |
Output is correct |
13 |
Correct |
435 ms |
19164 KB |
Output is correct |
14 |
Correct |
404 ms |
18156 KB |
Output is correct |
15 |
Correct |
374 ms |
18012 KB |
Output is correct |
16 |
Correct |
259 ms |
15580 KB |
Output is correct |
17 |
Correct |
299 ms |
15836 KB |
Output is correct |
18 |
Correct |
113 ms |
10440 KB |
Output is correct |
19 |
Correct |
432 ms |
19164 KB |
Output is correct |
20 |
Correct |
414 ms |
18652 KB |
Output is correct |
21 |
Correct |
421 ms |
19164 KB |
Output is correct |
22 |
Correct |
248 ms |
15068 KB |
Output is correct |
23 |
Correct |
216 ms |
14684 KB |
Output is correct |
24 |
Correct |
90 ms |
9948 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 |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
15 ms |
1900 KB |
Output is correct |
8 |
Correct |
12 ms |
1900 KB |
Output is correct |
9 |
Correct |
15 ms |
1900 KB |
Output is correct |
10 |
Correct |
8 ms |
1388 KB |
Output is correct |
11 |
Correct |
9 ms |
1388 KB |
Output is correct |
12 |
Correct |
4 ms |
804 KB |
Output is correct |
13 |
Correct |
11 ms |
1644 KB |
Output is correct |
14 |
Correct |
10 ms |
1644 KB |
Output is correct |
15 |
Correct |
11 ms |
1664 KB |
Output is correct |
16 |
Correct |
7 ms |
1144 KB |
Output is correct |
17 |
Correct |
7 ms |
1260 KB |
Output is correct |
18 |
Correct |
3 ms |
748 KB |
Output is correct |
19 |
Correct |
410 ms |
19164 KB |
Output is correct |
20 |
Correct |
384 ms |
18140 KB |
Output is correct |
21 |
Correct |
407 ms |
18012 KB |
Output is correct |
22 |
Correct |
217 ms |
15404 KB |
Output is correct |
23 |
Correct |
279 ms |
15728 KB |
Output is correct |
24 |
Correct |
113 ms |
10480 KB |
Output is correct |
25 |
Correct |
400 ms |
18140 KB |
Output is correct |
26 |
Correct |
385 ms |
17884 KB |
Output is correct |
27 |
Correct |
344 ms |
17704 KB |
Output is correct |
28 |
Correct |
281 ms |
15196 KB |
Output is correct |
29 |
Correct |
208 ms |
14684 KB |
Output is correct |
30 |
Correct |
98 ms |
10020 KB |
Output is correct |
31 |
Correct |
435 ms |
19164 KB |
Output is correct |
32 |
Correct |
404 ms |
18156 KB |
Output is correct |
33 |
Correct |
374 ms |
18012 KB |
Output is correct |
34 |
Correct |
259 ms |
15580 KB |
Output is correct |
35 |
Correct |
299 ms |
15836 KB |
Output is correct |
36 |
Correct |
113 ms |
10440 KB |
Output is correct |
37 |
Correct |
432 ms |
19164 KB |
Output is correct |
38 |
Correct |
414 ms |
18652 KB |
Output is correct |
39 |
Correct |
421 ms |
19164 KB |
Output is correct |
40 |
Correct |
248 ms |
15068 KB |
Output is correct |
41 |
Correct |
216 ms |
14684 KB |
Output is correct |
42 |
Correct |
90 ms |
9948 KB |
Output is correct |
43 |
Correct |
859 ms |
45584 KB |
Output is correct |
44 |
Correct |
820 ms |
45500 KB |
Output is correct |
45 |
Correct |
816 ms |
46564 KB |
Output is correct |
46 |
Correct |
379 ms |
32576 KB |
Output is correct |
47 |
Correct |
497 ms |
33884 KB |
Output is correct |
48 |
Correct |
118 ms |
10360 KB |
Output is correct |
49 |
Correct |
804 ms |
48476 KB |
Output is correct |
50 |
Correct |
835 ms |
47588 KB |
Output is correct |
51 |
Correct |
830 ms |
48604 KB |
Output is correct |
52 |
Correct |
438 ms |
28804 KB |
Output is correct |
53 |
Correct |
252 ms |
21724 KB |
Output is correct |