QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#764041#8237. Sugar Sweet IIgray114514WA 4ms20320kbC++142.2kb2024-11-19 23:33:222024-11-19 23:33:22

Judging History

你现在查看的是最新测评结果

  • [2024-11-19 23:33:22]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:20320kb
  • [2024-11-19 23:33:22]
  • 提交

answer

#include<cstdio>
#include<bitset>
#include<cstring>
using namespace std;
typedef long long ll;
const int N = 5e5+10;
const ll mod = 1e9 + 7;
ll a[N] , b[N] , w[N] ,E[N] ,  n , T , inv2 , fac[N];
int h[N << 1] , nxt[N << 1] , to[N << 1] , tot , dep[N];
int tmp[N] , idx;
bitset<N> vis , st;
ll qmi(ll x,ll q)
{
    ll res = 1;
    while(q){
        if(q & 1) res = res * x % mod;
        x = x * x % mod;
        q >>= 1ll;
    }
    return res;
}
void add(int u,int v)
{
    nxt[++tot] = h[u] , to[tot] = v , h[u] = tot;
}
void dfs(int u,int fa)
{
    if(st[u]) return ;
    if(dep[fa]) dep[u] = dep[fa] + 1;
    else dep[u] = 0;
    E[u] = (a[u] + qmi(fac[dep[u]],mod-2) * w[u] % mod) % mod;
    st.set(u);
    for(int i=h[u];i;i=nxt[i]){
        int v = to[i];
        dfs(v,u);
    }
    return ;
}
int main()
{
    scanf("%d",&T);
    fac[1] = 1;
    for(int i=2;i<N;i++)
        fac[i] = (fac[i-1] * (ll)i) % mod;
    while(T--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for(int i=1;i<=n;i++)
            scanf("%d",&b[i]);
        for(int i=1;i<=n;i++)
            scanf("%d",&w[i]);
        int cur;
        for(int i=1;i<=n;i++){
            if(vis[i]) continue;
            idx = 0 , cur = i;
            while(!vis[cur]){
                vis[cur] = 1;
                if(b[cur] == cur) dep[cur] = 0 , E[cur] = a[cur] , st[cur] = 1;
                if(a[cur] >= a[b[cur]]+w[b[cur]])  dep[cur] = 0 , E[cur] = a[cur] , st[cur] = 1;
                else if(a[cur] < a[b[cur]]) dep[cur] = 1 , E[cur] = a[cur] + w[cur] , st[cur] = 1;
                add(b[cur],cur);
                tmp[++idx] = cur;
                cur = b[cur];
            }
        }
        for(int u=1;u<=n;u++){
            for(int i=h[u];i;i=nxt[i]){
                int v = to[i];
              //  printf("u = %d v = %d\n",u,v);
              //  if(v == u) break;
                if(!st.test(v) && st.test(u))
                    dfs(v,u);
            }
        }
        for(int i=1;i<=n;i++) 
            printf("%d ",E[i]);
        puts("");
        tot = 0;
        memset(h,0,sizeof(int) * n);
        for(int i=1;i<=n;i++)
            st.reset(i) , vis.reset(i);
    }
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 20320kb

input:

4
4
2 5 5 2
4 2 1 3
3 2 1 4
3
5 4 3
1 1 1
6 6 6
3
5 4 3
2 3 1
1 2 3
5
2 1 3 2 1
5 1 1 3 4
1 3 4 2 4

output:

500000007 5 5 6 
5 10 9 
166666673 5 6 
2 4 3 4 5 

result:

wrong answer 11th numbers differ - expected: '500000006', found: '2'