//八(^□^*)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=3e5+6;
const int SQRT=600;
int n,q;
int ans[MAXN];
set<pair<int,int> >xs;
set<int>ys,zs;
int s[MAXN],t[MAXN],sum[MAXN];
int x[MAXN],y[MAXN],z[MAXN];
map<pair<int,int>,int>newx;
map<int,int>newy,newz;
struct student
{
int a,b,c;
student(){}
student(int _a,int _b,int _c)
{
a=_a;b=_b;c=_c;
}
bool operator<(student const& other)const
{
return b<other.b;
}
};
struct query
{
int a,b,c,pos;
query(){}
query(int _a,int _b,int _c,int _pos)
{
a=_a;b=_b;c=_c;pos=_pos;
}
bool operator<(query const& other)const
{
return b<other.b;
}
};
vector<student>blocks1[SQRT];
vector<query>blocks2[SQRT];
int BIT[MAXN];
void update(int idx,int val)
{
++idx;
for(;idx<MAXN;idx+=idx&(-idx))
{
BIT[idx]+=val;
}
}
int query(int idx)
{
++idx;
int ret=0;
for(;idx>0;idx-=idx&(-idx))
{
ret+=BIT[idx];
}
return ret;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>q;
for(int i=1;i<=n;++i)
{
cin>>s[i]>>t[i];
xs.insert({s[i],i});
sum[i]=s[i]+t[i];
ys.insert(t[i]);zs.insert(sum[i]);
}
int cntx=0,cnty=0,cntz=0;
for(auto xd:xs)
{
newx[xd]=++cntx;
}
for(auto xd:ys)
{
newy[xd]=++cnty;
}
for(auto xd:zs)
{
newz[xd]=++cntz;
}
for(int i=1;i<=q;++i)
{
cin>>x[i]>>y[i]>>z[i];
xs.insert({x[i],-i});
auto it=ys.lower_bound(y[i]);
if(it==ys.end())y[i]=cnty+1;
else y[i]=newy[(*it)];
it=zs.lower_bound(z[i]);
if(it==zs.end())z[i]=cntz+1;
else z[i]=newz[(*it)];
}
for(auto xd:xs)
{
newx[xd]=++cntx;
}
for(int i=1;i<=n;++i)
{
s[i]=newx[{s[i],i}];
t[i]=newy[t[i]];
sum[i]=newz[sum[i]];
}
for(int i=1;i<=q;i++)
{
x[i]=newx[{x[i],-i}];
}
//cout<<"students:\n";
for(int i=1;i<=n;++i)
{
//cout<<s[i]<<" "<<t[i]<<" "<<sum[i]<<endl;
blocks1[s[i]/SQRT].push_back({s[i],t[i],sum[i]});
}
//cout<<"criterias:\n";
for(int i=1;i<=q;++i)
{
//cout<<x[i]<<" "<<y[i]<<" "<<z[i]<<endl;
blocks2[x[i]/SQRT].push_back({x[i],y[i],z[i],i});
}
vector<student>computed,eh,oh;
for(int j=SQRT-1;j>=0;--j)
{
if(blocks1[j].size()==0&&blocks2[j].size()==0)continue;
memset(BIT,0,sizeof(BIT));
/*cout<<"block1 "<<j<<":\n";
for(int i=0;i<blocks1[j].size();++i)
{
cout<<blocks1[j][i].a<<" "<<blocks1[j][i].b<<" "<<blocks1[j][i].c<<"\n";
}
cout<<endl;
cout<<"block2 "<<j<<":\n";
for(int i=0;i<blocks2[j].size();++i)
{
cout<<blocks2[j][i].a<<" "<<blocks2[j][i].b<<" "<<blocks2[j][i].c<<" "<<blocks2[j][i].pos<<"\n";
}
cout<<endl;*/
for(int i1=0;i1<blocks2[j].size();++i1)
{
for(int i2=0;i2<blocks1[j].size();++i2)
{
if(blocks2[j][i1].a<=blocks1[j][i2].a&&blocks2[j][i1].b<=blocks1[j][i2].b&&blocks2[j][i1].c<=blocks1[j][i2].c)
{
ans[blocks2[j][i1].pos]++;
}
}
}
sort(blocks2[j].rbegin(),blocks2[j].rend());
int p=computed.size()-1;
for(int i=0;i<blocks2[j].size();++i)
{
while(p>=0&&computed[p].b>=blocks2[j][i].b)
{
update(computed[p].c,+1);
p--;
}
ans[blocks2[j][i].pos]+=(computed.size()-p-1)-query(blocks2[j][i].c-1);
}
eh.clear();
for(int i=0;i<blocks1[j].size();++i)
{
eh.push_back(blocks1[j][i]);
}
sort(eh.begin(),eh.end());
oh.clear();
int i1=0,i2=0;
while(i1<eh.size()||i2<computed.size())
{
if(i1==eh.size())
{
oh.push_back(computed[i2]);
++i2;
}
else if(i2==computed.size())
{
oh.push_back(eh[i1]);
++i1;
}
else if(eh[i1]<computed[i2])
{
oh.push_back(eh[i1]);
++i1;
}
else
{
oh.push_back(computed[i2]);
++i2;
}
}
computed=oh;
/*cout<<"computed:\n";
for(int j=0;j<computed.size();j++)
{
cout<<computed[j].a<<" "<<computed[j].b<<" "<<computed[j].c<<endl;
}*/
}
for(int i=1;i<=q;++i)
{
cout<<ans[i]<<"\n";
}
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:142:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
142 | for(int i1=0;i1<blocks2[j].size();++i1)
| ~~^~~~~~~~~~~~~~~~~~
examination.cpp:144:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<student>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
144 | for(int i2=0;i2<blocks1[j].size();++i2)
| ~~^~~~~~~~~~~~~~~~~~
examination.cpp:154:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
154 | for(int i=0;i<blocks2[j].size();++i)
| ~^~~~~~~~~~~~~~~~~~
examination.cpp:164:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<student>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
164 | for(int i=0;i<blocks1[j].size();++i)
| ~^~~~~~~~~~~~~~~~~~
examination.cpp:171:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<student>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
171 | while(i1<eh.size()||i2<computed.size())
| ~~^~~~~~~~~~
examination.cpp:171:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<student>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
171 | while(i1<eh.size()||i2<computed.size())
| ~~^~~~~~~~~~~~~~~~
examination.cpp:173:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<student>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
173 | if(i1==eh.size())
| ~~^~~~~~~~~~~
examination.cpp:178:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<student>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
178 | else if(i2==computed.size())
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1516 KB |
Output is correct |
2 |
Correct |
1 ms |
1516 KB |
Output is correct |
3 |
Correct |
1 ms |
1516 KB |
Output is correct |
4 |
Correct |
1 ms |
1516 KB |
Output is correct |
5 |
Correct |
1 ms |
1516 KB |
Output is correct |
6 |
Correct |
1 ms |
1516 KB |
Output is correct |
7 |
Correct |
19 ms |
3180 KB |
Output is correct |
8 |
Correct |
19 ms |
3180 KB |
Output is correct |
9 |
Correct |
19 ms |
3180 KB |
Output is correct |
10 |
Correct |
16 ms |
2924 KB |
Output is correct |
11 |
Correct |
21 ms |
3308 KB |
Output is correct |
12 |
Correct |
12 ms |
2668 KB |
Output is correct |
13 |
Correct |
18 ms |
3180 KB |
Output is correct |
14 |
Correct |
17 ms |
3180 KB |
Output is correct |
15 |
Correct |
17 ms |
3180 KB |
Output is correct |
16 |
Correct |
12 ms |
3180 KB |
Output is correct |
17 |
Correct |
14 ms |
2944 KB |
Output is correct |
18 |
Correct |
7 ms |
2540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1698 ms |
48896 KB |
Output is correct |
2 |
Correct |
1666 ms |
51460 KB |
Output is correct |
3 |
Correct |
1674 ms |
51644 KB |
Output is correct |
4 |
Correct |
1328 ms |
43832 KB |
Output is correct |
5 |
Correct |
1078 ms |
48180 KB |
Output is correct |
6 |
Correct |
796 ms |
35644 KB |
Output is correct |
7 |
Correct |
1615 ms |
51580 KB |
Output is correct |
8 |
Correct |
1600 ms |
51444 KB |
Output is correct |
9 |
Correct |
1527 ms |
51576 KB |
Output is correct |
10 |
Correct |
880 ms |
48376 KB |
Output is correct |
11 |
Correct |
1255 ms |
43620 KB |
Output is correct |
12 |
Correct |
491 ms |
35560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1698 ms |
48896 KB |
Output is correct |
2 |
Correct |
1666 ms |
51460 KB |
Output is correct |
3 |
Correct |
1674 ms |
51644 KB |
Output is correct |
4 |
Correct |
1328 ms |
43832 KB |
Output is correct |
5 |
Correct |
1078 ms |
48180 KB |
Output is correct |
6 |
Correct |
796 ms |
35644 KB |
Output is correct |
7 |
Correct |
1615 ms |
51580 KB |
Output is correct |
8 |
Correct |
1600 ms |
51444 KB |
Output is correct |
9 |
Correct |
1527 ms |
51576 KB |
Output is correct |
10 |
Correct |
880 ms |
48376 KB |
Output is correct |
11 |
Correct |
1255 ms |
43620 KB |
Output is correct |
12 |
Correct |
491 ms |
35560 KB |
Output is correct |
13 |
Correct |
1782 ms |
51760 KB |
Output is correct |
14 |
Correct |
1763 ms |
51068 KB |
Output is correct |
15 |
Correct |
1626 ms |
51340 KB |
Output is correct |
16 |
Correct |
1446 ms |
44148 KB |
Output is correct |
17 |
Correct |
1173 ms |
48668 KB |
Output is correct |
18 |
Correct |
786 ms |
35900 KB |
Output is correct |
19 |
Correct |
1798 ms |
51884 KB |
Output is correct |
20 |
Correct |
1787 ms |
51844 KB |
Output is correct |
21 |
Correct |
1780 ms |
50672 KB |
Output is correct |
22 |
Correct |
855 ms |
48336 KB |
Output is correct |
23 |
Correct |
1216 ms |
43716 KB |
Output is correct |
24 |
Correct |
498 ms |
35100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1516 KB |
Output is correct |
2 |
Correct |
1 ms |
1516 KB |
Output is correct |
3 |
Correct |
1 ms |
1516 KB |
Output is correct |
4 |
Correct |
1 ms |
1516 KB |
Output is correct |
5 |
Correct |
1 ms |
1516 KB |
Output is correct |
6 |
Correct |
1 ms |
1516 KB |
Output is correct |
7 |
Correct |
19 ms |
3180 KB |
Output is correct |
8 |
Correct |
19 ms |
3180 KB |
Output is correct |
9 |
Correct |
19 ms |
3180 KB |
Output is correct |
10 |
Correct |
16 ms |
2924 KB |
Output is correct |
11 |
Correct |
21 ms |
3308 KB |
Output is correct |
12 |
Correct |
12 ms |
2668 KB |
Output is correct |
13 |
Correct |
18 ms |
3180 KB |
Output is correct |
14 |
Correct |
17 ms |
3180 KB |
Output is correct |
15 |
Correct |
17 ms |
3180 KB |
Output is correct |
16 |
Correct |
12 ms |
3180 KB |
Output is correct |
17 |
Correct |
14 ms |
2944 KB |
Output is correct |
18 |
Correct |
7 ms |
2540 KB |
Output is correct |
19 |
Correct |
1698 ms |
48896 KB |
Output is correct |
20 |
Correct |
1666 ms |
51460 KB |
Output is correct |
21 |
Correct |
1674 ms |
51644 KB |
Output is correct |
22 |
Correct |
1328 ms |
43832 KB |
Output is correct |
23 |
Correct |
1078 ms |
48180 KB |
Output is correct |
24 |
Correct |
796 ms |
35644 KB |
Output is correct |
25 |
Correct |
1615 ms |
51580 KB |
Output is correct |
26 |
Correct |
1600 ms |
51444 KB |
Output is correct |
27 |
Correct |
1527 ms |
51576 KB |
Output is correct |
28 |
Correct |
880 ms |
48376 KB |
Output is correct |
29 |
Correct |
1255 ms |
43620 KB |
Output is correct |
30 |
Correct |
491 ms |
35560 KB |
Output is correct |
31 |
Correct |
1782 ms |
51760 KB |
Output is correct |
32 |
Correct |
1763 ms |
51068 KB |
Output is correct |
33 |
Correct |
1626 ms |
51340 KB |
Output is correct |
34 |
Correct |
1446 ms |
44148 KB |
Output is correct |
35 |
Correct |
1173 ms |
48668 KB |
Output is correct |
36 |
Correct |
786 ms |
35900 KB |
Output is correct |
37 |
Correct |
1798 ms |
51884 KB |
Output is correct |
38 |
Correct |
1787 ms |
51844 KB |
Output is correct |
39 |
Correct |
1780 ms |
50672 KB |
Output is correct |
40 |
Correct |
855 ms |
48336 KB |
Output is correct |
41 |
Correct |
1216 ms |
43716 KB |
Output is correct |
42 |
Correct |
498 ms |
35100 KB |
Output is correct |
43 |
Correct |
1915 ms |
59896 KB |
Output is correct |
44 |
Correct |
1908 ms |
59076 KB |
Output is correct |
45 |
Correct |
1902 ms |
59796 KB |
Output is correct |
46 |
Correct |
1493 ms |
48640 KB |
Output is correct |
47 |
Correct |
1285 ms |
56676 KB |
Output is correct |
48 |
Correct |
797 ms |
36180 KB |
Output is correct |
49 |
Correct |
1799 ms |
59624 KB |
Output is correct |
50 |
Correct |
1811 ms |
59572 KB |
Output is correct |
51 |
Correct |
1708 ms |
59428 KB |
Output is correct |
52 |
Correct |
1135 ms |
56744 KB |
Output is correct |
53 |
Correct |
1250 ms |
47844 KB |
Output is correct |