QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623540#8237. Sugar Sweet IIFXLY_awa#WA 123ms11276kbC++203.6kb2024-10-09 12:56:072024-10-09 12:56:08

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-09 12:56:08]
  • 评测
  • 测评结果:WA
  • 用时:123ms
  • 内存:11276kb
  • [2024-10-09 12:56:07]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


typedef long long                               ll;
typedef unsigned long long                      ull;
#define int                                     long long
#define itn                                     int
#define endl                                    '\n'
#define Endl                                    endl
#define ednl                                    endl
#define al(a)                                   (a).begin(),(a).end()
#define all(a)                                  (a).begin()+1,(a).end()
#define debug(x)                                {cerr<<"ss:"<<x<<endl;}
#define qdebug(x)                               {cerr<<"ss:";for(auto i:x)cout<<i<<" ";cout<<endl;}
#define lowbit(x)                               (x&-x)
#define vi                                      vector<int>
#define pii                                     pair<int,int>
#define pb                                      push_back
#define fs                                      first
#define sc                                      second

constexpr long long maxlonglong = 9223372036854775807;   //9e18
constexpr int maxint = 2147483647;      //2e9
constexpr int INF = 0x7f7f7f7f7f7f7f7f; //2139062143^2
constexpr int M = 1e9 + 7;
constexpr int mod =  1e9+7;
constexpr int hs = 0x1F351F35; // good hash number.
const double pi = acos(-1.0);
const double eps = 1e-15;
vector<int> input(int n){vector<int> a(n+1);for(int i=1;i<=n;i++)cin>>a[i];return a;}
mt19937_64 rnd(time(0));


constexpr int N=1231564;

vector<vi> g;
int power(int a,int b,int p){
    int ans=1%p;
    for(;b;b>>=1){
        if(b&1)ans=(long long)ans*a%p;
        a=(long long)a*a%p;
    }
    return ans;
}
vector<int> fac,inv;
void init(int n) 
{
    fac.resize(n+1);inv.resize(n+1);
    fac[0]=1,inv[0]=1;
    for(int i=1;i<=n;i++)
        fac[i]=fac[i-1]*i%mod;
    int res=1%mod,a=fac[n];
    //inv[maxn-1]=power(fac[maxn-1],mod-2,mod);//下面6行和均为快速幂逆元
    for(int b=mod-2;b;b>>=1){//快速幂逆元
        if(b&1)res=(long long)res*a%mod;
        a=(long long)a*a%mod;
    }
    inv[n]=res;
    for(int i=n-1;i;i--)
        inv[i]=inv[i+1]*(i+1)%mod;
} 
int c(int a,int b){//Cab a在下
    if(a<0||b<0||a<b) return 0;
    return fac[a]*inv[a-b]%mod*inv[b]%mod;
}
vi ans,w,a,b;
int n;
void dfs(int u,int dep){
    if(dep!=1){
        ans[u]+=fac[n-dep]*c(n,dep)%mod*w[u]%mod*inv[n]%mod;
        ans[u]%=mod;
    }
    for(auto v:g[u]){
        dfs(v,dep+1);
    }
}
inline void solve(){
    cin>>n;
    g.clear();g.resize(n+1);
    a=input(n),b=input(n);
    w=input(n);
    ans=a;
    vi book(n+1);
    for(int i=1;i<=n;i++){
        if(a[i]<a[b[i]]){
            ans[i]+=w[i];
            ans[i]%=mod;
        }
        else if(a[i]<a[b[i]]+w[b[i]]&&i!=b[i]){
            g[b[i]].push_back(i);
            book[i]=1;
        }
    }
    for(int i=1;i<=n;i++){
        if(book[i]) continue;
        dfs(i,1);
    }

    for(int i=1;i<=n;i++){
        cout<<ans[i]<<" \n"[i==n];
    }
    
}





signed main()
{
    //freopen("E:\work tool\code document\data\input.in", "r", stdin);
	//freopen("E:\work tool\code document\data\output.out", "w", stdout);
    ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);    //关闭同步  如果使用 则不要使用<cstdio>
    cout << fixed << setprecision(20);
    init(5e5+5);
    //fac[0]=1;
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 10840kb

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: 123ms
memory: 11276kb

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 206455474 17527050 449261413 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 113628626 977360756 482247153 963066959
902284038 240323331 132646723 421298438 601054667 99438820 94...

result:

wrong answer 25th numbers differ - expected: '665922935', found: '902284038'