#include <bits/stdc++.h>
#define SQRTN 320
#define MAX 100005
typedef std::pair<int,int> pii;
int tab[325][325];
int sumed[325][325];
int t(int x,int y) {
if(x<0||y<0)return 0;
return sumed[x][y];
}
int subrec(int x1,int y1,int x2,int y2) {
if(x1==-1||x2==-1||y1==-1||y2==-1)return 0;
return t(x2,y2)-t(x2,y1-1)-t(x1-1,y2)+t(x1-1,y1-1);
}
void clear(void){memset(&tab[0][0],0,sizeof(tab));}
void comp(void) {
for(int i = 0; i != 325;++i) {
int val = 0;
for(int j = 0; j != 325;++j) {
val += tab[i][j];
sumed[i][j]=val;
if(i)sumed[i][j]+=sumed[i-1][j];
}
}
}
pii valores[MAX];
int N,Q;
struct bucket {
pii valores[SQRTN];
int l,r;
};
int respostas[MAX][320];
bucket baldes[320];
typedef std::pair<pii,int> ppi;
std::vector<ppi> queries;
std::vector<pii> VA,VB,VC;
int compressao[MAX][3];
void obter_respostas(bucket& ref,int tosave) {
std::map<int,bool> re1,re2;
for(int i=0;i!=ref.r-ref.l+1;++i){
re1[ref.valores[i].first]=true;
re2[ref.valores[i].second]=true;
}
std::map<int,int> fim1,fim2;
std::vector<int> v1,v2;
{
int cur=0;
for(auto&x:re1) {
fim1[x.first]=cur;++cur;
v1.push_back(x.first);
}
}
{
int cur=0;
for(auto&x:re2) {
fim2[x.first]=cur;++cur;
v2.push_back(x.first);
}
}
for(int i=0;i!=MAX;++i){
compressao[i][0]=compressao[i][1]=compressao[i][2]=-1;
}
int tabela[SQRTN][3];
clear();
{
int cursor=0;
int cursor2=0;
for(;;) {
if(VA[cursor2].first
<=v1[cursor]){
compressao[VA[cursor2].second][0]=cursor;++cursor2;
}else ++cursor;
if(cursor==v1.size())break;
if(cursor2==VA.size())break;
}
}
{
int cursor=0;
int cursor2=0;
for(;;) {
if(VB[cursor2].first<=v2[cursor]){
compressao[VB[cursor2].second][1]=cursor;++cursor2;
}else ++cursor;
if(cursor==v2.size())break;
if(cursor2==VB.size())break;
}
}
for(int i=0;i!=ref.r-ref.l+1;++i){
tab[fim1[ref.valores[i].first]][fim2[ref.valores[i].second]]++;
}
comp();
for(int i=0;i!=queries.size();++i) {
(respostas[i][tosave]=subrec(compressao[i][0],compressao[i][1],322,322));
}
}
int main()
{
for(auto&x:baldes)x.r=-1;
std::cin >> N >> Q;
for(int i=0;i!=N;++i){
std::cin>>valores[i].first>>valores[i].second;
}
std::sort(valores,&valores[N],[](auto x,auto y){return x.first+x.second<y.first+y.second;});
for(int i=0;i!=Q;++i) {
int a,b,c;
std::cin>>a>>b>>c;
queries.push_back({{a,b},c});
VA.push_back({a,i});
VB.push_back({b,i});
VC.push_back({c,i});
}
std::sort(VA.begin(),VA.end());
std::sort(VB.begin(),VB.end());
std::sort(VC.begin(),VC.end());
int ind=0,count=0;
for(int i=0;i!=N;++i){
baldes[ind].valores[count]=valores[i];
++count;
if(count==SQRTN) {
baldes[ind].r=i;
++ind;
baldes[ind].l=i+1;
count=0;
}
}
baldes[ind].r=N-1;
{
int cur=0;
for(auto&x:baldes){
if(x.l>=N)continue;
if(x.r==-1)break;
obter_respostas(x,cur);
++cur;
}
}
for(int i=0;i!=Q;++i) {
int count=0;
int min = queries[i].second;
for(int j=0;j!=320;++j) {
auto&x=baldes[j];
if(x.r==-1)break;
if(x.l>=N)continue;
if(x.valores[x.r-x.l].first+x.valores[x.r-x.l].second<min)continue;
if(x.valores[0].first+x.valores[0].second>=min) {
count+=respostas[i][j];
}else {
for(int k=0;k!=x.r-x.l+1;++k) {
if(x.valores[k].first+x.valores[k].second>=min&&
x.valores[k].first>=queries[i].first.first&&
x.valores[k].second>=queries[i].first.second)++count;
}
}
}
std::cout<<count<<"\n";
}
}
Compilation message
examination.cpp: In function 'void obter_respostas(bucket&, int)':
examination.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | if(cursor==v1.size())break;
| ~~~~~~^~~~~~~~~~~
examination.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if(cursor2==VA.size())break;
| ~~~~~~~^~~~~~~~~~~
examination.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | if(cursor==v2.size())break;
| ~~~~~~^~~~~~~~~~~
examination.cpp:85:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | if(cursor2==VB.size())break;
| ~~~~~~~^~~~~~~~~~~
examination.cpp:92:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for(int i=0;i!=queries.size();++i) {
| ~^~~~~~~~~~~~~~~~
examination.cpp:63:9: warning: unused variable 'tabela' [-Wunused-variable]
63 | int tabela[SQRTN][3];
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
3 |
Correct |
2 ms |
3020 KB |
Output is correct |
4 |
Correct |
2 ms |
3020 KB |
Output is correct |
5 |
Correct |
2 ms |
3044 KB |
Output is correct |
6 |
Correct |
3 ms |
3020 KB |
Output is correct |
7 |
Correct |
19 ms |
7248 KB |
Output is correct |
8 |
Correct |
19 ms |
7136 KB |
Output is correct |
9 |
Correct |
19 ms |
7192 KB |
Output is correct |
10 |
Correct |
16 ms |
7216 KB |
Output is correct |
11 |
Correct |
16 ms |
7116 KB |
Output is correct |
12 |
Correct |
13 ms |
7136 KB |
Output is correct |
13 |
Correct |
16 ms |
7216 KB |
Output is correct |
14 |
Correct |
16 ms |
7228 KB |
Output is correct |
15 |
Correct |
16 ms |
7132 KB |
Output is correct |
16 |
Correct |
13 ms |
7116 KB |
Output is correct |
17 |
Correct |
18 ms |
7112 KB |
Output is correct |
18 |
Correct |
11 ms |
7136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1223 ms |
136072 KB |
Output is correct |
2 |
Correct |
1255 ms |
136136 KB |
Output is correct |
3 |
Correct |
1224 ms |
136092 KB |
Output is correct |
4 |
Correct |
1073 ms |
135304 KB |
Output is correct |
5 |
Correct |
1058 ms |
135436 KB |
Output is correct |
6 |
Correct |
1072 ms |
134600 KB |
Output is correct |
7 |
Correct |
1194 ms |
136120 KB |
Output is correct |
8 |
Correct |
1208 ms |
135920 KB |
Output is correct |
9 |
Correct |
1210 ms |
135856 KB |
Output is correct |
10 |
Correct |
977 ms |
135144 KB |
Output is correct |
11 |
Correct |
982 ms |
135168 KB |
Output is correct |
12 |
Correct |
828 ms |
134148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1223 ms |
136072 KB |
Output is correct |
2 |
Correct |
1255 ms |
136136 KB |
Output is correct |
3 |
Correct |
1224 ms |
136092 KB |
Output is correct |
4 |
Correct |
1073 ms |
135304 KB |
Output is correct |
5 |
Correct |
1058 ms |
135436 KB |
Output is correct |
6 |
Correct |
1072 ms |
134600 KB |
Output is correct |
7 |
Correct |
1194 ms |
136120 KB |
Output is correct |
8 |
Correct |
1208 ms |
135920 KB |
Output is correct |
9 |
Correct |
1210 ms |
135856 KB |
Output is correct |
10 |
Correct |
977 ms |
135144 KB |
Output is correct |
11 |
Correct |
982 ms |
135168 KB |
Output is correct |
12 |
Correct |
828 ms |
134148 KB |
Output is correct |
13 |
Correct |
1302 ms |
136484 KB |
Output is correct |
14 |
Correct |
1318 ms |
136440 KB |
Output is correct |
15 |
Correct |
1190 ms |
136120 KB |
Output is correct |
16 |
Correct |
1108 ms |
135692 KB |
Output is correct |
17 |
Correct |
1164 ms |
135684 KB |
Output is correct |
18 |
Correct |
1123 ms |
134724 KB |
Output is correct |
19 |
Correct |
1301 ms |
136496 KB |
Output is correct |
20 |
Correct |
1318 ms |
136596 KB |
Output is correct |
21 |
Correct |
1298 ms |
136640 KB |
Output is correct |
22 |
Correct |
947 ms |
135124 KB |
Output is correct |
23 |
Correct |
994 ms |
135236 KB |
Output is correct |
24 |
Correct |
876 ms |
134164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3020 KB |
Output is correct |
2 |
Correct |
2 ms |
3020 KB |
Output is correct |
3 |
Correct |
2 ms |
3020 KB |
Output is correct |
4 |
Correct |
2 ms |
3020 KB |
Output is correct |
5 |
Correct |
2 ms |
3044 KB |
Output is correct |
6 |
Correct |
3 ms |
3020 KB |
Output is correct |
7 |
Correct |
19 ms |
7248 KB |
Output is correct |
8 |
Correct |
19 ms |
7136 KB |
Output is correct |
9 |
Correct |
19 ms |
7192 KB |
Output is correct |
10 |
Correct |
16 ms |
7216 KB |
Output is correct |
11 |
Correct |
16 ms |
7116 KB |
Output is correct |
12 |
Correct |
13 ms |
7136 KB |
Output is correct |
13 |
Correct |
16 ms |
7216 KB |
Output is correct |
14 |
Correct |
16 ms |
7228 KB |
Output is correct |
15 |
Correct |
16 ms |
7132 KB |
Output is correct |
16 |
Correct |
13 ms |
7116 KB |
Output is correct |
17 |
Correct |
18 ms |
7112 KB |
Output is correct |
18 |
Correct |
11 ms |
7136 KB |
Output is correct |
19 |
Correct |
1223 ms |
136072 KB |
Output is correct |
20 |
Correct |
1255 ms |
136136 KB |
Output is correct |
21 |
Correct |
1224 ms |
136092 KB |
Output is correct |
22 |
Correct |
1073 ms |
135304 KB |
Output is correct |
23 |
Correct |
1058 ms |
135436 KB |
Output is correct |
24 |
Correct |
1072 ms |
134600 KB |
Output is correct |
25 |
Correct |
1194 ms |
136120 KB |
Output is correct |
26 |
Correct |
1208 ms |
135920 KB |
Output is correct |
27 |
Correct |
1210 ms |
135856 KB |
Output is correct |
28 |
Correct |
977 ms |
135144 KB |
Output is correct |
29 |
Correct |
982 ms |
135168 KB |
Output is correct |
30 |
Correct |
828 ms |
134148 KB |
Output is correct |
31 |
Correct |
1302 ms |
136484 KB |
Output is correct |
32 |
Correct |
1318 ms |
136440 KB |
Output is correct |
33 |
Correct |
1190 ms |
136120 KB |
Output is correct |
34 |
Correct |
1108 ms |
135692 KB |
Output is correct |
35 |
Correct |
1164 ms |
135684 KB |
Output is correct |
36 |
Correct |
1123 ms |
134724 KB |
Output is correct |
37 |
Correct |
1301 ms |
136496 KB |
Output is correct |
38 |
Correct |
1318 ms |
136596 KB |
Output is correct |
39 |
Correct |
1298 ms |
136640 KB |
Output is correct |
40 |
Correct |
947 ms |
135124 KB |
Output is correct |
41 |
Correct |
994 ms |
135236 KB |
Output is correct |
42 |
Correct |
876 ms |
134164 KB |
Output is correct |
43 |
Correct |
1388 ms |
138440 KB |
Output is correct |
44 |
Correct |
1385 ms |
138556 KB |
Output is correct |
45 |
Correct |
1372 ms |
138388 KB |
Output is correct |
46 |
Correct |
1160 ms |
136900 KB |
Output is correct |
47 |
Correct |
1228 ms |
136956 KB |
Output is correct |
48 |
Correct |
1090 ms |
134432 KB |
Output is correct |
49 |
Correct |
1304 ms |
138308 KB |
Output is correct |
50 |
Correct |
1361 ms |
138476 KB |
Output is correct |
51 |
Correct |
1350 ms |
138192 KB |
Output is correct |
52 |
Correct |
1045 ms |
136768 KB |
Output is correct |
53 |
Correct |
1031 ms |
135952 KB |
Output is correct |