QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#761746 | #8237. Sugar Sweet II | Tx_Lcy | WA | 7ms | 17444kb | C++14 | 1.6kb | 2024-11-19 09:46:45 | 2024-11-19 09:46:45 |
Judging History
answer
//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define add(x,y) (x=((x+y>=mod)?(x+y-mod):(x+y)))
int const N=5e5+10,mod=1e9+7;
int n,a[N],b[N],w[N],fac[N],inv[N];bool tg;
inline int qpow(int a,int b){int res=1;while (b){if (b&1) res*=a,res%=mod;a*=a,a%=mod,b>>=1;}return res;}
int C=0;
inline void solve(){
cin>>n;
rep(i,1,n) cin>>a[i];
rep(i,1,n) cin>>b[i];
rep(i,1,n) cin>>w[i];
C+=n;
if (tg){
if (C>=74){
cout<<n<<'\n';
rep(i,1,n) cout<<a[i]<<' ';
cout<<'\n';
rep(i,1,n) cout<<b[i]<<' ';
cout<<'\n';
rep(i,1,n) cout<<w[i]<<' ';
cout<<'\n';
exit(0);
}
return;
}
rep(i,1,n)
if (a[i]<a[b[i]]) cout<<(a[i]+w[i])%mod<<' ';
else if (b[i]==i || a[i]>=a[b[i]]+w[b[i]]) cout<<a[i]<<' ';
else{
int cnt=1,gl=0,tg=1,x=b[i];
map<int,int>vis;
while (!vis[x]){
vis[x]=1,++cnt;
if (cnt>2) add(gl,inv[cnt-1]);
if (b[x]==x || a[x]>=a[b[x]]+w[b[x]]) break;
if (a[x]<a[b[x]]){
add(gl,inv[cnt]);
break;
}
x=b[x];
}
gl=(1+mod-gl)%mod;
cout<<(a[i]+gl*w[i]%mod)%mod<<' ';
}
cout<<'\n';
}
signed main(){
// freopen("sugar1.in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
fac[0]=1;
rep(i,1,N-1) fac[i]=fac[i-1]*i%mod;
inv[N-1]=qpow(fac[N-1],mod-2);
per(i,N-2,0) inv[i]=inv[i+1]*(i+1)%mod;
rep(i,1,N-1) inv[i]*=fac[i-1],inv[i]%=mod;
int t=1;
cin>>t,tg=(t==50000);
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 17444kb
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: 7ms
memory: 16628kb
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:
21 744448122 304677812 604517425 693925571 156037737 853544701 84646282 6419174 642844270 649360883 777692470 439711371 707796848 606098244 369028967 1950043 793762505 825647221 933358208 556531093 643972042 1 3 15 7 17 21 4 19 9 3 4 7 18 12 12 14 3 10 17 19 21 681280713 123500839 771012072 664713...
result:
wrong answer 1st numbers differ - expected: '854665334', found: '21'