#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;
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];
}
//cout<<l<<' '<<r<<' ';
//cout<<'\n';
}
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(a);
temp.pb(b);
temp.pb(c);
}
for(int i=0;i<q;i++){
int a,b,c;
cin>>a>>b>>c;
vec.pb({a,b,c});
temp.pb(a);
temp.pb(b);
temp.pb(c);
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 |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4560 KB |
Output is correct |
5 |
Correct |
1 ms |
4692 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
7 ms |
5332 KB |
Output is correct |
8 |
Correct |
9 ms |
5332 KB |
Output is correct |
9 |
Correct |
8 ms |
5344 KB |
Output is correct |
10 |
Correct |
7 ms |
7128 KB |
Output is correct |
11 |
Correct |
7 ms |
7128 KB |
Output is correct |
12 |
Incorrect |
6 ms |
3288 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
32484 KB |
Output is correct |
2 |
Correct |
244 ms |
31632 KB |
Output is correct |
3 |
Correct |
239 ms |
31364 KB |
Output is correct |
4 |
Correct |
246 ms |
31360 KB |
Output is correct |
5 |
Correct |
192 ms |
32044 KB |
Output is correct |
6 |
Incorrect |
201 ms |
32360 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
32484 KB |
Output is correct |
2 |
Correct |
244 ms |
31632 KB |
Output is correct |
3 |
Correct |
239 ms |
31364 KB |
Output is correct |
4 |
Correct |
246 ms |
31360 KB |
Output is correct |
5 |
Correct |
192 ms |
32044 KB |
Output is correct |
6 |
Incorrect |
201 ms |
32360 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4560 KB |
Output is correct |
5 |
Correct |
1 ms |
4692 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
7 ms |
5332 KB |
Output is correct |
8 |
Correct |
9 ms |
5332 KB |
Output is correct |
9 |
Correct |
8 ms |
5344 KB |
Output is correct |
10 |
Correct |
7 ms |
7128 KB |
Output is correct |
11 |
Correct |
7 ms |
7128 KB |
Output is correct |
12 |
Incorrect |
6 ms |
3288 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |