#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];
map<int,int>mp;
int bit[2][5*mxn];
struct t{
int x,y,z,id;
};
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;
}
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];
mp[a[i]];
mp[b[i]];
}
for(int i=0;i<q;i++){
int x,y,z;cin>>x>>y>>z;
aux.pb({x,y,z,i});
mp[x];mp[y];
}
int T=0;
for(auto it=mp.begin();it!=mp.end();it++){
T++;
it->second=T;
}
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,mp[a[i]],1);
upd(1,mp[b[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,mp[a[arr[i]]],-1);
upd(1,mp[b[arr[i]]],-1);
i++;
}
int sub=0;
sub+=query(0,mp[aux[j].x]-1);
sub+=query(1,mp[aux[j].y]-1);
ans[aux[j].id]=n-i-sub;
}
for(int i=0;i<q;i++)cout<<ans[i]<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3053 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
431 ms |
11948 KB |
Output is correct |
2 |
Correct |
444 ms |
12252 KB |
Output is correct |
3 |
Runtime error |
674 ms |
20336 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
431 ms |
11948 KB |
Output is correct |
2 |
Correct |
444 ms |
12252 KB |
Output is correct |
3 |
Runtime error |
674 ms |
20336 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3053 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |