请问各位大佬有没有知道原因的,我的代码没有过测试样例3,但是我提交之后却AC了(评测记录)。代码如下:
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 4e7+10, MOD = (1 << 30);
typedef long long LL;
typedef pair<LL, int> PII;
int n, type, p[N], ff = 1, tt = 1;
LL sum[N];
PII q[N];
void input()
{
cin >> n >> type;
if(!type)
{
for(int i = 1; i <= n; i++) cin >> sum[i];
}
else
{
int x, y, z, b1, b2, b3, m;
int i = 1;
cin >> x >> y >> z >> b2 >> b3 >> m;
while(m--)
{
int p, l, r;
cin >> p >> l >> r;
for(; i <= p; i++)
{
if(i > 2)
{
b1 = b2;
b2 = b3;
b3 = (1ll*x*b2+1ll*y*b1+z)%MOD;
}
if(i == 1) sum[i] = (b2%(r-l+1))+l;
else sum[i] = (b3%(r-l+1))+l;
}
}
}
for(int i = 2; i <= n; i++) sum[i] += sum[i-1];
}
void output()
{
if(!type)
{
LL ans = 0;
for(int i = n; i; i = p[i]) ans += (sum[i]-sum[p[i]])*(sum[i]-sum[p[i]]);
cout << ans;
}
else
{
__int128 ans = 0, ans1 = 0;
for(int i = n; i; i = p[i]) ans += (__int128)(sum[i]-sum[p[i]])*(sum[i]-sum[p[i]]);
while(ans)
{
ans1 = ans1*10+ans%10;
ans /= 10;
}
while(ans1)
{
cout << (int)(ans1%10);
ans1 /= 10;
}
}
}
PII find(LL x)
{
int l = ff, r = tt-1;
while(l < r)
{
int mid = (l+r+1) >> 1;
if(q[mid].first <= x) l = mid;
else r = mid-1;
}
return q[l];
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
input();
q[tt++] = {0, 0};
q[tt++] = {sum[1]+sum[1], 1};
for(int i = 2; i <= n; i++)
{
PII j = find(sum[i]);
p[i] = j.second;
PII numi = {sum[i]+sum[i]-sum[p[i]], i};
while(ff < tt && q[ff].first < j.first) ++ff;
while(ff < tt && q[tt-1].first >= numi.first) --tt;
q[tt++] = numi;
}
output();
return 0;
}
样例3如下:
输入:
10000000 1
123 456 789 12345 6789 3
2000000 123456789 987654321
7000000 234567891 876543219
10000000 456789123 567891234
标准输出:
4972194419293431240859891640
本地答案:
497219441929343124085989164