QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#401873 | #8237. Sugar Sweet II | younger | WA | 158ms | 24308kb | C++20 | 2.5kb | 2024-04-29 15:58:02 | 2024-04-29 15:58:03 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
const int mod = 1e9 + 7 , N = 5e5 + 10;
int n;
int h[N] , ne[2 * N] , e[2 * N] , idx;
LL a[N] , b[N] , w[N] , f[N] , inv[N];
LL ans[N] , d[N];
bool st[N];
LL ksm(LL a , LL b)
{
LL res = 1;
while(b)
{
if(b & 1)res = res * a % mod;
b >>= 1;
a = a * a % mod;
}
return res % mod;
}
void init()
{
f[0] = inv[0] = 1;
for(int i = 1 ; i <= 500000 ; i ++){
f[i] = f[i - 1] * i % mod;
inv[i] = ksm(f[i] , mod - 2);
}
return;
}
LL C(LL a , LL b)
{
if(a < b)return 0;
return (((f[a] * inv[b] + mod) % mod) * inv[a - b] + mod) % mod;
}
LL pmod(LL a , LL b)
{
return (a * b % mod + mod) % mod;
}
LL amod(LL a , LL b)
{
return (a % mod + b % mod) % mod;
}
LL mmod(LL a , LL b)
{
return (a - b + mod) % mod;
}
void add(int a , int b)
{
e[idx] = b , ne[idx] = h[a] , h[a] = idx ++;
return;
}
void dfs(int u , int now){
if(!st[u])
{
ans[u] = amod(a[u] , pmod(pmod(1ll , inv[now]) , ((w[u]) % mod + mod) % mod));
// ans[u] = pmod(pmod(pmod(C(n , now) , f[n - now]) , inv[n]) , (a[u] + w[u]) % mod) % mod;
// ans[u] = amod(ans[u] % mod , pmod(a[u] , pmod(inv[n] , mmod(f[n] , pmod(C(n , now) , f[n - now])))));
}
for(int i = h[u] ; ~ i ; i = ne[i]){
int j = e[i];
dfs(j , now + 1);
}
return;
}
void Asuka()
{
cin >> n;
idx = 0;
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 ++){
ans[i] = 0;d[i] = 0;h[i] = -1;st[i] = false;
}
vector<int>node;
for(int i = 1 ; i <= n ; i ++){
if(a[b[i]] > a[i]){
ans[i] = (a[i] + w[i]) % mod;
st[i] = true;
node.emplace_back(i);
}else if(a[i] >= a[b[i]] + w[b[i]] || b[i] == i){
ans[i] = a[i] % mod;
st[i] = true;
}else{
add(b[i] , i);
}
}
// for(int i = 1 ; i <= n ; i ++)
// cout << ans[i] << ' ';
// cout << '\n';
for(auto t : node){
dfs(t , 1);
}
for(int i = 1 ; i <= n ; i ++){
cout << ans[i] << ' ';
}
cout << '\n';
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
init();
int t = 1;
cin >> t;
while(t --){
Asuka();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 51ms
memory: 24308kb
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: 158ms
memory: 24124kb
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 0 0 132646723 421298438 601054667 99438820 94575413 81954...
result:
wrong answer 25th numbers differ - expected: '665922935', found: '0'