QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618015#8237. Sugar Sweet IIukukWA 3ms12500kbC++203.1kb2024-10-06 18:05:382024-10-06 18:05:41

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-06 18:05:41]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:12500kb
  • [2024-10-06 18:05:38]
  • 提交

answer

#include<bits/stdc++.h>
#define ls i<<1
#define rs i<<1|1
#define fi first
#define se second
#define min amin
#define max amax
#define eb emplace_back
using namespace std;
using ll=long long;
using LL=__int128;
using pii=pair<int,int>;
const int N=5E5+10;
const int inf=1E9;
const int p=1E9+7;
template<typename T=int>T read(){T x;cin>>x;return x;}
template<typename U,typename V>U min(const U &x,const V &y){return x<y?x:y;}
template<typename U,typename V>U max(const U &x,const V &y){return y<x?x:y;}
template<typename U,typename ...V>U min(const U &x,const V &...y){return min(x,min(y...));}
template<typename U,typename ...V>U max(const U &x,const V &...y){return max(x,max(y...));}
template<typename U,typename V>bool cmin(U &x,const V &y){return y<x?x=y,true:false;}
template<typename U,typename V>bool cmax(U &x,const V &y){return x<y?x=y,true:false;}
template<typename T>T qpow(T x,int n){T y=1;for(;n;n>>=1,x*=x)if(n&1)y*=x;return y;}
istream &operator>>(istream &is,LL &x){string a;is>>a;bool k=a[0]=='-';if(k)a=a.substr(1);x=0;for(char &t:a)x=x*10+t-48;if(k)x=-x;return is;}
ostream &operator<<(ostream &os,LL x){if(x<0)os<<'-',x=-x;string a;do a+=x%10|48;while(x/=10);reverse(a.begin(),a.end());return os<<a;}
struct mint{
    int x;
    mint():x(){}
    mint(const int &x):x(x<0?x+p:x){}
    mint inv()const{return qpow(*this,p-2);}
    mint &operator+=(const mint &t){return (x+=t.x)<p?0:x-=p,*this;}
    mint &operator-=(const mint &t){return (x-=t.x)<0?x+=p:0,*this;}
    mint &operator*=(const mint &t){return x=ll(x)*t.x%p,*this;}
    mint &operator/=(const mint &t){return *this*=t.inv();}
    mint operator+(const mint &t)const{return mint(*this)+=t;}
    mint operator-(const mint &t)const{return mint(*this)-=t;}
    mint operator*(const mint &t)const{return mint(*this)*=t;}
    mint operator/(const mint &t)const{return mint(*this)/=t;}
    bool operator==(const mint &t)const{return x==t.x;}
    friend istream &operator>>(istream &is,mint &t){return is>>t.x;}
    friend ostream &operator<<(ostream &os,const mint &t){return os<<t.x;}
};

int a[N],b[N],c[N],h[N];
bool vis[N];
mint ifac[N];
void init(){
    ifac[0]=ifac[1]=1;
    for(int i=2;i<N;++i)ifac[i]=ifac[p%i]*(-p/i);
    for(int i=2;i<N;++i)ifac[i]*=ifac[i-1];
}
void dfs(int x){
    vis[x]=true;
    int y=b[x];
    if(a[x]<a[y])h[x]=-1;
    else if(a[x]>=a[y]+c[y])h[x]=-2;
    else{
        if(!vis[y])dfs(y);
        if(h[y]==-2)h[x]=-2;
        else if(h[y]==-1)h[x]=1;
        else h[x]=h[y]+1;
    }
}
void solve(){
    int n;
    cin>>n;
    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>>c[i];
    for(int i=1;i<=n;++i){
        if(!vis[i]){
            dfs(i);
        }
    }
    for(int i=1;i<=n;++i){
    	if(h[i]==-1){
    		cout<<(a[i]+c[i])%p<<' ';
		} 
        if(h[i]>0){
            cout<<ifac[h[i]]*c[i]+a[i]<<' ';
            h[i]=0;
        }
        else cout<<a[i]<<' ';
        vis[i]=false;
    }
    cout<<'\n';
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    init();
    int T;
    cin>>T;
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 12500kb

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:

5 7 5 6 2 
11 10 4 9 3 
500000009 6 6 3 
3 4 1 3 4 2 5 1 

result:

wrong answer 1st numbers differ - expected: '500000007', found: '5'