結果

問題 No.1996 <><
ユーザー MasKoaTSMasKoaTS
提出日時 2023-09-03 15:49:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 2,034 bytes
コンパイル時間 2,549 ms
コンパイル使用メモリ 210,000 KB
実行使用メモリ 20,808 KB
最終ジャッジ日時 2023-09-03 15:49:17
合計ジャッジ時間 5,017 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 27 ms
12,084 KB
testcase_12 AC 52 ms
20,772 KB
testcase_13 AC 76 ms
20,808 KB
testcase_14 AC 72 ms
20,224 KB
testcase_15 AC 62 ms
17,828 KB
testcase_16 AC 54 ms
16,092 KB
testcase_17 AC 63 ms
17,836 KB
testcase_18 AC 51 ms
11,892 KB
testcase_19 AC 43 ms
13,472 KB
testcase_20 AC 42 ms
12,944 KB
testcase_21 AC 55 ms
16,000 KB
testcase_22 AC 65 ms
18,204 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 36 ms
11,780 KB
testcase_25 AC 17 ms
7,668 KB
testcase_26 AC 30 ms
9,980 KB
testcase_27 AC 7 ms
4,744 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 16 ms
7,028 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 7 ms
4,664 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define mod 1000000007ll
#define lb(a, x) lower_bound(a.begin(), a.end(), x) - a.begin()
using namespace std;
using ll = long long;

template <typename T>
struct BinaryIndexedTree {
    int N;
    vector<T> data;

    BinaryIndexedTree(void){

    };

    BinaryIndexedTree(int size) { 
        N = size + 2;
        data = vector<T>(size + 1);
    }


    T sum(int r) {
        if (r <= 0) {
            return 0;
        }
        T ret(0);
        for (r = r; r > 0; r -= r & -r){
            ret += data[r];
        }
        return ret;
    }

    T sum(int l, int r) { 
        return sum(r) - sum(l); 
    }


    T operator[](int k) { 
        return sum(k + 1) - sum(k); 
    }


    void add(int k, T x) {
        for (++k; k < N; k += k & -k) {
            data[k] += x;
        }
    }

    void range_add(int l, int r, T x) {
        add(l, x);
        add(r, -x);
    }

    
    int lower_bound(T w) {
        if (w <= 0) { 
            return 0;
        }
        int x = 0;
        for (int k = 1 << __lg(N); k; k >>= 1) {
            if (x + k <= N - 1 && data[x + k] < w) {
                w -= data[x + k];
                x += k;
            }
        }
        return x;
    }

    
    int upper_bound(T w) {
        return lower_bound(w + 1);
    }
};


int main(){
    int N, K;	cin >> N >> K;
	vector<ll> a(N);
	for(auto& x : a){
        cin >> x;
    }
	string s;	cin >> s;

	vector<ll> st = a;	sort(st.begin(), st.end());
	st.erase(unique(st.begin(), st.end()), st.end());
	for(auto& x : a){
		x = lb(st, x);
	}

	vector<vector<ll> > dp(K + 1, vector<ll>(N, 1));
	for(int i = 1; i < K + 1; ++i){
		BinaryIndexedTree<ll> bt(N);
		for(int j = 0; j < N; ++j){
			int k = (int)a[j];
			bt.add(k, dp[i - 1][j]);
            if(s[i - 1] == '<'){
                dp[i][j] = bt.sum(k) % mod;
            }
			else{
                dp[i][j] = bt.sum(k + 1, N) % mod;
            }
		}
	}

	ll ans = 0;
	for (ll t : dp[K]) {
		ans += t;
		ans %= mod;
	}
	cout << ans << endl;

	return 0;
}
0