QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#695427 | #8237. Sugar Sweet II | shenchuan_fan | Compile Error | / | / | C++14 | 2.0kb | 2024-10-31 20:00:53 | 2024-10-31 20:00:54 |
Judging History
你现在查看的是最新测评结果
- [2024-11-04 16:59:03]
- hack成功,自动添加数据
- (/hack/1109)
- [2024-10-31 20:00:54]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2024-10-31 20:00:53]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
// The 2023 ICPC Asia Hangzhou Regional Contest
constexpr int mod = 1E9 + 7;
const int N = 500005;
int qmi(int a, int b){
int res = 1;
while(b){
if(b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int fact[N], ifact[N];
void init(int n){
fact[0] = 1, fact[1] = 1, ifact[1] = 1;
for(int i = 2;i<=n;i++){
fact[i] = fact[i - 1] * i % mod;
ifact[i] = ifact[i - 1] * qmi(i, mod - 2) % mod;
}
}
void sol(){
int n; std::cin>>n;
std::vector<int>a(n + 1), b(n + 1), w(n + 1);
std::vector<int>du(n + 1), ans(n + 1), vis(n + 1);
std::vector G(n + 1, std::vector<int>(0));
for(int i = 1;i<=n;i++) std::cin>>a[i];
for(int i = 1;i<=n;i++) std::cin>>b[i];
for(int i = 1;i<=n;i++) std::cin>>w[i];
for(int i = 1;i<=n;i++){
if(i != b[i]){
if(a[b[i]] > a[i]){
ans[i] = a[i] + w[i];
vis[i] = 1;
}else if(a[i] >= a[b[i]] + w[b[i]]){
ans[i] = a[i];
vis[i] = 1;
}else{
du[b[i]]++;
G[i].push_back(b[i]);
}
}else{
vis[i] = 1;
ans[i] = a[i];
}
}
auto dfs = [&](auto& self, int u)->int{
vis[u] = 1;
if(G[u].size() == 0) return 1;
int kk = self(self, G[u].back()) + 1;
ans[u] = (ifact[kk] * (a[u] + w[u]) + (1ll - ifact[kk]) * a[u]);
ans[u] = (ans[u] % mod + mod) % mod;
return kk;
};
for(int u = 1;u<=n;u++){
if(vis[u] || du[u]) continue ;
dfs(dfs, u);
}
for(int i = 1;i<=n;i++){
std::cout<<ans[i]<<" \n"[i == n];
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
init(N - 1);
int t = 1; std::cin>>t;
while(t--) sol();
return 0;
}
Details
answer.code: In function ‘void sol()’: answer.code:35:17: error: missing template arguments before ‘G’ 35 | std::vector G(n + 1, std::vector<int>(0)); | ^ answer.code:51:17: error: ‘G’ was not declared in this scope 51 | G[i].push_back(b[i]); | ^ answer.code: In lambda function: answer.code:61:12: error: ‘G’ was not declared in this scope 61 | if(G[u].size() == 0) return 1; | ^ answer.code:62:29: error: ‘G’ was not declared in this scope 62 | int kk = self(self, G[u].back()) + 1; | ^