#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())
#define __lg(x) 63-__builtin_clzll(x)
#define pow2(x) (1LL<<x)
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
struct line{
int a,b;
int operator()(const int x)const{
return a*x+b;
}
};
bool check(line l1,line l2,line l3){
return (l3.b-l2.b)*(l1.a-l2.a)<=(l2.b-l1.b)*(l2.a-l3.a);
}
struct node{
int x,y,z,tf;
bool operator <(const node b)const{
return z>b.z;
}
};
const int mxn=6e5+5;
vector<node>vec;
node upd[mxn];
int bit[mxn];
int ans[mxn];
void modify(int p,int v){
p++;
for(;p<mxn;p+=p&-p){
bit[p]+=v;
}
}
int query(int p){
p++;
int res=0;
for(;p;p-=p&-p){
res+=bit[p];
}
return res;
}
void cdq(int l,int r){
if(l>=r)return;
int mm=l+r>>1;
cdq(l,mm);
cdq(mm+1,r);
int L=l,R=mm+1;
vector<int>undo;
int p=l;
while(L<=mm or R<=r){
if(R>r or (L<=mm and vec[L].x>=vec[R].x)){
if(!vec[L].tf){
modify(vec[L].y,1);
undo.pb(vec[L].y);
}
upd[p++]=vec[L];
L++;
}
else{
if(vec[R].tf){
//debug(vec[R].tf,mxn-2,vec[R].y-1,query(mxn-1)-query(vec[R].y-1));
ans[vec[R].tf-1]+=query(mxn-2)-query(vec[R].y-1);
}
upd[p++]=vec[R];
R++;
}
}
for(auto x:undo)modify(x,-1);
for(int i=l;i<=r;i++){
vec[i]=upd[i];
}
}
vector<int>temp;
void lisanhua(node& a){
a.x=lower_bound(all(temp),a.x)-temp.begin();
a.y=lower_bound(all(temp),a.y)-temp.begin();
a.z=lower_bound(all(temp),a.z)-temp.begin();
}
signed main(){
setio();
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,q;
cin>>n>>q;
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
int c=a+b;
vec.pb({a,b,c});
temp.pb(b);
}
for(int i=0;i<q;i++){
int a,b,c;
cin>>a>>b>>c;
vec.pb({a,b,c});
temp.pb(b);
vec.back().tf=i+1;
}
sort(all(vec));
sort(all(temp));
temp.resize(unique(all(temp))-temp.begin());
for(int i=0;i<n+q;i++){
lisanhua(vec[i]);
}
cdq(0,n+q);
for(int i=0;i<q;i++){
cout<<ans[i]<<'\n';
}
}
/*
input:
*/
Compilation message
examination.cpp: In function 'void cdq(long long int, long long int)':
examination.cpp:81:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
81 | int mm=l+r>>1;
| ~^~
examination.cpp: In function 'void setIO(std::string)':
examination.cpp:42:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
209 ms |
25840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
209 ms |
25840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |