第一题:储物点的距离
前缀和,求距离前缀和,以及数量前缀和,以及花费的前缀和
数据很烦,必须不断取模
#include<iostream>
using namespace std;
typedef long long LL;
const int N = 200010, MOD = 1000000007;
LL a[N], b[N], c[N];
int n, m;
int main(){
scanf("%d%d", &n, &m);
for(int i = 2; i <= n; i++) {
scanf("%lld", &a[i]);
a[i] = (a[i] + a[i - 1]) % MOD;
}
for(int i = 1; i <= n; i++) {
scanf("%lld", &b[i]);
c[i] = (c[i - 1] + a[i] * b[i] % MOD) % MOD;
b[i] = (b[i] + b[i - 1]) % MOD;
}
while(m--){
int x, l, r;
scanf("%d%d%d", &x, &l, &r);
LL ans = 0;
if (x <= l) {
ans = (c[r] - c[l - 1] + MOD) % MOD;
ans = (ans - (b[r] - b[l - 1] + MOD) % MOD * a[x] % MOD + MOD) % MOD;
}
else if (x >= r) {
ans = (b[r] - b[l - 1] + MOD) % MOD * a[x] % MOD;
ans = (ans - (c[r] - c[l - 1] + MOD) % MOD + MOD) % MOD;
}
else {
ans = (c[r] - c[x] + MOD) % MOD;
ans = (ans - (b[r] - b[x] + MOD) % MOD * a[x] % MOD + MOD) % MOD;
ans = (ans + (b[x] - b[l - 1] + MOD) % MOD * a[x] % MOD - (c[x] - c[l - 1] + MOD) % MOD + MOD) % MOD;
}
cout<<ans<<endl;
}
return 0;
}
第二题:
待更