#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) int(x.size())
typedef pair<int,int>ii;
typedef vector<int> vi;
const int mxn=1e5+5;
int n,q,a[mxn],b[mxn],ans[mxn],arr[mxn],ai[mxn],bi[mxn];
vector<ii>tmp;
int bit[2][mxn];
struct t{
int x,y,z,id,xi,yi;
};
vector<t>aux;
void upd(int k,int pos,int val){
for(;pos<mxn;pos+=pos&-pos)bit[k][pos]+=val;
}
int query(int k,int pos){
int sum=0;
for(;pos>0;pos-=pos&-pos)sum+=bit[k][pos];
return sum;
}
vector<ii> cmp[2];
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);
//setIO("sort");
cin>>n>>q;
for(int i=0;i<n;i++){
cin>>a[i]>>b[i];
cmp[0].pb({a[i],i});
cmp[1].pb({b[i],i});
}
for(int i=0;i<2;i++)sort(cmp[i].begin(),cmp[i].end());
for(int i=0;i<q;i++){
int x,y,z;cin>>x>>y>>z;
auto it=lower_bound(cmp[0].begin(),cmp[0].end(),ii(x,-1));
int xi=(it-cmp[0].begin())+1;
auto it1=lower_bound(cmp[1].begin(),cmp[1].end(),ii(y,-1));
int yi=(it1-cmp[1].begin())+1;
aux.pb({x,y,z,i,xi,yi});
}
for(int i=0;i<sz(cmp[0]);i++){
ai[cmp[0][i].second]=i+1;
}
for(int i=0;i<sz(cmp[1]);i++){
bi[cmp[1][i].second]=i+1;
}
for(int i=0;i<n;i++)arr[i]=i;
sort(arr,arr+n,[](int x,int y){return a[x]+b[x]<a[y]+b[y];});
sort(aux.begin(),aux.end(),[](t a,t b){return max(a.x+a.y,a.z)<max(b.x+b.y,b.z);});
for(int tmp=0;tmp<n;tmp++){
int i=arr[tmp];
upd(0,ai[i],1);
upd(1,bi[i],1);
}
int i=0;
for(int j=0;j<q;j++){
while(a[arr[i]]+b[arr[i]]<max(aux[j].x+aux[j].y,aux[j].z)){
upd(0,ai[arr[i]],-1);
upd(1,bi[arr[i]],-1);
i++;
}
int sub=0;
sub+=query(0,aux[j].xi-1);
sub+=query(1,aux[j].yi-1);
ans[aux[j].id]=n-i-sub;
}
for(int i=0;i<q;i++)cout<<ans[i]<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3058 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
10192 KB |
Output is correct |
2 |
Correct |
159 ms |
10580 KB |
Output is correct |
3 |
Execution timed out |
3040 ms |
9936 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
10192 KB |
Output is correct |
2 |
Correct |
159 ms |
10580 KB |
Output is correct |
3 |
Execution timed out |
3040 ms |
9936 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3058 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |