結果

問題 No.2374 ASKT Subsequences
ユーザー momoyuumomoyuu
提出日時 2023-07-08 01:13:10
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,747 bytes
コンパイル時間 3,030 ms
コンパイル使用メモリ 115,768 KB
実行使用メモリ 38,852 KB
最終ジャッジ日時 2023-09-29 02:45:57
合計ジャッジ時間 6,028 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 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,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,680 KB
testcase_15 AC 4 ms
5,364 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 5 ms
6,432 KB
testcase_18 AC 9 ms
10,604 KB
testcase_19 AC 8 ms
9,640 KB
testcase_20 AC 16 ms
17,256 KB
testcase_21 AC 20 ms
20,692 KB
testcase_22 AC 13 ms
14,372 KB
testcase_23 AC 10 ms
11,036 KB
testcase_24 AC 10 ms
11,028 KB
testcase_25 AC 19 ms
12,028 KB
testcase_26 AC 32 ms
34,420 KB
testcase_27 AC 78 ms
38,852 KB
testcase_28 AC 47 ms
35,692 KB
testcase_29 AC 33 ms
34,624 KB
testcase_30 AC 101 ms
38,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
using ll = long long;


template< typename T >
struct BIT2D{
    int H,W;
    vector<vector<T>> data;
    BIT2D(int h,int w):H(h),W(w),data(h+1,vector<T>(w+1,0)){}

    void add(int h,int w,T x){
        h++;w++;
        for(int i = h;i<=H;i+=i&(-i)){
            for(int j = w;j<=W;j+=j&(-j)){
                data[i][j] += x;
            }
        }
    }

    //sum of [l,r)
    T sum(int h1,int w1,int h2,int w2){
        return sum(h2,w2)-sum(h2,w1-1)-sum(h1-1,w2)+sum(h1-1,w1-1);
    }

    T sum(int h,int w){
        h++;w++;
        T now = 0;
        for(int i = h;i>0;i-=i&(-i)){
            for(int j = w;j>0;j-=j&(-j)){
                now += data[i][j];
            }
        }
        return now;
    }
};  

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    ll ans = 0;
    vector<vector<pair<int,int>>> u1(2001),u2(2001);
    for(int i = 0;i<n;i++) for(int j = i+1;j<n;j++){
        if(a[j]==a[i]+10) {
            u1[a[i]].push_back(make_pair(i,j));
        }
        if(a[j]==a[i]+1){
            u2[a[i]].push_back(make_pair(i,j));
        }
    }
    BIT2D<ll> b(n+1,n+1);
    for(int i = 2000;i>=0;i--){
        int want = i + 11;
        if(want<=2000){
            for(int j = 0;j<u2[want].size();j++){
                int ni = u2[want][j].first;
                int nj = u2[want][j].second;
                b.add(ni,nj,1);
            }
        }
        for(int j = 0;j<u1[i].size();j++){
            int ni = u1[i][j].first;
            int nj = u1[i][j].second;
            ans += b.sum(ni+1,nj+1,nj,n);
        }
    }
    cout <<ans<<endl;

}

0