#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5;
struct node
{
int x, y, z, i;
bool operator<(const node &o) const
{
if (x==o.x&&y==o.y&&z==o.z) return i<o.i;
if (x==o.x&&y==o.y) return z>o.z;
if (x==o.x) return y>o.y;
return x>o.x;
}
} d[nx], tmp[nx];
struct fenwick
{
int d[nx];
void add(int i, int vl)
{
while (i<nx) d[i]+=vl, i+=(i&-i);
}
int query(int i)
{
int res=0;
while (i>0) res+=d[i], i-=(i&-i);
return res;
}
} f;
int n, q, t, res[nx];
map<int, int> mp;
void solve(int l, int r)
{
if (l==r) return;
int md=(l+r)/2;
solve(l, md);
solve(md+1, r);
int idx=l;
//cout<<"here "<<l<<' '<<r<<'\n';
//for (int i=l; i<=r; i++) cout<<"value "<<d[i].i<<' '<<d[i].x<<' '<<d[i].y<<' '<<d[i].z<<'\n';
for (int i=l, j=md+1; idx<=r;)
{
if (j>r||(i<=md&&d[i].y>=d[j].y))
{
if (d[i].i==0) f.add(mp[d[i].z], 1);//cout<<"update "<<l<<' '<<r<<' '<<d[i].x<<' '<<d[i].y<<' '<<d[i].z<<' '<<mp[d[i].z]<<'\n', f.add(mp[d[i].z], 1);
tmp[idx++]=d[i++];
}
else
{
if (d[j].i!=0) res[d[j].i]+=f.query(nx-1)-f.query(mp[d[j].z]-1);//cout<<"query "<<l<<' '<<r<<' '<<d[j].i<<' '<<mp[d[j].z]<<'\n', res[d[j].i]+=f.query(nx-1)-f.query(mp[d[j].z]-1);
tmp[idx++]=d[j++];
}
}
for (int i=l; i<=md; i++) if (d[i].i==0) f.add(mp[d[i].z], -1);
for (int i=l; i<=r; i++) d[i]=tmp[i];
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>q;
for (int i=1; i<=n; i++) cin>>d[i].x>>d[i].y, d[i].z=d[i].x+d[i].y, d[i].i=0;
for (int i=n+1; i<=n+q; i++) cin>>d[i].x>>d[i].y>>d[i].z, d[i].i=i-n;
sort(d+1, d+n+q+1);
for (int i=1; i<=n+q; i++) mp[d[i].z]=0;
for (auto &[x, y]:mp) y=++t;
solve(1, n+q);
for (int i=1; i<=q;i ++) cout<<res[i]<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
10 ms |
4952 KB |
Output is correct |
8 |
Correct |
10 ms |
4956 KB |
Output is correct |
9 |
Correct |
9 ms |
4956 KB |
Output is correct |
10 |
Correct |
8 ms |
4960 KB |
Output is correct |
11 |
Correct |
8 ms |
4952 KB |
Output is correct |
12 |
Correct |
4 ms |
4444 KB |
Output is correct |
13 |
Correct |
7 ms |
4700 KB |
Output is correct |
14 |
Correct |
7 ms |
4700 KB |
Output is correct |
15 |
Correct |
8 ms |
4696 KB |
Output is correct |
16 |
Correct |
6 ms |
4700 KB |
Output is correct |
17 |
Correct |
8 ms |
4956 KB |
Output is correct |
18 |
Correct |
3 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
380 ms |
14716 KB |
Output is correct |
2 |
Correct |
410 ms |
14976 KB |
Output is correct |
3 |
Correct |
377 ms |
14676 KB |
Output is correct |
4 |
Correct |
240 ms |
13676 KB |
Output is correct |
5 |
Correct |
275 ms |
13496 KB |
Output is correct |
6 |
Correct |
99 ms |
9812 KB |
Output is correct |
7 |
Correct |
401 ms |
14712 KB |
Output is correct |
8 |
Correct |
373 ms |
14676 KB |
Output is correct |
9 |
Correct |
382 ms |
14676 KB |
Output is correct |
10 |
Correct |
273 ms |
13368 KB |
Output is correct |
11 |
Correct |
281 ms |
13484 KB |
Output is correct |
12 |
Correct |
93 ms |
9240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
380 ms |
14716 KB |
Output is correct |
2 |
Correct |
410 ms |
14976 KB |
Output is correct |
3 |
Correct |
377 ms |
14676 KB |
Output is correct |
4 |
Correct |
240 ms |
13676 KB |
Output is correct |
5 |
Correct |
275 ms |
13496 KB |
Output is correct |
6 |
Correct |
99 ms |
9812 KB |
Output is correct |
7 |
Correct |
401 ms |
14712 KB |
Output is correct |
8 |
Correct |
373 ms |
14676 KB |
Output is correct |
9 |
Correct |
382 ms |
14676 KB |
Output is correct |
10 |
Correct |
273 ms |
13368 KB |
Output is correct |
11 |
Correct |
281 ms |
13484 KB |
Output is correct |
12 |
Correct |
93 ms |
9240 KB |
Output is correct |
13 |
Correct |
567 ms |
17592 KB |
Output is correct |
14 |
Correct |
549 ms |
16848 KB |
Output is correct |
15 |
Correct |
383 ms |
14740 KB |
Output is correct |
16 |
Correct |
409 ms |
14960 KB |
Output is correct |
17 |
Correct |
397 ms |
14972 KB |
Output is correct |
18 |
Correct |
105 ms |
9792 KB |
Output is correct |
19 |
Correct |
571 ms |
17412 KB |
Output is correct |
20 |
Correct |
534 ms |
17124 KB |
Output is correct |
21 |
Correct |
559 ms |
17496 KB |
Output is correct |
22 |
Correct |
281 ms |
13156 KB |
Output is correct |
23 |
Correct |
281 ms |
13136 KB |
Output is correct |
24 |
Correct |
92 ms |
9236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
10 ms |
4952 KB |
Output is correct |
8 |
Correct |
10 ms |
4956 KB |
Output is correct |
9 |
Correct |
9 ms |
4956 KB |
Output is correct |
10 |
Correct |
8 ms |
4960 KB |
Output is correct |
11 |
Correct |
8 ms |
4952 KB |
Output is correct |
12 |
Correct |
4 ms |
4444 KB |
Output is correct |
13 |
Correct |
7 ms |
4700 KB |
Output is correct |
14 |
Correct |
7 ms |
4700 KB |
Output is correct |
15 |
Correct |
8 ms |
4696 KB |
Output is correct |
16 |
Correct |
6 ms |
4700 KB |
Output is correct |
17 |
Correct |
8 ms |
4956 KB |
Output is correct |
18 |
Correct |
3 ms |
4444 KB |
Output is correct |
19 |
Correct |
380 ms |
14716 KB |
Output is correct |
20 |
Correct |
410 ms |
14976 KB |
Output is correct |
21 |
Correct |
377 ms |
14676 KB |
Output is correct |
22 |
Correct |
240 ms |
13676 KB |
Output is correct |
23 |
Correct |
275 ms |
13496 KB |
Output is correct |
24 |
Correct |
99 ms |
9812 KB |
Output is correct |
25 |
Correct |
401 ms |
14712 KB |
Output is correct |
26 |
Correct |
373 ms |
14676 KB |
Output is correct |
27 |
Correct |
382 ms |
14676 KB |
Output is correct |
28 |
Correct |
273 ms |
13368 KB |
Output is correct |
29 |
Correct |
281 ms |
13484 KB |
Output is correct |
30 |
Correct |
93 ms |
9240 KB |
Output is correct |
31 |
Correct |
567 ms |
17592 KB |
Output is correct |
32 |
Correct |
549 ms |
16848 KB |
Output is correct |
33 |
Correct |
383 ms |
14740 KB |
Output is correct |
34 |
Correct |
409 ms |
14960 KB |
Output is correct |
35 |
Correct |
397 ms |
14972 KB |
Output is correct |
36 |
Correct |
105 ms |
9792 KB |
Output is correct |
37 |
Correct |
571 ms |
17412 KB |
Output is correct |
38 |
Correct |
534 ms |
17124 KB |
Output is correct |
39 |
Correct |
559 ms |
17496 KB |
Output is correct |
40 |
Correct |
281 ms |
13156 KB |
Output is correct |
41 |
Correct |
281 ms |
13136 KB |
Output is correct |
42 |
Correct |
92 ms |
9236 KB |
Output is correct |
43 |
Correct |
670 ms |
22864 KB |
Output is correct |
44 |
Correct |
594 ms |
22828 KB |
Output is correct |
45 |
Correct |
626 ms |
23024 KB |
Output is correct |
46 |
Correct |
491 ms |
21560 KB |
Output is correct |
47 |
Correct |
450 ms |
21332 KB |
Output is correct |
48 |
Correct |
115 ms |
9556 KB |
Output is correct |
49 |
Correct |
622 ms |
22624 KB |
Output is correct |
50 |
Correct |
628 ms |
22932 KB |
Output is correct |
51 |
Correct |
646 ms |
22992 KB |
Output is correct |
52 |
Correct |
403 ms |
21456 KB |
Output is correct |
53 |
Correct |
316 ms |
15696 KB |
Output is correct |