/* code by the cute PixelCat owo */
/* as cute as nyachoneko chan! */
#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
//#define int LL //__int128
#define double long double
using namespace std;
using LL=long long;
using uLL=unsigned long long;
using pii=pair<int,int>;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fors(i,a,b,s) for(int i=a;i<=b;i+=s)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define L(id) (id*2+1)
#define R(id) (id*2+2)
#define LO(x) (x&(-x))
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair
#define MOD (int)(1000000007)
#define INF (int)(1e17)
#define EPS (1e-6)
#ifdef NYAOWO
#define debug(...) do{\
cerr << __LINE__ <<\
" : ("#__VA_ARGS__ << ") = ";\
_OUT(__VA_ARGS__);\
cerr << flush;\
}while(0)
template<typename T> void _OUT(T _X) { cerr << _X << "\n"; }
template<typename T,typename...I>
void _OUT(T _X,I ...tail) { cerr << _X << ", "; _OUT(tail...); }
inline void USACO(const string &s) { cerr<<"USACO: "<<s<<"\n"; }
#else
#define debug(...)
inline void USACO(const string &s){
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
#endif
inline void NYA(){ ios::sync_with_stdio(false); cin.tie(0); }
inline int gcd(int a,int b) { return __gcd(a,b); }
inline int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p,const int &mod){
int ans=1;
while(p){
if(p&1) ans=ans*b%mod;
p/=2; b=b*b%mod;
}
return ans;
}
int fpow(int b,int p) { return fpow(b,p,MOD); }
template<typename T> inline void chmin(T &_a,const T &_b) { if(_b<_a) _a=_b; }
template<typename T> inline void chmax(T &_a,const T &_b) { if(_b>_a) _a=_b; }
template<typename T1,typename T2>
ostream& operator<<(ostream &os,pair<T1,T2> p){
os<<"("<<p.F<<","<<p.S<<")";
return os;
}
template<typename T>
ostream& operator<<(ostream &os,const vector<T> &v){
os<<"[";
for(auto &i:v)
os<<" "<<i<<",";
os<<"]";
return os;
}
template<typename T>
ostream& operator<<(ostream &os,const deque<T> &v){
os<<"[";
for(auto &i:v)
os<<" "<<i<<",";
os<<"]";
return os;
}
template<typename T1,typename T2>
ostream& operator<<(ostream &os,const map<T1,T2> &v){
os<<"[";
for(auto &i:v)
os<<" "<<i.F<<":"<<i.S<<",";
os<<"]";
return os;
}
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define MAXN 100000
struct SegTree{
int l[MAXN*4+10];
int r[MAXN*4+10];
vector<int> y[MAXN*4+10];
void build(int id,vector<pii> &v,int L,int R){
l[id]=v[L].F;
r[id]=v[R].F;
y[id].clear();
For(i,L,R){
y[id].eb(v[i].S);
}
sort(all(y[id]));
if(L==R) return;
int m=(L+R)/2;
build(L(id),v,L,m);
build(R(id),v,m+1,R);
}
int ask(int id,int L,int R,int Y){
if(l[id]>R || r[id]<L) return 0;
if(l[id]>=L && r[id]<=R)
return sz(y[id])-(lower_bound(all(y[id]),Y)-y[id].begin());
return ask(L(id),L,R,Y)+ask(R(id),L,R,Y);
}
}seg1,seg2;
int32_t main(){
NYA();
//nyaacho >/////<
int N,Q; cin>>N>>Q;
vector<pii> v(N);
for(auto &i:v)
cin>>i.F>>i.S;
sort(all(v));
seg1.build(0,v,0,N-1);
for(auto &i:v)
i.S+=i.F;
seg2.build(0,v,0,N-1);
int e9=1000000010;
while(Q--){
int x,y,z; cin>>x>>y>>z;
int x2=max(x,z-y);
cout<<(seg1.ask(0,x2,e9,y)+seg2.ask(0,x,x2-1,z))<<"\n";
//cout<<(seg1.ask(0,x2,e9,y))<<" "<<(seg2.ask(0,x,x2-1,z))<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19020 KB |
Output is correct |
2 |
Correct |
11 ms |
19104 KB |
Output is correct |
3 |
Correct |
11 ms |
19124 KB |
Output is correct |
4 |
Correct |
12 ms |
19124 KB |
Output is correct |
5 |
Correct |
11 ms |
19028 KB |
Output is correct |
6 |
Correct |
13 ms |
19032 KB |
Output is correct |
7 |
Correct |
20 ms |
20044 KB |
Output is correct |
8 |
Correct |
20 ms |
20044 KB |
Output is correct |
9 |
Correct |
20 ms |
20044 KB |
Output is correct |
10 |
Correct |
18 ms |
20044 KB |
Output is correct |
11 |
Correct |
18 ms |
20028 KB |
Output is correct |
12 |
Correct |
17 ms |
19988 KB |
Output is correct |
13 |
Correct |
20 ms |
20028 KB |
Output is correct |
14 |
Correct |
19 ms |
20068 KB |
Output is correct |
15 |
Correct |
20 ms |
20032 KB |
Output is correct |
16 |
Correct |
16 ms |
20020 KB |
Output is correct |
17 |
Correct |
18 ms |
20044 KB |
Output is correct |
18 |
Correct |
16 ms |
19916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
478 ms |
53188 KB |
Output is correct |
2 |
Correct |
497 ms |
53172 KB |
Output is correct |
3 |
Correct |
489 ms |
53200 KB |
Output is correct |
4 |
Correct |
384 ms |
52492 KB |
Output is correct |
5 |
Correct |
283 ms |
52516 KB |
Output is correct |
6 |
Correct |
208 ms |
51752 KB |
Output is correct |
7 |
Correct |
447 ms |
53060 KB |
Output is correct |
8 |
Correct |
445 ms |
53152 KB |
Output is correct |
9 |
Correct |
438 ms |
53056 KB |
Output is correct |
10 |
Correct |
206 ms |
52364 KB |
Output is correct |
11 |
Correct |
303 ms |
52300 KB |
Output is correct |
12 |
Correct |
159 ms |
51372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
478 ms |
53188 KB |
Output is correct |
2 |
Correct |
497 ms |
53172 KB |
Output is correct |
3 |
Correct |
489 ms |
53200 KB |
Output is correct |
4 |
Correct |
384 ms |
52492 KB |
Output is correct |
5 |
Correct |
283 ms |
52516 KB |
Output is correct |
6 |
Correct |
208 ms |
51752 KB |
Output is correct |
7 |
Correct |
447 ms |
53060 KB |
Output is correct |
8 |
Correct |
445 ms |
53152 KB |
Output is correct |
9 |
Correct |
438 ms |
53056 KB |
Output is correct |
10 |
Correct |
206 ms |
52364 KB |
Output is correct |
11 |
Correct |
303 ms |
52300 KB |
Output is correct |
12 |
Correct |
159 ms |
51372 KB |
Output is correct |
13 |
Correct |
565 ms |
53584 KB |
Output is correct |
14 |
Correct |
539 ms |
53552 KB |
Output is correct |
15 |
Correct |
479 ms |
53232 KB |
Output is correct |
16 |
Correct |
477 ms |
52804 KB |
Output is correct |
17 |
Correct |
303 ms |
52804 KB |
Output is correct |
18 |
Correct |
222 ms |
51764 KB |
Output is correct |
19 |
Correct |
560 ms |
53524 KB |
Output is correct |
20 |
Correct |
615 ms |
53684 KB |
Output is correct |
21 |
Correct |
611 ms |
53556 KB |
Output is correct |
22 |
Correct |
209 ms |
52188 KB |
Output is correct |
23 |
Correct |
298 ms |
52240 KB |
Output is correct |
24 |
Correct |
175 ms |
51268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19020 KB |
Output is correct |
2 |
Correct |
11 ms |
19104 KB |
Output is correct |
3 |
Correct |
11 ms |
19124 KB |
Output is correct |
4 |
Correct |
12 ms |
19124 KB |
Output is correct |
5 |
Correct |
11 ms |
19028 KB |
Output is correct |
6 |
Correct |
13 ms |
19032 KB |
Output is correct |
7 |
Correct |
20 ms |
20044 KB |
Output is correct |
8 |
Correct |
20 ms |
20044 KB |
Output is correct |
9 |
Correct |
20 ms |
20044 KB |
Output is correct |
10 |
Correct |
18 ms |
20044 KB |
Output is correct |
11 |
Correct |
18 ms |
20028 KB |
Output is correct |
12 |
Correct |
17 ms |
19988 KB |
Output is correct |
13 |
Correct |
20 ms |
20028 KB |
Output is correct |
14 |
Correct |
19 ms |
20068 KB |
Output is correct |
15 |
Correct |
20 ms |
20032 KB |
Output is correct |
16 |
Correct |
16 ms |
20020 KB |
Output is correct |
17 |
Correct |
18 ms |
20044 KB |
Output is correct |
18 |
Correct |
16 ms |
19916 KB |
Output is correct |
19 |
Correct |
478 ms |
53188 KB |
Output is correct |
20 |
Correct |
497 ms |
53172 KB |
Output is correct |
21 |
Correct |
489 ms |
53200 KB |
Output is correct |
22 |
Correct |
384 ms |
52492 KB |
Output is correct |
23 |
Correct |
283 ms |
52516 KB |
Output is correct |
24 |
Correct |
208 ms |
51752 KB |
Output is correct |
25 |
Correct |
447 ms |
53060 KB |
Output is correct |
26 |
Correct |
445 ms |
53152 KB |
Output is correct |
27 |
Correct |
438 ms |
53056 KB |
Output is correct |
28 |
Correct |
206 ms |
52364 KB |
Output is correct |
29 |
Correct |
303 ms |
52300 KB |
Output is correct |
30 |
Correct |
159 ms |
51372 KB |
Output is correct |
31 |
Correct |
565 ms |
53584 KB |
Output is correct |
32 |
Correct |
539 ms |
53552 KB |
Output is correct |
33 |
Correct |
479 ms |
53232 KB |
Output is correct |
34 |
Correct |
477 ms |
52804 KB |
Output is correct |
35 |
Correct |
303 ms |
52804 KB |
Output is correct |
36 |
Correct |
222 ms |
51764 KB |
Output is correct |
37 |
Correct |
560 ms |
53524 KB |
Output is correct |
38 |
Correct |
615 ms |
53684 KB |
Output is correct |
39 |
Correct |
611 ms |
53556 KB |
Output is correct |
40 |
Correct |
209 ms |
52188 KB |
Output is correct |
41 |
Correct |
298 ms |
52240 KB |
Output is correct |
42 |
Correct |
175 ms |
51268 KB |
Output is correct |
43 |
Correct |
556 ms |
55608 KB |
Output is correct |
44 |
Correct |
558 ms |
55528 KB |
Output is correct |
45 |
Correct |
571 ms |
55552 KB |
Output is correct |
46 |
Correct |
451 ms |
53932 KB |
Output is correct |
47 |
Correct |
289 ms |
53980 KB |
Output is correct |
48 |
Correct |
210 ms |
51528 KB |
Output is correct |
49 |
Correct |
616 ms |
55596 KB |
Output is correct |
50 |
Correct |
536 ms |
55416 KB |
Output is correct |
51 |
Correct |
704 ms |
55340 KB |
Output is correct |
52 |
Correct |
214 ms |
53828 KB |
Output is correct |
53 |
Correct |
312 ms |
53028 KB |
Output is correct |