QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#655927#8237. Sugar Sweet II111111qqqqqqWA 123ms28144kbC++232.0kb2024-10-19 10:23:402024-10-19 10:23:41

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-19 10:23:41]
  • 评测
  • 测评结果:WA
  • 用时:123ms
  • 内存:28144kb
  • [2024-10-19 10:23:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define cmin(a,b) a=min(a,b)
#define cmax(a,b) a=max(a,b)
#define modd(a,b) a=a%b
#define pb push_back
#define db double
#define lowbit(x) x&(-x)
#define cerr(x) cout<<#x<<"="<<x<<endl
#define fi first
#define se second
const ll mod=1e9+7;
#define N 500010
ll n,a[N],b[N],w[N],ans[N];
ll fact[N],inv[N];
ll p[N],dist[N],flag[N],col[N];
bool vis[N];
ll ksm(ll a,ll b) {ll ans=1,bs=a;while(b) {if(b&1) ans=ans*bs%mod;bs=bs*bs%mod;b>>=1;}return ans;}
void init(int n=500000) {
    fact[0]=1;
    for(int i=1;i<=n;i++) fact[i]=fact[i-1]*i%mod;
    inv[n]=ksm(fact[n],mod-2);
    for(int i=n-1;~i;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
void dfs(int u) {
    if(vis[u]) return;
    vis[u]=1;
    dfs(b[u]);
    col[u]=col[b[u]];
    if(flag[u]) {
        if(p[u]==0) dist[u]=0,col[u]=0;
        else dist[u]=1,col[u]=1;
    }
    else {
        dist[u]=dist[b[u]]+1;
        if(col[b[u]]) ans[u]=(ans[u]+inv[dist[u]]*w[u]%mod)%mod;
    }
}
void solve() {
    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++) flag[i]=0,p[i]=0,ans[i]=a[i],vis[i]=0;
    for(int i=1;i<=n;i++) {
        if(i==b[i] || a[i]>=a[b[i]]+w[b[i]]) p[i]=0,ans[i]=a[i],flag[i]=1,col[i]=0;
        else if(a[i]<a[b[i]]) p[i]=1,ans[i]=a[i]+w[i],flag[i]=1,col[i]=1;
    }
    for(int i=1;i<=n;i++) {
        if(vis[i]) continue;
        dfs(i);
    }
    for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
    cout<<endl;
}
int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    init();
    int T;
    cin>>T;
    while(T--) 
    solve();
    return 0;
}
/*
虽然说对于全排列而言a在b前面和b在a前面的概率是一样的,但是如果固定了a在b前面,
来考虑b和c的关系的话,那b在c前面和c在b前面的概率是不同的,因为a和b的相对位置
固定了的情况下.所以对于某种情况而言应该是一种1/dis(i)!阶乘的形式
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 28144kb

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: 26164kb

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 986091180 234208588 859123744 
863886789 
871186919 814243920 968784984 1206455481 17527050 1449261420 196759729 901433117 519383814 907574792 983760005 984444619 489899014 435736558 1113628633 977360756 482247153 963066959 
665922935 577926775 132646723 421298438 601054667 10994...

result:

wrong answer 3rd numbers differ - expected: '590444253', found: '986091180'