QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#610728#8237. Sugar Sweet IIinfCraftWA 212ms30752kbC++141.9kb2024-10-04 17:09:572024-10-04 17:09:58

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-04 17:09:58]
  • 评测
  • 测评结果:WA
  • 用时:212ms
  • 内存:30752kb
  • [2024-10-04 17:09:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back

#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ff first
#define ss second
#define fori(x,y) for(int i=x;i<=(int)(y);++i)
#define forj(x,y) for(int j=x;j<=(int)(y);++j)
#define fork(x,y) for(int k=x;k<=(int)(y);++k)

#define debug(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll MOD = 1e9+7;
ll qpow(ll a,ll p) {ll res=1; while(p) {if (p&1) {res=res*a%MOD;} a=a*a%MOD; p>>=1;} return res;}


const int N = 5e5+7;
ll fact[N], inv[N];  // 阶乘逆元

ll a[N], b[N], w[N];
vector<int> g[N];
ll res[N];
void solve() {
	int n;
    cin >> n;
    fori(1, n) {
        g[i].clear();
        res[i] = -1;
    }
    fori(1, n) cin >> a[i];
    fori(1, n) {
        cin >> b[i];
        g[b[i]].push_back(i);
    }
    fori(1, n) cin >> w[i];

    deque<pii> que;
    fori(1, n) {
        if (a[b[i]]<=a[i]&&a[i]<a[b[i]]+w[b[i]]) continue;
        if (a[b[i]]>a[i]) res[i] = (a[i]+w[i])%MOD;
        else res[i] = a[i];
        for (auto v: g[i]) que.push_back({v, 2});
    }
    while (que.size()) {
        auto pi = que.front();
        que.pop_front();
        int u = pi.first;
        if (res[u] != -1) continue;
        res[u] = (a[u]*fact[pi.second]+w[u])%MOD*inv[pi.second]%MOD;
        for (auto v: g[u]) {
            if (res[v] != -1) continue;
            que.push_back({v, pi.second+1});
        }
    }
    fori(1, n) if (res[i] == -1) res[i] = a[i];

    fori(1, n) cout << res[i]%MOD << " ";
    cout << endl;
}

signed main() {
	IOS;
    fact[0] = inv[0] = 1;
    fori(1, N-1) fact[i] = fact[i-1]*i%MOD;
    fori(1, N-1) inv[i] = qpow(fact[i], MOD-2)%MOD;
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 106ms
memory: 29252kb

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: 212ms
memory: 30752kb

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 
665922935 577926775 132646723 421298438 601054667 99438820...

result:

wrong answer 67th numbers differ - expected: '777692470', found: '416086330'