#include <bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N=1e5+5;
struct BIT2D
{
const int inf = 2e9;
int n;
vector<vector<int>>nodes,f;
void fakeUpdate(int u, int v)
{
for (int x = u; x > 0; x -= x & -x) nodes[x].push_back(v);
}
void fakeGet(int u, int v)
{
for (int x = u; x <= n; x += x & -x) nodes[x].push_back(v);
}
void update(int u, int v)
{
for (int x = u; x > 0; x -= x & -x)
{
for (int y = upper_bound(nodes[x].begin(), nodes[x].end(), v) - nodes[x].begin(); y > 0; y -= y & -y)
f[x][y]++;
}
}
int get(int u, int v)
{
int res=0;
for (int x = u; x <= n; x += x & -x)
{
for (int y = lower_bound(nodes[x].begin(), nodes[x].end(), v) - nodes[x].begin() + 1; y <= nodes[x].size(); y += y & -y)
res += f[x][y];
}
return res;
}
void init(int _n)
{
n = _n;
nodes.assign(n + 5, {});
f.assign(n + 5, {});
}
void normalize()
{
for(int i=1;i<=n;i++)
{
nodes[i].push_back(inf);
sort(nodes[i].begin(), nodes[i].end());
f[i].resize(nodes[i].size()+3);
}
}
} ft;
int n,q,ans[N];
pair<int,int>stu[N];
vector<int>val;
int compress(int x)
{
return lower_bound(val.begin(),val.end(),x)-val.begin()+1;
}
struct Q
{
int A, B, C, id;
};
Q query[N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>stu[i].fi>>stu[i].se;
val.push_back(stu[i].fi);
val.push_back(stu[i].se);
val.push_back(stu[i].fi+stu[i].se);
}
for(int i=1;i<=q;i++)
{
query[i].id=i;
cin>>query[i].A>>query[i].B>>query[i].C;
val.push_back(query[i].A);
val.push_back(query[i].B);
val.push_back(query[i].C);
}
sort(val.begin(),val.end());
val.erase(unique(val.begin(),val.end()),val.end());
ft.init(val.size());
sort(stu+1,stu+n+1);
reverse(stu+1,stu+n+1);
sort(query + 1, query + 1 + n, [&](const Q& x, const Q& y) {
return x.A > y.A;
});
int j=1;
for(int i=1;i<=q;i++)
{
while(j<=n&&stu[j].fi>=query[i].A)
{
ft.fakeUpdate(compress(stu[j].se),compress(stu[j].fi+stu[j].se));
j++;
}
ft.fakeGet(compress(query[i].B),compress(query[i].C));
}
ft.normalize();
j=1;
for(int i=1;i<=q;i++)
{
while(j<=n&&stu[j].fi>=query[i].A)
{
ft.update(compress(stu[j].se),compress(stu[j].fi+stu[j].se));
j++;
}
ans[query[i].id]=ft.get(compress(query[i].B),compress(query[i].C));
}
for(int i=1;i<=q;i++) cout<<ans[i]<<'\n';
}
Compilation message
examination.cpp: In member function 'int BIT2D::get(int, int)':
examination.cpp:36:101: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int y = lower_bound(nodes[x].begin(), nodes[x].end(), v) - nodes[x].begin() + 1; y <= nodes[x].size(); y += y & -y)
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
416 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
17 ms |
2944 KB |
Output is correct |
8 |
Correct |
16 ms |
2944 KB |
Output is correct |
9 |
Correct |
17 ms |
2944 KB |
Output is correct |
10 |
Correct |
13 ms |
2304 KB |
Output is correct |
11 |
Correct |
14 ms |
2304 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
13 |
Correct |
14 ms |
2560 KB |
Output is correct |
14 |
Correct |
13 ms |
2560 KB |
Output is correct |
15 |
Correct |
13 ms |
2560 KB |
Output is correct |
16 |
Correct |
9 ms |
1536 KB |
Output is correct |
17 |
Correct |
12 ms |
2048 KB |
Output is correct |
18 |
Correct |
3 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
722 ms |
38944 KB |
Output is correct |
2 |
Correct |
721 ms |
39232 KB |
Output is correct |
3 |
Correct |
704 ms |
39136 KB |
Output is correct |
4 |
Correct |
363 ms |
32992 KB |
Output is correct |
5 |
Correct |
517 ms |
32992 KB |
Output is correct |
6 |
Correct |
128 ms |
11876 KB |
Output is correct |
7 |
Correct |
680 ms |
38752 KB |
Output is correct |
8 |
Correct |
673 ms |
39776 KB |
Output is correct |
9 |
Correct |
584 ms |
38496 KB |
Output is correct |
10 |
Correct |
437 ms |
31968 KB |
Output is correct |
11 |
Correct |
349 ms |
31824 KB |
Output is correct |
12 |
Correct |
96 ms |
9312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
722 ms |
38944 KB |
Output is correct |
2 |
Correct |
721 ms |
39232 KB |
Output is correct |
3 |
Correct |
704 ms |
39136 KB |
Output is correct |
4 |
Correct |
363 ms |
32992 KB |
Output is correct |
5 |
Correct |
517 ms |
32992 KB |
Output is correct |
6 |
Correct |
128 ms |
11876 KB |
Output is correct |
7 |
Correct |
680 ms |
38752 KB |
Output is correct |
8 |
Correct |
673 ms |
39776 KB |
Output is correct |
9 |
Correct |
584 ms |
38496 KB |
Output is correct |
10 |
Correct |
437 ms |
31968 KB |
Output is correct |
11 |
Correct |
349 ms |
31824 KB |
Output is correct |
12 |
Correct |
96 ms |
9312 KB |
Output is correct |
13 |
Correct |
932 ms |
42204 KB |
Output is correct |
14 |
Correct |
889 ms |
39392 KB |
Output is correct |
15 |
Correct |
706 ms |
39136 KB |
Output is correct |
16 |
Correct |
762 ms |
33752 KB |
Output is correct |
17 |
Correct |
657 ms |
33636 KB |
Output is correct |
18 |
Correct |
140 ms |
11916 KB |
Output is correct |
19 |
Correct |
910 ms |
42080 KB |
Output is correct |
20 |
Correct |
926 ms |
40676 KB |
Output is correct |
21 |
Correct |
927 ms |
41956 KB |
Output is correct |
22 |
Correct |
458 ms |
32096 KB |
Output is correct |
23 |
Correct |
347 ms |
31864 KB |
Output is correct |
24 |
Correct |
94 ms |
9568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
416 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
17 ms |
2944 KB |
Output is correct |
8 |
Correct |
16 ms |
2944 KB |
Output is correct |
9 |
Correct |
17 ms |
2944 KB |
Output is correct |
10 |
Correct |
13 ms |
2304 KB |
Output is correct |
11 |
Correct |
14 ms |
2304 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
13 |
Correct |
14 ms |
2560 KB |
Output is correct |
14 |
Correct |
13 ms |
2560 KB |
Output is correct |
15 |
Correct |
13 ms |
2560 KB |
Output is correct |
16 |
Correct |
9 ms |
1536 KB |
Output is correct |
17 |
Correct |
12 ms |
2048 KB |
Output is correct |
18 |
Correct |
3 ms |
640 KB |
Output is correct |
19 |
Correct |
722 ms |
38944 KB |
Output is correct |
20 |
Correct |
721 ms |
39232 KB |
Output is correct |
21 |
Correct |
704 ms |
39136 KB |
Output is correct |
22 |
Correct |
363 ms |
32992 KB |
Output is correct |
23 |
Correct |
517 ms |
32992 KB |
Output is correct |
24 |
Correct |
128 ms |
11876 KB |
Output is correct |
25 |
Correct |
680 ms |
38752 KB |
Output is correct |
26 |
Correct |
673 ms |
39776 KB |
Output is correct |
27 |
Correct |
584 ms |
38496 KB |
Output is correct |
28 |
Correct |
437 ms |
31968 KB |
Output is correct |
29 |
Correct |
349 ms |
31824 KB |
Output is correct |
30 |
Correct |
96 ms |
9312 KB |
Output is correct |
31 |
Correct |
932 ms |
42204 KB |
Output is correct |
32 |
Correct |
889 ms |
39392 KB |
Output is correct |
33 |
Correct |
706 ms |
39136 KB |
Output is correct |
34 |
Correct |
762 ms |
33752 KB |
Output is correct |
35 |
Correct |
657 ms |
33636 KB |
Output is correct |
36 |
Correct |
140 ms |
11916 KB |
Output is correct |
37 |
Correct |
910 ms |
42080 KB |
Output is correct |
38 |
Correct |
926 ms |
40676 KB |
Output is correct |
39 |
Correct |
927 ms |
41956 KB |
Output is correct |
40 |
Correct |
458 ms |
32096 KB |
Output is correct |
41 |
Correct |
347 ms |
31864 KB |
Output is correct |
42 |
Correct |
94 ms |
9568 KB |
Output is correct |
43 |
Correct |
1298 ms |
90848 KB |
Output is correct |
44 |
Correct |
1266 ms |
90840 KB |
Output is correct |
45 |
Correct |
1251 ms |
91000 KB |
Output is correct |
46 |
Correct |
932 ms |
68956 KB |
Output is correct |
47 |
Correct |
903 ms |
67040 KB |
Output is correct |
48 |
Correct |
184 ms |
12520 KB |
Output is correct |
49 |
Correct |
1191 ms |
90736 KB |
Output is correct |
50 |
Correct |
1308 ms |
92000 KB |
Output is correct |
51 |
Correct |
1205 ms |
91980 KB |
Output is correct |
52 |
Correct |
795 ms |
56448 KB |
Output is correct |
53 |
Correct |
408 ms |
45796 KB |
Output is correct |