結果

問題 No.1868 Teleporting Cyanmond
ユーザー mkmkmkmkmkmkmkmk
提出日時 2022-03-11 21:50:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 4,009 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 177,332 KB
実行使用メモリ 6,072 KB
最終ジャッジ日時 2023-10-14 06:57:07
合計ジャッジ時間 4,562 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 59 ms
5,936 KB
testcase_04 AC 43 ms
4,580 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 11 ms
4,348 KB
testcase_07 AC 28 ms
4,364 KB
testcase_08 AC 17 ms
4,352 KB
testcase_09 AC 26 ms
4,496 KB
testcase_10 AC 53 ms
5,688 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 15 ms
4,352 KB
testcase_13 AC 26 ms
4,348 KB
testcase_14 AC 52 ms
5,752 KB
testcase_15 AC 34 ms
4,764 KB
testcase_16 AC 7 ms
4,352 KB
testcase_17 AC 12 ms
4,348 KB
testcase_18 AC 53 ms
6,004 KB
testcase_19 AC 53 ms
5,956 KB
testcase_20 AC 53 ms
6,000 KB
testcase_21 AC 53 ms
6,072 KB
testcase_22 AC 53 ms
6,000 KB
testcase_23 AC 52 ms
6,012 KB
testcase_24 AC 51 ms
5,960 KB
testcase_25 AC 52 ms
5,896 KB
testcase_26 AC 52 ms
5,956 KB
testcase_27 AC 51 ms
6,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
//const lint MOD =1000000007;
const lint MOD=998244353;
const lint MAX = 4000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#pragma GCC optimize("Ofast")
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)


 
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }
    template <class T>
class SegTree {
    int n;                       // 葉の数
    vector<T> data;              // データを格納するvector
    T def;                       // 初期値かつ単位元
    function<T(T, T)> operation; // 区間クエリで使う処理
    function<T(T, T)> update;    // 点更新で使う処理

    // 区間[a,b)の総和。ノードk=[l,r)に着目している。
    T _query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return def; // 交差しない
        if (a <= l && r <= b)
            return data[k]; // a,l,r,bの順で完全に含まれる
        else {
            T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
            T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
            return operation(c1, c2);
        }
    }

  public:
    // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
    // _update:更新関数 
    SegTree(size_t _n, T _def, function<T(T, T)> _operation,
            function<T(T, T)> _update)
        : def(_def), operation(_operation), update(_update) {
        n = 1;
        while (n < _n) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, def);
    }

    // 場所i(0-indexed)の値をxで更新
    void change(int i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    // [a, b)の区間クエリを実行
    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    // 添字でアクセス
    T operator[](int i) {
        return data[i + n - 1];
    }
};


  
    int main(){
        lint n;
        cin>>n;
        vector<lint> r(n-1);
        rep(i,n-1)cin>>r[i];
        rep(i,n-1)--r[i];
        SegTree<lint> st(n,INF,
              [](lint a,lint b){return min(a,b);},
              [](lint a,lint b){return b;});
              st.change(n-1,0);
              rep(i,n-1){
                  st.change(n-i-2,st.query(n-i-1,r[n-i-2]+1)+1);
              }
        rep(i,1)cout<<st.operator[](i)<<" ";
        cout<<endl;
        }

       
       
       
       

       

    

        


        
        



    
0