結果

問題 No.1996 <><
ユーザー kaichou243kaichou243
提出日時 2022-07-01 21:41:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 4,317 bytes
コンパイル時間 2,356 ms
コンパイル使用メモリ 214,116 KB
実行使用メモリ 20,808 KB
最終ジャッジ日時 2023-08-17 09:07:19
合計ジャッジ時間 5,819 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 106 ms
12,084 KB
testcase_12 AC 209 ms
20,808 KB
testcase_13 AC 205 ms
20,744 KB
testcase_14 AC 197 ms
20,284 KB
testcase_15 AC 170 ms
18,084 KB
testcase_16 AC 148 ms
16,108 KB
testcase_17 AC 170 ms
17,840 KB
testcase_18 AC 99 ms
11,932 KB
testcase_19 AC 119 ms
13,428 KB
testcase_20 AC 113 ms
12,820 KB
testcase_21 AC 149 ms
16,052 KB
testcase_22 AC 174 ms
18,364 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 98 ms
11,792 KB
testcase_25 AC 45 ms
7,620 KB
testcase_26 AC 80 ms
9,972 KB
testcase_27 AC 17 ms
4,708 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 42 ms
7,020 KB
testcase_30 AC 3 ms
4,384 KB
testcase_31 AC 18 ms
4,724 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<int MOD> struct Fp{
  ll val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0) val += MOD;
  }
  static constexpr int getmod() { return MOD; }
  constexpr Fp operator - () const noexcept {
    return val ? MOD - val : 0;
  }
  constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp& operator += (const Fp& r) noexcept {
    val += r.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  constexpr Fp& operator -= (const Fp& r) noexcept {
    val -= r.val;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr Fp& operator *= (const Fp& r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp& operator /= (const Fp& r) noexcept {
    ll a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      ll t = a / b;
      a -= t * b, swap(a, b);
      u -= t * v, swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr bool operator == (const Fp& r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator != (const Fp& r) const noexcept {
    return this->val != r.val;
  }
  constexpr bool operator < (const Fp& r) const noexcept {
    return this->val < r.val;
  }
  friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
    is >> x.val;
    x.val %= MOD;
    if (x.val < 0) x.val += MOD;
    return is;
  }
  friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
    return os << x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
    Fp<MOD> res=1,r=a;
    while(n){
      if(n&1) res*=r;
      r*=r;
      n>>=1;
    }
    return res;
  }
  friend constexpr Fp<MOD> modinv(const Fp<MOD>& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        return Fp<MOD>(u);
  }
  explicit operator bool()const{
		return val;
  }
};
template<class T,T (*op)(T,T),T (*e)()> struct SegmentTree{
  int n;
  vector<T> dat;
  SegmentTree(int N){
    n=1;
    while(n<N)n*=2;
    dat.assign(2*n,e());
  }
  void add(int k,T x){
    k+=n;
    dat[k]+=x;
    while(k){
      k>>=1;
      dat[k]=op(dat[k*2],dat[k*2+1]);
    }
  }
  void apply(int k,T x){
    k+=n;
    dat[k]=op(dat[k],x);
    while(k){
      k>>=1;
      dat[k]=op(dat[k*2],dat[k*2+1]);
    }
  }
  void set(int k,T x){
    k+=n;
    dat[k]=x;
    while(k){
      k>>=1;
      dat[k]=op(dat[k*2],dat[k*2+1]);
    }
  }
  T query(int l,int r){
    T prodl=e(),prodr=e();
    l+=n;
    r+=n;
    while(l<r){
      if(l&1) prodl=op(prodl,dat[l++]);
      if(r&1) prodr=op(dat[--r],prodr);
      l>>=1;
      r>>=1;
    }
    return op(prodl,prodr);
  }
};
template <typename T>
vector<int> compress(vector<T> &x){
  vector<T> vals=x;
  vector<int> res;
  sort(vals.begin(),vals.end());
  auto it=unique(vals.begin(),vals.end());
  vals.erase(it,vals.end());
  for(auto xx : x){
    int ret=lower_bound(vals.begin(),vals.end(),xx) - vals.begin();
    res.push_back(ret);
  }
  return res;
}
using mint=Fp<1000000007>;
mint op(mint a,mint b){
    return a+b;
}
mint e(){
    return mint(0);
}
int main(){
    int n,k;
    cin>>n>>k;
    vector<ll> a(n);
    string s;
    for(int i=0;i<n;i++) cin>>a[i];
    cin>>s;
    vector<int> A=compress(a);
    vector<vector<mint>> dp(k+1,vector<mint>(n));
    for(int i=0;i<n;i++) dp[0][i]=1;
    for(int i=1;i<=k;i++){
        if(s[i-1]=='<'){
            SegmentTree<mint,op,e> S(n);
            for(int j=0;j<n;j++){
                dp[i][j]=S.query(0,A[j]);
                S.add(A[j],dp[i-1][j]);
            }
        }else{
            SegmentTree<mint,op,e> S(n);
            for(int j=0;j<n;j++){
                dp[i][j]=S.query(A[j]+1,n);
                S.add(A[j],dp[i-1][j]);
            }
        }
    }
    mint ans=0;
    for(int i=0;i<n;i++) ans+=dp[k][i];
    cout<<ans<<endl;
}
0