結果

問題 No.2374 ASKT Subsequences
ユーザー momoyuumomoyuu
提出日時 2023-07-08 00:54:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,560 bytes
コンパイル時間 1,218 ms
コンパイル使用メモリ 111,652 KB
実行使用メモリ 66,088 KB
最終ジャッジ日時 2023-09-29 02:27:39
合計ジャッジ時間 3,331 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
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 AC 34 ms
18,900 KB
testcase_26 WA -
testcase_27 AC 142 ms
65,824 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    BIT2D<ll> b1(n+2,n+2),b2(n+2,n+2);
    for(int i = 0;i<n;i++) for(int j = i+1;j<n;j++){
        if(a[j]==a[i]+10) {
            b1.add(i,j,1);
        }
        if(a[j]==a[i]+1){
            b2.add(i,j,1);
        }
    }
    for(int i = 0;i<n;i++) for(int j = i+1;j<n;j++){
        if(j==i+1) continue;
        if(a[j]==a[i]+10) {
            
            ans += b2.sum(i+1,j,j+1,n);
            //cout<<i<<" "<<j<<" "<<ans<<endl;
        }
        if(a[j]==a[i]+1){
            ans += b1.sum(i+1,j,j+1,n);
            //cout<<i<<" "<<j<<" "<<ans<<endl;
        }
    }
    cout <<ans<<endl;

}

0