QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#590099#8237. Sugar Sweet IIucup-team3294WA 193ms22308kbC++202.9kb2024-09-25 21:35:172024-09-25 21:35:17

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-09-25 21:35:17]
  • 评测
  • 测评结果:WA
  • 用时:193ms
  • 内存:22308kb
  • [2024-09-25 21:35:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=5e5+10;
const int mod=1e9+7;
#define ll long long
struct node
{
    int to;
};
vector<node> h[N];
int dis[N];
int n;
int a[N],b[N],w[N];
int d[N];
ll fact[N],infact[N];
int ans=0;
int color[N];
int kk[N];
ll qmi(ll a,ll b,ll p)
{
    ll cnt=1;
    while(b)
    {
        if(b&1) cnt=(cnt*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return cnt;
}
void add(int a,int b)
{
    h[a].push_back({b});
    d[b]++;
}
void bfs(int pos)
{
    queue<int> q;
    q.push(pos);
    dis[pos]=1;
    while(q.size())
    {
        auto t=q.front();
        q.pop();
        for(int i=0;i<h[t].size();i++)
        {
            int j=h[t][i].to;
            if(dis[j]!=0) continue;
            dis[j]=dis[t]+1;
            d[j]--;
            kk[j]=infact[dis[j]]*(a[j]+w[j])%mod+(1-infact[dis[j]]+mod)%mod*a[j]%mod;
          //  ans=(ans+infact[dis[j]]*w[j]%mod)%mod;
            q.push(j);
        }
    }

}
void solve()
{
    for(int i=1;i<=n;i++)
    {
        h[i].clear();
        d[i]=0;
        dis[i]=0;
        color[i]=0;
    }
    ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>b[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>w[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(a[b[i]]<=a[i]&&a[b[i]]+w[b[i]]>a[i]) //可能加
        {
           // cout<<b[i]<<"aa"<<i<<endl;
            color[i]=3;
           // add(b[i],i);
        }
        else if(a[b[i]]>a[i]) //百分百加
        {
            color[i]=1;
        }
        else color[i]=2; //注定不会加
    }
    for(int i=1;i<=n;i++)
    {
        if(a[b[i]]<=a[i]&&a[b[i]]+w[b[i]]>a[i])
        {
           // cout<<b[i]<<"ee"<<i<<endl;
            if(color[b[i]]==1||color[i]==3)
            {
                add(b[i],i);
               // cout<<b[i]<<"aa"<<i<<endl;
            }
            else
            {
                kk[i]=a[i];
            }
        }
        else if(a[b[i]]>a[i])
        {
            kk[i]=a[i]+w[i];
        }
        else kk[i]=a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(dis[i]==0&&d[i]==0) 
        {
            bfs(i);
            //cout<<i<<"aa"<<endl;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(d[i]!=0)
        {
            kk[i]=a[i];
        }
    }
    for(int i=1;i<=n;i++)
    {
        cout<<kk[i]<<' ';
    }
    cout<<endl;

}
signed main()
{
    //cout<<qmi(2,mod-2,mod)<<endl;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin>>T;
    fact[0]=infact[0]=1;
    for(ll i=1;i<N;i++)  //此处不能取到N,否则数组越界
    {
        fact[i]=(fact[i-1]*i)%mod;
        infact[i]=(infact[i-1]*qmi(i,mod-2,mod))%mod;
    }
    while(T--)
    {
        solve();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 48ms
memory: 22004kb

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 
500000006 4 3 4 5 

result:

ok 15 numbers

Test #2:

score: -100
Wrong Answer
time: 193ms
memory: 22308kb

input:

50000
5
508432375 168140163 892620793 578579275 251380640
3 4 4 1 3
346232959 736203130 186940774 655629320 607743104
1
863886789
1
364158084
18
864679185 463975750 558804051 604216585 694033700 499417132 375390750 337590759 467353355 111206671 983760005 984444619 322277587 138763925 205122047 97736...

output:

854665334 904343293 590444253 906393935 859123744 
863886789 
871186919 814243920 968784984 1206455481 1017527057 1449261420 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 1113628633 977360756 482247153 963066959 
665922935 577926775 1132646730 421298438 601054667 10...

result:

wrong answer 10th numbers differ - expected: '206455474', found: '1206455481'