QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#422669 | #8237. Sugar Sweet II | lmeowdn# | WA | 80ms | 36844kb | C++14 | 2.5kb | 2024-05-27 18:17:03 | 2024-05-27 18:17:03 |
Judging History
answer
//Shirasu Azusa 2024.5
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
return x*w;
}
const int N=5e5+5,mod=1e9+7;
int n,p[N],f[N],fac[N],ifac[N],deg[N],a[N],w[N],g[N],c[N],vst[N],oc[N];
vi r[N],st;
int ksm(int x,int y,int r=1) {
for(;y;y>>=1,x=x*x%mod) if(y&1) r=r*x%mod;
return r;
}
void dfs(int u) {
if(g[p[u]]==0) {
g[u]=c[u]=0; return;
}
if(c[p[u]]) {
c[u]=c[p[u]]+1;
return;
} vst[u]=1;
if(vst[p[u]]) {
int cnt=0; vi circ;
while(!oc[u]) {
circ.eb(u); oc[u]=1; cnt++;
}
for(int x:circ) g[x]=cnt;
} else {
dfs(p[u]);
if(!c[u]) c[u]=c[p[u]]+1;
}
}
void work() {
n=read();
rep(i,0,n+1) c[i]=f[i]=g[i]=deg[i]=a[i]=w[i]=oc[i]=p[i]=0, r[i].clear();
fac[0]=1; rep(i,1,n) fac[i]=fac[i-1]*i%mod;
ifac[n]=ksm(fac[n],mod-2);
per(i,n-1,0) ifac[i]=ifac[i+1]*(i+1)%mod;
f[1]=1;
rep(i,2,n) {
if(i&1) f[i]=(f[i-1]+ifac[i])%mod;
else f[i]=(f[i-1]+mod-ifac[i])%mod;
}
rep(i,1,n) a[i]=read(), g[i]=-1;
rep(i,1,n) p[i]=read(), r[p[i]].eb(i);
rep(i,1,n) w[i]=read(); queue<int> q;
rep(i,1,n) {
if(a[i]<a[p[i]]) g[i]=1, q.push(i);
else if(a[i]>=a[p[i]]+w[p[i]]) g[i]=0, q.push(i);
else if(p[i]==i) g[i]=0;
else g[i]=-1;
}
rep(i,1,n) if(g[i]==1) c[i]=1;
rep(i,1,n) if(g[i]==-1&&!c[i]) dfs(i);
rep(i,1,n) if(g[i]==-1) g[i]=ifac[c[i]];
rep(i,1,n) printf("%lld ",(a[i]+w[i]*g[i])%mod); puts("");
}
signed main() {
int T=read(); while(T--) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 36844kb
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: 80ms
memory: 36728kb
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 200th numbers differ - expected: '408330545', found: '198109459'