#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma")
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
#define ll long long
//#define int ll
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 826
#endif
inline char readchar(){
const int maxn=1000000;
static char buf[maxn],*p=buf,*q=buf;
if(p==q&&(q=(p=buf)+fread(buf,1,maxn,stdin))==buf) return EOF;
else return *p++;
}
inline int readint(){
int c=readchar(),x=0,neg=0;
while((c<'0'||c>'9')&&c!='-'&&c!=EOF) c=readchar();
if(c=='-') neg=1,c=readchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^'0'),c=readchar();
return neg?-x:x;
}
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
const int maxn=200005;
//i_am_noob
struct item{
int x,y,z,id;
};
int n,m,ans[maxn];
item a[maxn];
struct BIT{
int n;
vector<int> val;
BIT(int _n){val.resize(_n+5),n=_n;}
void modify(int p, int x){for(++p; p<n+5; p+=p&-p) val[p]+=x;}
int query(int l, int r){
int res=0;
for(++r; r; r-=r&-r) res+=val[r];
for(; l; l-=l&-l) res-=val[l];
return res;
}
};
void solve(int l, int r){
if(l==r) return;
bug(l,r);
vector<item> vec1,vec2;
int mid=l+r>>1;
rep2(i,l,mid+1) vec1.pb(a[i]);
rep2(i,mid+1,r+1) vec2.pb(a[i]);
vector<int> vec;
for(auto& i: vec1) vec.pb(i.z);
for(auto& i: vec2) vec.pb(i.z);
sort(all(vec));
vec.resize(unique(all(vec))-vec.begin());
for(auto& i: vec1) i.z=lower_bound(all(vec),i.z)-vec.begin();
for(auto& i: vec2) i.z=lower_bound(all(vec),i.z)-vec.begin();
sort(all(vec1),[](item& i, item& j){return i.y>j.y;});
sort(all(vec2),[](item& i, item& j){return i.y>j.y;});
for(auto& i: vec1) bug(i.x,i.y,i.z,i.id);
for(auto& i: vec2) bug(i.x,i.y,i.z,i.id);
BIT bit(r-l+1);
int curl=0,curr=0;
while(curl<sz(vec1)){
if(curr==sz(vec2)||vec1[curl].y>vec2[curr].y){
if(vec1[curl].id!=-1){
bug(bit.query(vec1[curl].z,r-l));
ans[vec1[curl].id]+=bit.query(vec1[curl].z,r-l);
}
curl++;
}
else{
if(vec2[curr].id==-1){
bug(curl,curr);
bit.modify(vec2[curr].z,1);
}
curr++;
}
}
solve(l,mid),solve(mid+1,r);
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
#ifdef i_am_noob
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
freopen("output2.txt","w",stderr);
#endif
cin >> n >> m;
rep(n) cin >> a[i].x >> a[i].y;
rep(n) a[i].z=a[i].x+a[i].y,a[i].id=-1;
rep(m) cin >> a[n+i].x >> a[n+i].y >> a[n+i].z;
rep(m) a[n+i].id=i;
sort(a,a+n+m,[](item& i, item& j){return i.x<j.x;});
solve(0,n+m-1);
rep(m) cout << ans[i] << "\n";
return 0;
}
Compilation message
examination.cpp: In function 'void solve(int, int)':
examination.cpp:28:18: warning: statement has no effect [-Wunused-value]
28 | #define bug(...) 826
| ^~~
examination.cpp:70:5: note: in expansion of macro 'bug'
70 | bug(l,r);
| ^~~
examination.cpp:72:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
72 | int mid=l+r>>1;
| ~^~
examination.cpp:28:18: warning: statement has no effect [-Wunused-value]
28 | #define bug(...) 826
| ^~~
examination.cpp:85:24: note: in expansion of macro 'bug'
85 | for(auto& i: vec1) bug(i.x,i.y,i.z,i.id);
| ^~~
examination.cpp:85:15: warning: unused variable 'i' [-Wunused-variable]
85 | for(auto& i: vec1) bug(i.x,i.y,i.z,i.id);
| ^
examination.cpp:28:18: warning: statement has no effect [-Wunused-value]
28 | #define bug(...) 826
| ^~~
examination.cpp:86:24: note: in expansion of macro 'bug'
86 | for(auto& i: vec2) bug(i.x,i.y,i.z,i.id);
| ^~~
examination.cpp:86:15: warning: unused variable 'i' [-Wunused-variable]
86 | for(auto& i: vec2) bug(i.x,i.y,i.z,i.id);
| ^
examination.cpp:28:18: warning: statement has no effect [-Wunused-value]
28 | #define bug(...) 826
| ^~~
examination.cpp:92:17: note: in expansion of macro 'bug'
92 | bug(bit.query(vec1[curl].z,r-l));
| ^~~
examination.cpp:28:18: warning: statement has no effect [-Wunused-value]
28 | #define bug(...) 826
| ^~~
examination.cpp:99:17: note: in expansion of macro 'bug'
99 | bug(curl,curr);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
17 ms |
1004 KB |
Output is correct |
8 |
Correct |
17 ms |
1004 KB |
Output is correct |
9 |
Correct |
18 ms |
1004 KB |
Output is correct |
10 |
Correct |
15 ms |
876 KB |
Output is correct |
11 |
Incorrect |
17 ms |
876 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
697 ms |
16152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
697 ms |
16152 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
17 ms |
1004 KB |
Output is correct |
8 |
Correct |
17 ms |
1004 KB |
Output is correct |
9 |
Correct |
18 ms |
1004 KB |
Output is correct |
10 |
Correct |
15 ms |
876 KB |
Output is correct |
11 |
Incorrect |
17 ms |
876 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |