QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#383927 | #4944. 假面 | bachbeo2007 | 100 ✓ | 717ms | 4212kb | C++17 | 3.8kb | 2024-04-09 18:56:44 | 2024-04-09 18:56:45 |
Judging History
answer
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=205;
const int B=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
const int base=101;
int power(int a,int n){
int res=1;
while(n){
if(n&1) res=res*a%mod;
a=a*a%mod;n>>=1;
}
return res;
}
const int iroot=power(3,mod-2);
int fac[maxn],dfac[maxn],inv[maxn];
int C(int n,int k){
if(k>n || k<0 || n<0) return 0;
return fac[n]*dfac[k]%mod*dfac[n-k]%mod;
}
void combi(int n){
fac[0]=inv[0]=1;
for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
dfac[n]=power(fac[n],mod-2);
for(int i=n;i>=1;i--){
dfac[i-1]=dfac[i]*i%mod;
inv[i]=dfac[i]*fac[i-1]%mod;
}
}
int n,q,s[maxn];
int d[maxn][maxn];
void solve(){
cin >> n;combi(n);
for(int i=1;i<=n;i++) cin >> s[i],d[i][s[i]]=1;
cin >> q;
while(q--){
int id;cin >> id;
if(id){
int k;cin >> k;
vector<int> x(k);
for(int i=0;i<k;i++){
int p;cin >> p;
x[i]=(mod+1-d[p][0])%mod;
}
vector<int> dp(k,0);dp[0]=1;
auto add = [&](int id){
for(int i=k-1;i>=0;i--){
if(!dp[i]) continue;
dp[i+1]=(dp[i+1]+dp[i]*x[id])%mod;
dp[i]=dp[i]*(mod+1-x[id])%mod;
}
};
function<void(int,int)> dnc = [&](int l,int r){
if(l==r){
int total=0;
for(int i=0;i<k;i++) total=(total+dp[i]*inv[i+1])%mod;
total=total*x[l]%mod;
cout << total << ' ';
return;
}
int mid=(l+r)>>1;
vector<int> cc=dp;
for(int i=mid+1;i<=r;i++) add(i);
dnc(l,mid);dp=cc;
for(int i=l;i<=mid;i++) add(i);
dnc(mid+1,r);dp=cc;
};
dnc(0,k-1);
cout << '\n';
}
else{
int x,u,v;cin >> x >> u >> v;
u=u*power(v,mod-2)%mod;
for(int j=1;j<=s[x];j++){
d[x][j-1]=(d[x][j-1]+d[x][j]*u)%mod;
d[x][j]=(d[x][j]*(1-u)%mod+mod)%mod;
}
}
}
for(int i=1;i<=n;i++){
int total=0;
for(int j=1;j<=s[i];j++) total=(total+j*d[i][j])%mod;
cout << total << ' ';
}
cout << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test=1;//cin >> test;
while(test--) solve();
}
详细
Test #1:
score: 10
Accepted
time: 0ms
memory: 3572kb
input:
5 3 2 3 5 2 21 0 4 57200194 62560282 0 1 146714842 190677962 0 3 421682737 866825565 0 2 147205019 326165492 0 5 43044930 174129591 0 5 471737667 946078665 0 1 67470072 85631701 0 3 424723162 491392606 0 1 161738068 214618699 0 2 167409685 828201389 1 5 2 1 4 5 3 0 1 15605041 17495347 0 5 185545979 ...
output:
107368698 189599100 687600238 324320433 687600238 606654499 906006418 648113700 648113700 185844743 856212861 253665492 395756888 490853466 720424385 963622540 990903428 277019498 42763209 720424385 277019498 990903428 42763209 963622540 458983827 545373647 251091757 468284676 272754800 340362...
result:
ok 34 numbers
Test #2:
score: 10
Accepted
time: 106ms
memory: 3776kb
input:
60 93 22 28 60 27 27 37 69 30 31 24 36 3 59 68 57 43 74 20 38 25 71 27 81 74 71 82 26 28 6 30 58 96 46 68 65 51 9 79 85 52 100 61 69 13 87 40 71 79 2 3 93 57 100 87 66 45 41 32 98 199992 0 9 444583729 889658122 0 28 444583729 889658122 0 11 444583729 889658122 0 35 444583729 889658122 0 39 444583729...
output:
764196322 518700730 489720477 267683315 944759499 489706246 810974269 848295414 958825009 769587032 100148014 509434560 232856289 2353109 212130067 129459833 409889791 142582698 58894087 707314398 178109019 761720055 518483857 248114660 919049978 86715058 22798800 63432291 307970379 715642039 548359...
result:
ok 23057 numbers
Test #3:
score: 10
Accepted
time: 1ms
memory: 3760kb
input:
60 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 23 0 59 89817677 237987517 0 45 9286825 11937381 0 6 186458289 659261035 0 10 357086956 553050724 0 5 475088880 805335745 0 47 400707619 741220104 0 2 195821006 203870958 0 5 14...
output:
304278377 304278377 304278377 450544203 304278377 304278377 304278377 637957920 341116069 865590646 304278377 304278377 304278377 304278377 366627363 304278377 304278377 304278377 304278377 485008584 853044587 977460394 304278377 304278377 304278377 304278377 304278377 304278377 304278377 304278377 ...
result:
ok 339 numbers
Test #4:
score: 10
Accepted
time: 82ms
memory: 3840kb
input:
60 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 199994 0 13 601080363 879374736 0 41 13604970 620358714 0 4 474749303 543941493 0 11 204080001 233457854 0 58 438081964 812786834 0 23 884507813 995739274 0 53 148575990 2570380...
output:
603671434 346307002 472937431 420751207 126823661 436769552 525776156 504666874 886609578 97379102 44433317 490965368 588872603 205364900 764004244 581616782 121073920 606101615 383989028 659316281 311182521 375247790 393444793 704852419 861322040 638325251 427096039 140931152 394672817 201550761 87...
result:
ok 23287 numbers
Test #5:
score: 10
Accepted
time: 110ms
memory: 3724kb
input:
60 93 22 28 60 27 27 37 69 30 31 24 36 3 59 68 57 43 74 20 38 25 71 27 81 74 71 82 26 28 6 30 58 96 46 68 65 51 9 79 85 52 100 61 69 13 87 40 71 79 2 3 93 57 100 87 66 45 41 32 98 199995 0 41 13604970 620358714 0 4 474749303 543941493 0 11 204080001 233457854 0 58 438081964 812786834 0 23 884507813 ...
output:
880925494 290653588 521390872 861342120 187391714 904328230 690519955 527946830 35021728 836362841 191560014 791376646 461144894 548639684 586467108 818063632 59033652 43706329 886954774 14312194 291313471 818481148 150874524 885699229 215410211 792329674 164791319 136544870 429441970 976795291 7851...
result:
ok 22904 numbers
Test #6:
score: 10
Accepted
time: 89ms
memory: 3720kb
input:
60 93 22 28 60 27 27 37 69 30 31 24 36 3 59 68 57 43 74 20 38 25 71 27 81 74 71 82 26 28 6 30 58 96 46 68 65 51 9 79 85 52 100 61 69 13 87 40 71 79 2 3 93 57 100 87 66 45 41 32 98 199996 0 41 13604970 620358714 0 4 474749303 543941493 0 11 204080001 233457854 0 58 438081964 812786834 0 23 884507813 ...
output:
31311934 458218831 612517627 520630081 834524568 735573278 602359531 185925983 117136700 16578877 668810973 149004438 695957963 757993180 756227637 877038225 676747765 747833842 422848272 590332056 36037874 559204662 863781697 453196603 254777940 641553045 491620260 317701301 731946951 649095760 437...
result:
ok 60 numbers
Test #7:
score: 10
Accepted
time: 89ms
memory: 3936kb
input:
60 93 22 28 60 27 27 37 69 30 31 24 36 3 59 68 57 43 74 20 38 25 71 27 81 74 71 82 26 28 6 30 58 96 46 68 65 51 9 79 85 52 100 61 69 13 87 40 71 79 2 3 93 57 100 87 66 45 41 32 98 199997 0 4 233 233 0 11 233 233 0 58 233 233 0 23 233 233 0 53 233 233 0 45 233 233 0 11 233 233 0 31 233 233 0 55 233 2...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 23920 numbers
Test #8:
score: 10
Accepted
time: 705ms
memory: 4140kb
input:
200 93 22 28 60 27 27 37 69 30 31 24 36 3 59 68 57 43 74 20 38 25 71 27 81 74 71 82 26 28 6 30 58 96 46 68 65 51 9 79 85 52 100 61 69 13 87 40 71 79 2 3 93 57 100 87 66 45 41 32 98 82 10 68 98 87 7 20 29 33 4 71 9 41 97 19 47 22 80 65 42 94 100 65 15 57 92 66 37 52 29 8 22 96 38 94 29 12 30 5 64 39 ...
output:
421737305 105292341 240215808 749028261 224707095 93242760 928065947 239801839 517199786 687760868 502022091 392955495 428053444 330907240 46885553 106112751 310527975 817173654 494622743 596118073 669502125 58629348 711659348 400846887 327935833 706923295 618782995 423968818 359158511 58441258 5456...
result:
ok 163965 numbers
Test #9:
score: 10
Accepted
time: 698ms
memory: 4212kb
input:
200 93 22 28 60 27 27 37 69 30 31 24 36 3 59 68 57 43 74 20 38 25 71 27 81 74 71 82 26 28 6 30 58 96 46 68 65 51 9 79 85 52 100 61 69 13 87 40 71 79 2 3 93 57 100 87 66 45 41 32 98 82 10 68 98 87 7 20 29 33 4 71 9 41 97 19 47 22 80 65 42 94 100 65 15 57 92 66 37 52 29 8 22 96 38 94 29 12 30 5 64 39 ...
output:
971043096 868722851 875635361 215247791 785440837 377902251 150714744 697444982 662790052 480498888 32043015 575549872 572526454 895731814 92926758 88615559 758602780 772570474 275781091 206233514 342346690 686852273 954370168 704585237 604704513 946450840 247809365 55607264 381837037 942535798 2564...
result:
ok 163028 numbers
Test #10:
score: 10
Accepted
time: 717ms
memory: 4176kb
input:
200 93 22 28 60 27 27 37 69 30 31 24 36 3 59 68 57 43 74 20 38 25 71 27 81 74 71 82 26 28 6 30 58 96 46 68 65 51 9 79 85 52 100 61 69 13 87 40 71 79 2 3 93 57 100 87 66 45 41 32 98 82 10 68 98 87 7 20 29 33 4 71 9 41 97 19 47 22 80 65 42 94 100 65 15 57 92 66 37 52 29 8 22 96 38 94 29 12 30 5 64 39 ...
output:
358072467 98740040 682265210 735560556 457058322 39866355 946464972 789839555 765587358 240203502 617891630 455352073 421639136 607704397 754616177 78679522 136934614 763982442 92646916 50664698 763385610 866570195 724772491 607964748 12163419 722087145 453872135 442277078 756643760 869905047 316910...
result:
ok 165924 numbers
Extra Test:
score: 0
Extra Test Passed