結果

問題 No.2374 ASKT Subsequences
ユーザー erbowlerbowl
提出日時 2023-07-07 23:10:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,583 bytes
コンパイル時間 5,379 ms
コンパイル使用メモリ 204,708 KB
実行使用メモリ 13,544 KB
最終ジャッジ日時 2023-09-29 00:54:22
合計ジャッジ時間 9,038 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,544 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 10 ms
4,376 KB
testcase_20 AC 16 ms
4,380 KB
testcase_21 AC 21 ms
4,380 KB
testcase_22 AC 14 ms
4,376 KB
testcase_23 AC 13 ms
4,380 KB
testcase_24 AC 12 ms
4,380 KB
testcase_25 AC 1,813 ms
4,588 KB
testcase_26 AC 48 ms
4,384 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long

// Segment Tree
template<class Monoid> struct SegTree {
    using Func = function<Monoid(Monoid, Monoid)>;

    // core member
    int SIZE;
    Func F;
    Monoid IDENTITY;
    
    // data
    int offset;
    vector<Monoid> dat;

    // constructor
    SegTree() {}
    SegTree(int n, const Func &f, const Monoid &identity)
    : SIZE(n), F(f), IDENTITY(identity) {
        offset = 1;
        while (offset < n) offset *= 2;
        dat.assign(offset * 2, IDENTITY);
    }
    void init(int n, const Func &f, const Monoid &identity) {
        SIZE = n;
        F = f;
        IDENTITY = identity;
        offset = 1;
        while (offset < n) offset *= 2;
        dat.assign(offset * 2, IDENTITY);
    }
    int size() const { return SIZE; }
    
    // set, a is 0-indexed //
    // build(): O(N)
    void set(int a, const Monoid &v) { dat[a + offset] = v; }
    void build() {
        for (int k = offset - 1; k > 0; --k)
            dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    void build(const vector<Monoid> &vec) {
        for (int a = 0; a < vec.size() && a + offset < dat.size(); ++a)
            set(a, vec[a]);
        build();
    }
    
    // update a, a is 0-indexed, O(log N)
    void update(int a, const Monoid &v) {
        int k = a + offset;
        dat[k] = v;
        while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    // get [a, b), a and b are 0-indexed, O(log N)
    Monoid get(int a, int b) {
        Monoid vleft = IDENTITY, vright = IDENTITY;
        for (int left = a + offset, right = b + offset; left < right;
        left >>= 1, right >>= 1) {
            if (left & 1) vleft = F(vleft, dat[left++]);
            if (right & 1) vright = F(dat[--right], vright);
        }
        return F(vleft, vright);
    }
    Monoid get_all() { return dat[1]; }
    Monoid operator [] (int a) const { return dat[a + offset]; }
    
    // get max r that f(get(l, r)) = True (0-indexed), O(log N)
    // f(IDENTITY) need to be True
    int max_right(const function<bool(Monoid)> f, int l = 0) {
        if (l == SIZE) return SIZE;
        l += offset;
        Monoid sum = IDENTITY;
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(F(sum, dat[l]))) {
                while (l < offset) {
                    l = l * 2;
                    if (f(F(sum, dat[l]))) {
                        sum = F(sum, dat[l]);
                        ++l;
                    }
                }
                return l - offset;
            }
            sum = F(sum, dat[l]);
            ++l;
        } while ((l & -l) != l);  // stop if l = 2^e
        return SIZE;
    }

    // get min l that f(get(l, r)) = True (0-indexed), O(log N)
    // f(IDENTITY) need to be True
    int min_left(const function<bool(Monoid)> f, int r = -1) {
        if (r == 0) return 0;
        if (r == -1) r = SIZE;
        r += offset;
        Monoid sum = IDENTITY;
        do {
            --r;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(F(dat[r], sum))) {
                while (r < offset) {
                    r = r * 2 + 1;
                    if (f(F(dat[r], sum))) {
                        sum = F(dat[r], sum);
                        --r;
                    }
                }
                return r + 1 - offset;
            }
            sum = F(dat[r], sum);
        } while ((r & -r) != r);
        return 0;
    }
    
    // debug
    friend ostream& operator << (ostream &s, const SegTree &seg) {
        for (int i = 0; i < seg.size(); ++i) {
            s << seg[i];
            if (i != seg.size()-1) s << " ";
        }
        return s;
    }
};

signed main(){
    std::cin.tie(0)->sync_with_stdio(0);
    ll n;
    std::cin >> n;
    vector<ll> a(n);
    vector<vector<ll>> p(n);//,p10(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if(a[i]+1==a[j]){
                p[i].push_back(j);
            }
        }
    }
    
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        priority_queue<ll,vector<ll>,greater<ll>> pq;
        for (int j = i+1; j < n; j++) {
            while(pq.size()&&pq.top()<=j)pq.pop();
            if(a[i]+10==a[j]){
                ans += pq.size();
            }
            for (auto e : p[j]) {
                if(a[j]>=a[i]+11){
                    pq.push(e);
                }
            }
        }
    }
    std::cout << ans << std::endl;
}
0