QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#617799 | #8237. Sugar Sweet II | ukuk | Compile Error | / | / | C++14 | 1.9kb | 2024-10-06 17:10:47 | 2024-10-06 17:10:47 |
Judging History
你现在查看的是最新测评结果
- [2024-11-04 16:59:03]
- hack成功,自动添加数据
- (/hack/1109)
- [2024-10-06 17:10:47]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2024-10-06 17:10:47]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug(x) cout<<#x<<" = "<<x<<'\n'
const int mod=1e9+7;
const int N = 5e5 + 5;
int n;
int fac[N],infac[N];
bool vis[N];
int a[N],w[N];
int fa[N];
int cnt[N];
int qmi(int a,int b){
int ret=1;
for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;
return ret;
}
int C(int a,int b){
if(a<b||a<0||b<0)return 0;
return fac[a]*infac[b]%mod*infac[a-b]%mod;
}
void dfs(int u){
// debug(u);
vis[u]=1;
if(a[fa[u]]>a[u]){
cnt[u]=-1;
vis[u]=0;
return;
}
if(a[fa[u]]+w[fa[u]]<=a[u]){
cnt[u]=-2;
vis[u]=0;
return;
}
if(vis[fa[u]]){
cnt[u]=-2;
vis[u]=0;
return;
}
if(!cnt[fa[u]])dfs(fa[u]);
if(cnt[fa[u]]>0)cnt[u]=cnt[fa[u]]+1;
else if(cnt[fa[u]]==-1)cnt[u]=1;
else cnt[u]=-2;
vis[u]=0;
}
void solve(){
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>fa[i];
for(int i=1;i<=n;i++)cin>>w[i];
for(int i=1;i<=n;i++)cnt[i]=vis[i]=0;
for(int i=1;i<=n;i++){
if(!cnt[i])dfs(i);
// debug(cnt[i]);
}
// cout << cnt[5] << '\n';
for(int i=1;i<=n;i++){
if(cnt[i]==-2){
cout<<a[i]<<' ';
}
else if(cnt[i]==-1){
cout<<a[i]+w[i]<<' ';
}
else{
while(n-cnt[i]-1<0);
int t=C(n,cnt[i]+1)*w[i]%mod*fac[n-cnt[i]-1]%mod*infac[n]%mod;
t=((t+mod)%mod+a[i])%mod;
cout<<t<<' ';
}
}
cout<<'\n';
}
signed main(){
// freopen("1.in", "r", stdin);
// freopen("1.ans", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
fac[0]=1;
for(int i=1;i<N;i++)fac[i]=fac[i-1]*i%mod;
infac[N-1]=qmi(fac[N-1],mod-2);
for(int i=N-2;i>=0;i--)infac[i]=infac[i+1]*(i+1)%mod;
int _=1;
cin>>_;
while(_--)solve();
return 0;
}
/*
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
1
3
5 4 3
2 3 1
1 2 3
*/
詳細信息
answer.code:3:1: error: extended character is not valid in an identifier 3 | | ^ answer.code:6:1: error: extended character is not valid in an identifier 6 | | ^ answer.code:9:1: error: extended character is not valid in an identifier 9 | | ^ answer.code:16:1: error: extended character is not valid in an identifier 16 | | ^ answer.code:103:1: error: extended character is not valid in an identifier 103 | | ^ answer.code:3:1: error: ‘ ’ does not name a type 3 | | ^ answer.code:9:1: error: ‘ ’ does not name a type 9 | | ^ answer.code:16:1: error: ‘ ’ does not name a type 16 | | ^ answer.code: In function ‘long long int C(long long int, long long int)’: answer.code:24:32: error: ‘mod’ was not declared in this scope; did you mean ‘modf’? 24 | return fac[a]*infac[b]%mod*infac[a-b]%mod; | ^~~ | modf answer.code: In function ‘void solve()’: answer.code:56:14: error: ‘n’ was not declared in this scope 56 | cin>>n; | ^ answer.code:78:50: error: ‘mod’ was not declared in this scope; did you mean ‘modf’? 78 | int t=C(n,cnt[i]+1)*w[i]%mod*fac[n-cnt[i]-1]%mod*infac[n]%mod; | ^~~ | modf answer.code: In function ‘int main()’: answer.code:93:47: error: ‘mod’ was not declared in this scope; did you mean ‘modf’? 93 | for(int i=1;i<N;i++)fac[i]=fac[i-1]*i%mod; | ^~~ | modf answer.code:94:33: error: ‘mod’ was not declared in this scope; did you mean ‘modf’? 94 | infac[N-1]=qmi(fac[N-1],mod-2); | ^~~ | modf answer.code:94:20: error: ‘qmi’ was not declared in this scope 94 | infac[N-1]=qmi(fac[N-1],mod-2); | ^~~ answer.code: At global scope: answer.code:103:1: error: ‘ ’ does not name a type 103 | | ^