QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#531298 | #8237. Sugar Sweet II | HHAZ | WA | 154ms | 15592kb | C++17 | 2.9kb | 2024-08-24 19:46:34 | 2024-08-24 19:46:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define endl '\n'
#define debug(x) cout<<#x<<": "<<x<<endl
#define lowbit(x) (x&-x)
#define gcd __gcd
#define i128 __int128
#define rep(i, a, b) for(ll i = (a); i <= (b); i++)
#define per(i, a, b) for(ll i = (a); i >= (b); i--)
const int N=5e5+10,M=1e3+10;
const ll mod=1e9+7;
const ld eps=1e-12;
const ld pi=3.14159265358979;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
//unordered_map<int,int>mp;
#define poly vector<int>
ll f[N],g[N],inv[N];//注意int,下面用要强制转换成ll
void init_inverse1()//求1开始的连续逆元
{
inv[1]=1;
for(int i=2;i<N;i++)
inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod;
}
void init_combinatorial()
{
init_inverse1();//用init_inverse2()会稍微快一点
f[0]=g[0]=1;
for(int i=1;i<N;i++)
f[i]=(ll)f[i-1]*i%mod;
for(int i=1;i<N;i++)
g[i]=(ll)g[i-1]*inv[i]%mod;
}
ll getC(int n,int m)//n大m小
{
if(n<m) return 0;
return ((ll)f[n]*g[m]%mod)*g[n-m]%mod;
}
ll qpow(ll a,ll b)
{
ll res=1;
a%=mod;
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
void solve()
{
ll n;
cin >> n;
bool vis[n + 5], finall[n + 5];
memset(vis, 0, sizeof(vis));
memset(finall, 0, sizeof(finall));
ll w[n + 5];
array<ll, 3> a[n + 5];
ll b[n + 5];
vector<ll>ve[n + 5];
ll add[n + 5], q[n + 5];
memset(add, 0, sizeof(add));
memset(q, 0, sizeof(q));
rep(i, 1, n) {
cin >> a[i][0];
a[i][2] = i;
a[i][1] = 1;
b[i] = a[i][0];
}
rep(i, 1, n) {
ll x;
cin >> x;
ve[x].push_back(i);
if(b[i] < b[x]) {
a[i][1] = 0;
}
}
rep(i, 1, n) {
cin >> w[i];
}
rep(i, 1, n) {
swap(a[i][0], a[i][1]);
}
sort(a + 1, a + n + 1);
rep(i, 1, n) {
if(a[i][0]) break;
ll y = a[i][2];
// debug(y);
if(!vis[y]) add[y] = 1;
vis[y] = 1;
queue<int>qu;
qu.push(y);
while(!qu.empty()) {
int cur = qu.front();
qu.pop();
if(finall[cur]) continue;
finall[cur] = 1;
for(auto t : ve[cur]) {
if(!vis[t]) {
if(b[cur] > b[t]) {
add[t] = 1;
}
else if(b[cur] + w[cur] > b[t]) {
q[t] = q[cur] + 1;
add[t] = getC(n, q[t] + 1) * g[n];
add[t] %= mod;
add[t] *= f[n - q[t] - 1];
add[t] %= mod;
}
else {
add[t] = 0;
}
vis[t] = 1;
}
if(!finall[t]) qu.push(t);
}
}
}
rep(i, 1, n) {
// debug(b[i]);
// debug(add[i]);
// debug(w[i]);
cout << (b[i] + (add[i] * w[i]) % mod) % mod << " \n"[i==n];
}
// debug(((ll)2 + qpow(6, mod - 2)) % mod);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
init_inverse1();
init_combinatorial();
while(T--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 14ms
memory: 15420kb
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: 154ms
memory: 15592kb
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 94...
result:
wrong answer 67th numbers differ - expected: '777692470', found: '416086330'