結果

問題 No.1709 Indistinguishable by MEX
ユーザー planesplanes
提出日時 2021-10-16 00:23:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,032 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 173,376 KB
実行使用メモリ 19,236 KB
最終ジャッジ日時 2023-10-17 21:52:57
合計ジャッジ時間 8,344 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
4,348 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll mod=998244353;
ll mod_pow(ll x,ll n,ll mod) {
ll res=1;
  while(n>0) {
if(n&1) {
res=res*x%mod;
}
   x=x*x%mod;
    n>>=1;
  }
return res;
}



ll INF=2e18;
const ll MAX_N=1<<17;
ll n;
vector<pair<ll,ll>> dat;

void init(ll n_) {
    n=1;
    while (n<n_) n*=2;
dat=vector<pair<ll,ll>> (2*n-1);

}

    void update(ll k,ll i) {
        k+=n-1;
        dat[k]={k-n+1,i};

        while(k>0) {
            k=(k-1)/2;
            dat[k].first=dat[2*k+1].first;
            if(dat[2*k+2].second==0) dat[k].second=dat[2*k+1].second;
           else if(dat[2*k+1].second==dat[2*k+2].first) dat[k].second=dat[2*k+2].second;
           else dat[k].second=dat[2*k+1].second;
            }
        }
    



int main() {
    ll N;cin>>N;
    init(N);
    for(ll i=0;i<n;i++) {
        update(i,0);
    }
    
    vector<ll> P(N);  
  vector<ll> ind(N);
    for(ll i=0;i<N;i++) {
        cin>>P[i];
        ind[P[i]]=i;
    }
vector<ll> up(N+1);
up[0]=1;
for(ll i=1;i<=N;i++) {
    up[i]=up[i-1]*i;
    up[i]%=mod;
}

vector<ll> memo(N+1);
memo[0]=1;
for(ll i=1;i<=N;i++){
    memo[i]=mod_pow(i,mod-2,mod);
}
vector<ll> down(N+1);
down[0]=1;
for(ll i=1;i<=N;i++) {
    down[i]=down[i-1]*memo[i];
    down[i]%=mod;
}


    ll s=ind[0];
    ll g=ind[0];

    ll ans=1;
ll now=1;
update(0,1);
    while(now<N) {
        ll next;
        if(ind[now]<s) {
            for(ll i=ind[now];i<s;i++) {
                update(P[i],P[i]+1);
            }
            
            s=ind[now];
             next=dat[0].second;
        }
       else {
           for(ll i=g+1;i<=ind[now];i++) {
               update(P[i],P[i]+1);
           }
           g=ind[now];
            next=dat[0].second;
       }
       
cout<<s<<" "<<g<<" "<<next<<endl;
ll k=up[g-s-now]%mod*down[g-s-(next-1)]%mod;
ans*=k%mod;
ans%=mod;
    now=next;
    }

    cout<<ans%mod<<endl;/**/

}
0