社区讨论
88pts最后三个点不过求助
P5665[CSP-S 2019] 划分参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mdgv9qsx
- 此快照首次捕获于
- 2025/07/24 12:02 8 个月前
- 此快照最后确认于
- 2025/07/24 16:41 8 个月前
如题用的__int128:
CPP#include<bits/stdc++.h>
using namespace std;
#define ll __int128
#define LL long long
const int N=4e7+5;
const int mod=(1<<30)-1;
int n,type,q[N],a,p[N],g[N],l[N],head=1,tail=1,r[N],b[N];
ll ans;
ll sum[N];
template<typename T>
void read(T &x) {
x = 0; char c = getchar(); bool s = 0;
for (; !isdigit(c); c = getchar()) s ^= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
if (s) x = -x;
}
template<typename T>
void write(T x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
return;
}
int main(){
read(n);read(type);
if(type){
LL x,y,z,b1,b2,m;
read(x);read(y);read(z);read(b1);read(b2);read(m);b[1]=b1;b[2]=b2;
for(LL i=3;i<=n;i++)b[i]=((LL)b[i-1]*x+b[i-2]*y+z)%mod;
for(LL i=1;i<=m;i++){
read(p[i]);read(l[i]);read(r[i]);
for(LL j=p[i-1]+1;j<=p[i];j++){
a=((LL)b[j]%((LL)r[i]-l[i]+1))+l[i];
sum[j]=sum[j-1]+a;
}
}
}
else{
for(int i=1;i<=n;i++)read(a),sum[i]=sum[i-1]+a;
}
for(int i=1;i<=n;i++){
while(head<tail&&(sum[q[head+1]]<<1)-sum[g[q[head+1]]]<=sum[i])head++;
g[i]=q[head];
while(head<=tail&&(sum[q[tail]]<<1)-sum[g[q[tail]]]>=(sum[i]<<1)-sum[g[i]])tail--;
q[++tail]=i;
}
for(int p=n;p;p=g[p]){
ll tmp=sum[p]-sum[g[p]];
ans+=tmp*tmp;
}
write(ans);
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...