QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#668937 | #8237. Sugar Sweet II | xjt05 | WA | 191ms | 14028kb | C++23 | 2.2kb | 2024-10-23 16:39:22 | 2024-10-23 16:39:25 |
Judging History
answer
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<stack>
#include<string>
#define lowbit(x) (x & -x)
using namespace std;
mt19937 rnd(time(0));
typedef long long ll;
const ll mod=1e9+7;
const ll N=2e5+5;
ll ksm(ll x,ll y)
{
ll ans=1;
while(y)
{
if(y&1)
ans=(ans%mod*x%mod)%mod;
x=x%mod*(x%mod)%mod;
y>>=1;
}
return ans%mod%mod;
}
ll p1=ksm(2,mod-2);
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll query(ll l,ll r)
{
cout<<"?"<<" "<<l<<" "<<r<<endl;
cout.flush();
ll x;
cin>>x;
return x;
}
struct s
{
ll x,y,w;
}p[550000];
vector<ll>g[555000];
bool vi[550000];
ll ans[552000];
ll in[550000];
ll op[555000];
ll cs=0;
ll ou[550000];
ll dfs(ll x,ll sd)
{
if(vi[x])
{
cs=ou[x];
return (op[x]*ksm(ou[x],mod-2)%mod)%mod;
}
vi[x]=1;
ll cnt=0;
for(auto j:g[x])
{
op[x]=dfs(j,sd+1);
}
if(cs>0)cs++;
ll ok=ksm(cs,mod-2);
op[x]=(op[x]%mod*ok%mod)%mod;
ou[x]=cs;
ans[x]=(((p[x].x+p[x].w)%mod)*op[x]%mod)+(((1-op[x]+1000*mod)%mod)*(p[x].x)%mod)%mod;
ans[x]%=mod;
return op[x];
}
int main()
{
fio();
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
for(ll i=1;i<=n;i++)cin>>p[i].x,g[i].clear();
for(ll i=1;i<=n;i++)cin>>p[i].y,vi[i]=0,in[i]=0,ou[i]=0;
for(ll i=1;i<=n;i++)cin>>p[i].w,op[i]=0;
for(ll i=1;i<=n;i++)
{
in[p[i].y]++;
if(p[i].y==i)
{
ans[i]=p[i].x;
vi[i]=1;
op[i]=0;
in[p[i].y]--;
ou[i]=1;
}
else if(p[i].x<p[p[i].y].x)
{
vi[i]=1;
ans[i]=(p[i].x+p[i].w)%mod;
op[i]=1;
in[p[i].y]--;
ou[i]=1;
}
else if(p[i].x>=p[p[i].y].x+p[p[i].y].w)
{
vi[i]=1;
ans[i]=p[i].x;
op[i]=0;
in[p[i].y]--;
ou[i]=1;
}
else
g[i].push_back(p[i].y);
//if(vi[i])cout<<ans[i]<<endl;
}
for(ll i=1;i<=n;i++)
{
if(in[i]==0&&vi[i]==0)
{
ll u=dfs(i,1);
}
}
for(ll i=1;i<=n;i++)
{
cout<<ans[i]%mod<<" ";
}
cout<<endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11992kb
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: 191ms
memory: 14028kb
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 73rd numbers differ - expected: '94384869', found: '444073687'