#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define dd(x) cout<<#x<<" is "<<x<<endl;
int ord(int a, int b, int c, int d){
return(a <= b and b<=c and c<=d);
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n,l; cin>>n>>l;
int x[n];
for(int i=0; i<n; i++) cin>>x[i];
sort(x,x+n);
int bs = x[0], be = x[n-1];
int q; cin>>q;
while(q--){
int s,e,t; cin>>s>>e>>t;
if(n==1){
int ans = 0;
ans += abs(bs - s);
ans += abs(bs - e)*2;
ans++;
if(ans <= t) cout<<"Yes\n";
else cout<<"No\n";
continue;
}
int sp = 1;
int ans=0;
if(ord(s,e,bs,be) or ord(e,s,bs,be) or ord(e,bs,be,s) or ord(e,bs,s,be)){
ans += abs(be-s);
sp++;
for(int i=n-1; i>0; i--){
ans += (x[i] - x[i-1])*sp;
sp++;
}
ans += abs(bs-e)*sp;
ans += n;
} else if(ord(bs,be,s,e) or ord(bs,be,e,s) or ord(s,bs,be,e) or ord(bs,s,be,e)){
ans += abs(s-bs);
sp++;
for(int i=0; i<n-1; i++){
ans += (x[i+1]-x[i])*sp;
sp++;
}
ans += abs(e-be)*sp;
ans += n;
} else if(ord(bs,s,e,be) or ord(s,bs,e,be)){
ans += abs(s-bs);
if(x[0] < e) sp++;
for(int i=0; i<n-1; i++){
if(x[i+1] < e){
ans += (x[i+1]-x[i])*sp;
sp++;
} else {
ans += (be-x[i])*sp;
break;
}
}
sp++;
for(int i=n-1; i>0; i--){
if(x[i-1] > e){
ans += (x[i]-x[i-1])*sp;
sp++;
} else {
ans += (x[i]-e)*sp;
break;
}
}
ans += n;
} else {
ans += abs(s-be);
if(x[n-1] > e) sp++;
for(int i=n-1; i>0; i--){
if(x[i-1] > e){
ans += (x[i]-x[i-1])*sp;
sp++;
} else {
ans += (x[i]-bs)*sp;
break;
}
}
sp++;
for(int i=0; i<n-1; i++){
if(x[i+1] < e){
ans += (x[i+1]-x[i])*sp;
sp++;
} else {
ans += (e-x[i])*sp;
break;
}
}
ans += n;
}
cout<<ans<<endl;
//if(ans <= t) cout<<"Yes\n";
//else cout<<"No\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |