lichengxi1 @ 2024-10-01 23:44:21
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define int long long
const int MAXN = 5e5 + 10,Maxn = 1005;
int f[Maxn][Maxn][2][2],cnt[MAXN],a[MAXN],n,m,q;
signed main(){
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i = 1;i <= n;++i) cin >> a[i],cnt[a[i]]++;
for(int i = 1;i <= m;++i) cnt[i] += cnt[i - 1];
sort(a + 1,a + n + 1);
n = unique(a + 1,a + n + 1) - a - 1;
cin >> q;
if(n >= 1000){
while(q--) cout << "No" << endl;
return 0;
}
memset(f,0x3f,sizeof(f));
f[1][n][0][0] = f[1][n][1][1] = 0;
for(int len = n - 1;len >= 1;--len){
for(int l = 1;l + len - 1 <= n;++l){
int r = l + len - 1;
int res = cnt[m] - cnt[a[r]] + 1;
if(a[l]) res += cnt[a[l] - 1];
for(int i = 0;i <= 1;++i){
f[l][r][i][0] = min(f[l - 1][r][i][0] + res * (a[l] - a[l - 1]),f[l][r + 1][i][1] + res * (a[r + 1] - a[l]));
f[l][r][i][1] = min(f[l - 1][r][i][0] + res * (a[r] - a[l - 1]),f[l][r + 1][i][1] + res * (a[r + 1] - a[r]));
}
}
}
while(q--){
int l,r,t,ans = 1e9;
cin >> l >> r >> t;
if(r <= a[n]){
int p = lower_bound(a + 1,a + n + 1,r) - a;
ans = min(ans,abs(l - a[1]) + f[p][p][0][0] + (cnt[m] + 1) * abs(r - a[p]));
ans = min(ans,abs(l - a[n]) + f[p][p][1][0] + (cnt[m] + 1) * abs(r - a[p]));
}
if(t > a[1]){
int p = upper_bound(a + 1,a + n + 1,r) - a - 1;
ans = min(ans,abs(l - a[1]) + f[p][p][0][0] + (cnt[m] + 1) * abs(r - a[p]));
ans = min(ans,abs(l - a[n]) + f[p][p][1][0] + (cnt[m] + 1) * abs(r - a[p]));
}
if(ans + cnt[m] <= t) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
by dou_zi_ @ 2024-10-02 08:57:07
if(t > a[1])
改成if(r > a[1])
((((((
by lichengxi1 @ 2024-10-02 18:17:44
不是,这都能93分???
by lichengxi1 @ 2024-10-02 18:19:15
谢谢