#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, pair<int, int> > > vec;
int bit[600005], ans[100005];
map<int, int> mp;
void upd(int x, int y)
{
for (int i=x; i<=6e5; i+=i&(-i))
bit[i]+=y;
}
int qry(int x)
{
int res=0;
for (int i=x; i; i-=i&(-i))
res+=bit[i];
return res;
}
void recur(int l, int r)
{
if (l==r)
return;
int mid=(l+r)/2;
vector<pair<pair<int, int>, int> > a;
vector<pair<int, int> > b;
for (int i=l; i<=mid; i++)
if (vec[i].first.second<1e9)
a.push_back({vec[i].second, vec[i].first.second});
for (int i=mid+1; i<=r; i++)
if (vec[i].first.second==1e9)
b.push_back(vec[i].second);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int ind=b.size();
for (int i=a.size()-1; i>=0; i--)
{
while (ind && b[ind-1].first>=a[i].first.first)
{
upd(6e5+1-b[ind-1].second, 1);
ind--;
}
ans[a[i].second]+=qry(6e5+1-a[i].first.second);
}
for (int i=ind; i<b.size(); i++)
upd(6e5+1-b[i].second, -1);
recur(l, mid);
recur(mid+1, r);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, cnt=0;
cin >> n >> m;
for (int i=1; i<=n; i++)
{
int x, y;
cin >> x >> y;
vec.push_back({{x+y, 1e9}, {x, y}});
mp[x]=mp[y]=mp[x+y]=0;
}
for (int i=1; i<=m; i++)
{
int x, y, z;
cin >> x >> y >> z;
vec.push_back({{z, i}, {x, y}});
mp[x]=mp[y]=mp[z]=0;
}
for (auto it=mp.begin(); it!=mp.end(); it++)
(*it).second=(++cnt);
for (int i=0; i<vec.size(); i++)
{
vec[i].first.first=mp[vec[i].first.first];
vec[i].second.first=mp[vec[i].second.first];
vec[i].second.second=mp[vec[i].second.second];
}
sort(vec.begin(), vec.end());
recur(0, vec.size()-1);
for (int i=1; i<=m; i++)
cout << ans[i] << '\n';
}
Compilation message
examination.cpp: In function 'void recur(int, int)':
examination.cpp:43:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i=ind; i<b.size(); i++)
| ~^~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:71:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i=0; i<vec.size(); i++)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
10 ms |
1576 KB |
Output is correct |
8 |
Correct |
10 ms |
1372 KB |
Output is correct |
9 |
Correct |
10 ms |
1372 KB |
Output is correct |
10 |
Correct |
8 ms |
1116 KB |
Output is correct |
11 |
Correct |
9 ms |
1116 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
9 ms |
1612 KB |
Output is correct |
14 |
Correct |
8 ms |
1372 KB |
Output is correct |
15 |
Correct |
8 ms |
1508 KB |
Output is correct |
16 |
Correct |
6 ms |
860 KB |
Output is correct |
17 |
Correct |
7 ms |
1116 KB |
Output is correct |
18 |
Correct |
3 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
360 ms |
14960 KB |
Output is correct |
2 |
Correct |
355 ms |
16568 KB |
Output is correct |
3 |
Correct |
386 ms |
16544 KB |
Output is correct |
4 |
Correct |
248 ms |
14520 KB |
Output is correct |
5 |
Correct |
289 ms |
12724 KB |
Output is correct |
6 |
Correct |
148 ms |
9660 KB |
Output is correct |
7 |
Correct |
356 ms |
17868 KB |
Output is correct |
8 |
Correct |
350 ms |
18868 KB |
Output is correct |
9 |
Correct |
335 ms |
19232 KB |
Output is correct |
10 |
Correct |
244 ms |
14216 KB |
Output is correct |
11 |
Correct |
221 ms |
15704 KB |
Output is correct |
12 |
Correct |
129 ms |
10884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
360 ms |
14960 KB |
Output is correct |
2 |
Correct |
355 ms |
16568 KB |
Output is correct |
3 |
Correct |
386 ms |
16544 KB |
Output is correct |
4 |
Correct |
248 ms |
14520 KB |
Output is correct |
5 |
Correct |
289 ms |
12724 KB |
Output is correct |
6 |
Correct |
148 ms |
9660 KB |
Output is correct |
7 |
Correct |
356 ms |
17868 KB |
Output is correct |
8 |
Correct |
350 ms |
18868 KB |
Output is correct |
9 |
Correct |
335 ms |
19232 KB |
Output is correct |
10 |
Correct |
244 ms |
14216 KB |
Output is correct |
11 |
Correct |
221 ms |
15704 KB |
Output is correct |
12 |
Correct |
129 ms |
10884 KB |
Output is correct |
13 |
Correct |
441 ms |
17896 KB |
Output is correct |
14 |
Correct |
435 ms |
16984 KB |
Output is correct |
15 |
Correct |
351 ms |
19128 KB |
Output is correct |
16 |
Correct |
317 ms |
15480 KB |
Output is correct |
17 |
Correct |
366 ms |
14144 KB |
Output is correct |
18 |
Correct |
163 ms |
10300 KB |
Output is correct |
19 |
Correct |
468 ms |
19676 KB |
Output is correct |
20 |
Correct |
457 ms |
19444 KB |
Output is correct |
21 |
Correct |
454 ms |
20044 KB |
Output is correct |
22 |
Correct |
238 ms |
14448 KB |
Output is correct |
23 |
Correct |
227 ms |
16056 KB |
Output is correct |
24 |
Correct |
132 ms |
10888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
10 ms |
1576 KB |
Output is correct |
8 |
Correct |
10 ms |
1372 KB |
Output is correct |
9 |
Correct |
10 ms |
1372 KB |
Output is correct |
10 |
Correct |
8 ms |
1116 KB |
Output is correct |
11 |
Correct |
9 ms |
1116 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
9 ms |
1612 KB |
Output is correct |
14 |
Correct |
8 ms |
1372 KB |
Output is correct |
15 |
Correct |
8 ms |
1508 KB |
Output is correct |
16 |
Correct |
6 ms |
860 KB |
Output is correct |
17 |
Correct |
7 ms |
1116 KB |
Output is correct |
18 |
Correct |
3 ms |
732 KB |
Output is correct |
19 |
Correct |
360 ms |
14960 KB |
Output is correct |
20 |
Correct |
355 ms |
16568 KB |
Output is correct |
21 |
Correct |
386 ms |
16544 KB |
Output is correct |
22 |
Correct |
248 ms |
14520 KB |
Output is correct |
23 |
Correct |
289 ms |
12724 KB |
Output is correct |
24 |
Correct |
148 ms |
9660 KB |
Output is correct |
25 |
Correct |
356 ms |
17868 KB |
Output is correct |
26 |
Correct |
350 ms |
18868 KB |
Output is correct |
27 |
Correct |
335 ms |
19232 KB |
Output is correct |
28 |
Correct |
244 ms |
14216 KB |
Output is correct |
29 |
Correct |
221 ms |
15704 KB |
Output is correct |
30 |
Correct |
129 ms |
10884 KB |
Output is correct |
31 |
Correct |
441 ms |
17896 KB |
Output is correct |
32 |
Correct |
435 ms |
16984 KB |
Output is correct |
33 |
Correct |
351 ms |
19128 KB |
Output is correct |
34 |
Correct |
317 ms |
15480 KB |
Output is correct |
35 |
Correct |
366 ms |
14144 KB |
Output is correct |
36 |
Correct |
163 ms |
10300 KB |
Output is correct |
37 |
Correct |
468 ms |
19676 KB |
Output is correct |
38 |
Correct |
457 ms |
19444 KB |
Output is correct |
39 |
Correct |
454 ms |
20044 KB |
Output is correct |
40 |
Correct |
238 ms |
14448 KB |
Output is correct |
41 |
Correct |
227 ms |
16056 KB |
Output is correct |
42 |
Correct |
132 ms |
10888 KB |
Output is correct |
43 |
Correct |
1004 ms |
42708 KB |
Output is correct |
44 |
Correct |
1042 ms |
43348 KB |
Output is correct |
45 |
Correct |
976 ms |
42748 KB |
Output is correct |
46 |
Correct |
570 ms |
30116 KB |
Output is correct |
47 |
Correct |
599 ms |
30708 KB |
Output is correct |
48 |
Correct |
151 ms |
9220 KB |
Output is correct |
49 |
Correct |
856 ms |
43388 KB |
Output is correct |
50 |
Correct |
963 ms |
42728 KB |
Output is correct |
51 |
Correct |
965 ms |
43352 KB |
Output is correct |
52 |
Correct |
526 ms |
25068 KB |
Output is correct |
53 |
Correct |
252 ms |
22508 KB |
Output is correct |