问题标题: 酷町堂:5220RE找错

1
0
已解决
被禁言 李秉轩
李秉轩
修练者
修练者

#include <cstdio>

#include <vector>

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

 

typedef long long ll;

const int Maxn = 4e7;

 

struct BigInteger {

static const int BASE = 100000000;

int num[15], len;

BigInteger (ll x = 0) {

*this = x;

}

inline void clear(BigInteger &x) {

while(x.num[x.len] == 0 && x.len > 1)

x.len--;

}

BigInteger operator = (ll rhs) {

memset(num, 0, sizeof num);

len = 0;

do {

num[++len] = rhs % BASE;

rhs /= BASE;

} while(rhs != 0);

return *this;

}

BigInteger operator + (const BigInteger &rhs) {

BigInteger ret;

memset(ret.num, 0, sizeof ret.num), ret.len = 0;

for(int i = 1, tmp = 0; tmp != 0 || i <= len || i <= rhs.len; i++) {

tmp += num[i] + rhs.num[i];

ret.num[++ret.len] = tmp % BASE;

tmp /= BASE;

}

return ret;

}

BigInteger operator * (const BigInteger &rhs) {

BigInteger ret;

memset(ret.num, 0, sizeof ret.num), ret.len = len + rhs.len;

for(int i = 1; i <= len; i++) {

ll tmp = 0;

for(int j = 1; j <= rhs.len || tmp != 0; j++) {

tmp += 1LL * num[i] * rhs.num[j] + ret.num[i + j - 1];

ret.num[i + j - 1] = tmp % BASE;

tmp /= BASE;

}

}

clear(ret);

return ret;

}

BigInteger operator += (const BigInteger &rhs) {

*this = *this + rhs;

return *this;

}

BigInteger operator *= (const BigInteger &rhs) {

*this = *this * rhs;

return *this;

}

};

ostream &operator << (ostream &out, const BigInteger &x) {

out << x.num[x.len];

for(int i = x.len - 1; i >= 1; i--) {

char buf[20];

sprintf(buf, "%08d", x.num[i]);

out << buf;

}

return out;

}

 

int N;

ll sum[Maxn + 5];

 

ll B[Maxn + 5];

const ll mod = (1 << 30);

 

inline void ReadIn() {

int typ;

scanf("%d %d", &N, &typ);

if(typ == 0) {

for(int i = 1; i <= N; i++)

scanf("%lld", &sum[i]);

} else {

ll x, y, z;

scanf("%lld %lld %lld %lld %lld", &x, &y, &z, &B[1], &B[2]);

for(int i = 3; i <= N; i++)

B[i] = ((x * B[i - 1] % mod) + (y * B[i - 2] % mod) + z) % mod;

int m, las = 0, p;

scanf("%d", &m);

for(int i = 1; i <= m; i++) {

int l, r;

scanf("%d %d %d", &p, &l, &r);

for(int j = las + 1; j <= p; j++)

sum[j] = (B[j] % (r - l + 1)) + l;

las = p;

}

}

}

 

int f[Maxn + 5];

inline ll calc_val(int pos) {

return sum[pos] * 2 - sum[f[pos]];

}

 

int q[Maxn + 5], head, tail;

 

int main() {

#ifdef LOACL

freopen("in.txt", "r", stdin);

freopen("out.txt", "w", stdout);

#endif

ReadIn();

for(int i = 1; i <= N; i++)

sum[i] += sum[i - 1];

head = tail = 1;

for(int i = 1; i <= N; i++) {

while(head < tail && calc_val(q[head + 1]) <= sum[i])

head++;

f[i] = q[head];

while(head <= tail && calc_val(q[tail]) >= calc_val(i))

tail--;

q[++tail] = i;

}

BigInteger ans = 0;

int p = N;

while(p != 0) {

BigInteger tmp(sum[p] - sum[f[p]]);

ans += (tmp * tmp);

p = f[p];

}

cout << ans;

return 0;

}

李秉轩在2020-09-09 20:18:15追加了内容
  • 七星级题代码
  • #define N 103
    #define M 2003
    #define ac(x) (((x)+N))
    #define ll long long
    #define setIO(s) freopen(s".in","r",stdin)
    using namespace std;
    const int mod=998244353;
    ll sum[N];
    int a[N][M],g[N][N],f[N][N+N+233];
    int main()
    {
    // setIO("input");
    ll ans=0ll;
    int i,j,n,m,k;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;++i) for(j=1;j<=m;++j) scanf("%d",&a[i][j]), (sum[i]+=1ll*a[i][j])%=mod;
    g[0][0]=1, f[0][ac(0)]=1;
    for(i=1;i<=n;++i)
    {
    for(j=0;j<=i;++j)
    {
    g[i][j]=g[i-1][j];
    if(j>0) g[i][j]=(g[i][j]+1ll*g[i-1][j-1]*sum[i]%mod)%mod;
    }
    }
    for(i=1;i<=n;++i) (ans+=g[n][i])%=mod;
    for(int tmp=1;tmp<=m;++tmp)
    {
    for(i=1;i<=n;++i)
    {
    for(j=-i;j<=i;++j)
    {
    f[i][ac(j)]=f[i-1][ac(j)];
    if(j<i) (f[i][ac(j)]+=1ll*f[i-1][ac(j)+1]*(sum[i]-a[i][tmp])%mod)%=mod;
    if(j>-i) (f[i][ac(j)]+=1ll*f[i-1][ac(j)-1]*a[i][tmp]%mod)%=mod;
    }
    }
    for(i=1;i<=n;++i) ((ans-=f[n][ac(i)])+=mod)%=mod;
    for(i=1;i<=n;++i) for(j=-n;j<=n;++j) f[i][ac(j)]=0;
    }
    printf("%lld\n",ans);
    return 0;
    }

     


0
0
0
0
张恩泽
张恩泽
高级天翼
高级天翼

不是刷题求解吗,为什么你的点进去是刷题改造

 

0
张恩泽
张恩泽
高级天翼
高级天翼

不是刷题求解吗,为什么你的点进去是刷题改造

 

0
张恩泽
张恩泽
高级天翼
高级天翼

我这样输入,发出去的却是这个

这真是一个BUG!!

0
曹砚青
曹砚青
中级光能
中级光能

OH NO NO NO,7分!我真***不会呀!,

但我帮你顶一下吧

0
丁博扬
丁博扬
中级天翼
中级天翼

这是你从网上拷贝过来的吧

但我不会举报

我来帮你顶一下

顶顶顶顶

0
包涵宇
包涵宇
中级天翼
中级天翼

一看这种代码就知道是MX使用CC+CV做的

算法初级讲背包时才出现第一个7分题

我要回答