QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#457879 | #7408. Determination | rqoi031 | WA | 0ms | 9648kb | C++20 | 3.2kb | 2024-06-29 14:35:11 | 2024-06-29 14:35:12 |
Judging History
answer
#include<stdio.h>
#include<algorithm>
#include<cstdlib>
typedef unsigned int uint;
typedef unsigned long long ull;
constexpr uint mod(1000000007);
constexpr uint plus(const uint &x,const uint &y) {
if(x+y>=mod) {
return x+y-mod;
}
return x+y;
}
constexpr uint minus(const uint &x,const uint &y) {
if(x<y) {
return x-y+mod;
}
return x-y;
}
constexpr uint power(uint x,uint y) {
uint s(1);
while(y>0) {
if(y&1) {
s=ull(s)*x%mod;
}
x=ull(x)*x%mod;
y>>=1;
}
return s;
}
char __begin__;
uint d[1000005];
int p[1000005];
uint a[1000005],b[1000005];
// states:
// 0: never use x and never use u
// 1: never use x but u is already used
// 2: x is already used but never used u
// 3: x is already used and u is already used
// auxiliary states:
// 4: a chain of type A is reserved for a special operation
// 5: a chain of type B is reserved for a special operation
uint dp[1000005][6];
char __end__;
int main() {
fprintf(stderr,"memory: %lldMB\n",std::abs(&__end__-&__begin__)>>20);
int n;uint x;
while(scanf("%d%u",&n,&x)==2) {
for(int i=1;i<=n;i++) {
scanf("%u",d+i),d[i]=minus(d[i],x);
}
for(int i=2;i<=n;i++) {
scanf("%d%u%u",p+i,a+i,b+i);
// pay attention that a[i] is -a_i
a[i]=minus(x,a[i]);
b[i]=minus(x,b[i]);
}
for(int u=1;u<=n;u++) {
dp[u][0]=1;
dp[u][1]=0;
dp[u][2]=0;
dp[u][3]=x;
dp[u][4]=0;
dp[u][5]=0;
}
for(int u=n;u>1;u--) {
const int v(p[u]);
uint t[6]{};
std::copy(dp[v],dp[v]+6,t);
std::fill(dp[v],dp[v]+6,0);
// do nothing
const uint s0((ull(dp[u][0])*d[u]+dp[u][1])%mod);
const uint s1((ull(dp[u][2])*d[u]+dp[u][3])%mod);
// fprintf(stderr," s0 = %u, s1 = %u\n",s0,s1);
dp[v][0]=(dp[v][0]+ull(t[0])*s0)%mod;
dp[v][2]=(dp[v][2]+ull(t[0])*s1)%mod;
dp[v][1]=(dp[v][1]+ull(t[1])*s0)%mod;
dp[v][3]=(dp[v][3]+ull(t[1])*s1)%mod;
dp[v][2]=(dp[v][2]+ull(t[2])*s0)%mod;
dp[v][3]=(dp[v][3]+ull(t[3])*s0)%mod;
dp[v][4]=(dp[v][4]+ull(t[4])*s0)%mod;
dp[v][5]=(dp[v][5]+ull(t[5])*s0)%mod;
// ordinary operation (u contributes -a_u*b_u)
dp[v][1]=(dp[v][1]+ull(t[0])*dp[u][0]%mod*(mod-a[u])%mod*b[u])%mod;
dp[v][3]=(dp[v][3]+(ull(t[2])*dp[u][0]+ull(t[0])*dp[u][2])%mod*(mod-a[u])%mod*b[u])%mod;
// special operation (u contributes -a_u)
const uint t0(ull(dp[u][4]+dp[u][0])*a[u]%mod);
dp[v][4]=(dp[v][4]+ull(t[0])*t0)%mod;
dp[v][3]=(dp[v][3]+ull(t[5]+t[0])*t0%mod*x)%mod;
const uint t1(ull(dp[u][5]+dp[u][0])*b[u]%mod);
dp[v][5]=(dp[v][5]+ull(t[0])*t1)%mod;
dp[v][3]=(dp[v][3]+ull(t[4]+t[0])*t1%mod*x)%mod;
}
const uint ans((ull(dp[1][0]+dp[1][2])*d[1]+dp[1][1]+dp[1][3])%mod);
printf("%u\n",ans);
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 9648kb
input:
3 1 23333 233 3 1 1 1 1 1 2 3 1 4 5 3 1 2 3 4 1 4 5 2 6 7
output:
16285968 14 40
result:
wrong answer 1st numbers differ - expected: '233', found: '16285968'