結果

問題 No.1996 <><
ユーザー otoshigootoshigo
提出日時 2022-07-01 22:22:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 951 ms / 2,000 ms
コード長 2,367 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 222,720 KB
実行使用メモリ 51,392 KB
最終ジャッジ日時 2023-08-17 09:53:20
合計ジャッジ時間 13,268 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 476 ms
27,008 KB
testcase_12 AC 951 ms
51,392 KB
testcase_13 AC 937 ms
51,388 KB
testcase_14 AC 922 ms
49,740 KB
testcase_15 AC 730 ms
44,984 KB
testcase_16 AC 645 ms
39,948 KB
testcase_17 AC 775 ms
45,832 KB
testcase_18 AC 387 ms
30,216 KB
testcase_19 AC 511 ms
32,296 KB
testcase_20 AC 518 ms
30,044 KB
testcase_21 AC 707 ms
41,376 KB
testcase_22 AC 850 ms
44,472 KB
testcase_23 AC 18 ms
5,112 KB
testcase_24 AC 440 ms
32,932 KB
testcase_25 AC 171 ms
13,836 KB
testcase_26 AC 341 ms
25,740 KB
testcase_27 AC 47 ms
8,120 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 156 ms
11,764 KB
testcase_30 AC 7 ms
4,376 KB
testcase_31 AC 52 ms
9,096 KB
testcase_32 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,a,b) for (int i = a; i < b; i++)
#define rrep2(i,a,b) for (int i = a-1; i >= b; i--)
#define rep3(i,a,b,c) for (int i = a; i < b; i+=c)
#define rrep3(i,a,b,c) for (int i = a-1; i >= b; i-=c)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const int MOD=1e9+7;

template <class S, S (*op)(S, S), S (*e)()>
struct segtree{
    int n;
    vector<S> dat;
    segtree(int N){
        int x = 1;
        while (x < N) x *= 2;
        n = x;
        dat.resize(2*n-1, e());
    }
    void set(int i, S x){
        assert(i>=0&&i<n);
        i += n-1;
        dat[i] = x;
        while (i > 0){
            i = (i-1)/2;
            dat[i] = op(dat[2*i+1], dat[2*i+2]);
        }
    }
    S get(int i){
        assert(i>=0&&i<n);
        i += n-1;
        return dat[i];
    }
    S prod(int a, int b, int k = 0, int l = 0, int r = -1){
        if (r < 0) r = n;
        if (r <= a || l >= b) return e();
        if (l >= a && r <= b) return dat[k];
        else{
            S vl = prod(a, b, 2*k+1, l, (l+r)/2);
            S vr = prod(a, b, 2*k+2, (l+r)/2, r);
            return op(vl, vr);
        }
    }
};

ll op(ll l,ll r){
    return (l+r)%MOD;
}

ll e(){
    return 0;
}

int k,n;
ll A[1500];
char C[1500];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>k;
    vector<int>V;
    rep(i,n){
        cin>>A[i];
        V.push_back(A[i]);
    }
    sort(all(V));
    V.erase(unique(all(V)),V.end());
    map<int,int>mp;
    rep(i,V.size())mp[V[i]]=i;
    rep(i,n)A[i]=mp[A[i]];
    rep(i,k)cin>>C[i];
    vector<segtree<ll,op,e>>Seg(k+1,segtree<ll,op,e>(n+1));
    rep(i,n){
        Seg[0].set(A[i],1);
        rep(j,k){
            if(C[j]=='<'){
                Seg[j+1].set(A[i],Seg[j+1].get(A[i])+Seg[j].prod(0,A[i]));
            }else{
                Seg[j+1].set(A[i],Seg[j+1].get(A[i])+Seg[j].prod(A[i]+1,n+1));
            }
        }
    }
    ll ans=0;
    rep(i,n+1){
        ans+=Seg[k].get(i);
        ans%=MOD;
    }
    cout<<ans<<"\n";
}
0