結果

問題 No.1975 Zigzag Sequence
ユーザー HaaHaa
提出日時 2022-06-10 22:45:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 1,756 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 185,368 KB
実行使用メモリ 12,088 KB
最終ジャッジ日時 2023-10-21 05:32:18
合計ジャッジ時間 7,129 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 17 ms
4,420 KB
testcase_04 AC 8 ms
4,348 KB
testcase_05 AC 172 ms
7,600 KB
testcase_06 AC 114 ms
7,072 KB
testcase_07 AC 18 ms
4,464 KB
testcase_08 AC 103 ms
6,016 KB
testcase_09 AC 180 ms
8,656 KB
testcase_10 AC 118 ms
6,808 KB
testcase_11 AC 134 ms
7,072 KB
testcase_12 AC 26 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 102 ms
7,336 KB
testcase_19 AC 102 ms
7,336 KB
testcase_20 AC 139 ms
7,864 KB
testcase_21 AC 128 ms
7,864 KB
testcase_22 AC 159 ms
12,088 KB
testcase_23 AC 159 ms
12,088 KB
testcase_24 AC 174 ms
12,088 KB
testcase_25 AC 176 ms
12,088 KB
testcase_26 AC 176 ms
7,600 KB
testcase_27 AC 225 ms
9,976 KB
testcase_28 AC 166 ms
12,088 KB
testcase_29 AC 165 ms
12,088 KB
testcase_30 AC 165 ms
12,088 KB
testcase_31 AC 165 ms
12,088 KB
testcase_32 AC 110 ms
7,336 KB
testcase_33 AC 110 ms
7,336 KB
testcase_34 AC 162 ms
8,128 KB
testcase_35 AC 163 ms
8,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

struct BIT{
    int N;
    VI dat;
    BIT(int N):N(N){
        dat.resize(N+1,0);
    }
    ll sum(int k){
        k++;
        if(k<=0)
            return 0;
        ll res=0;
        for(;k>0;k-=k&-k)
            res=(res+dat[k])%MOD;
        return res;
    }
    ll sum(int l, int r){
        return (sum(r-1)-sum(l-1)+MOD)%MOD;
    }
    void add(int k, ll x){
        k++;
        for(;k<=N;k+=k&-k)
            dat[k]=(dat[k]+x)%MOD;
    }
};

ll power(ll x, ll y){
    x%=MOD;
    ll ret=1;
    while(y){
        if(y&1) ret=ret*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ret;
}

int main(){
    int n; cin >> n;
    VI a(n); REP(i,n) cin >> a[i];
    VI sa=a; sort(ALL(sa));
    map<int,int> idx;
    REP(i,n) idx[sa[i]]=i;
    BIT btx(n), btl(n), btr(n);
    ll ans=0;
    REP(i,n){
        int j=idx[a[i]];
        btx.add(j,btx.sum(j,j+1));
        btx.add(j,btl.sum(j,j+1));
        btx.add(j,btr.sum(j,j+1));
        btx.add(j,1);
        ll lsl=btl.sum(0,j), lsr=btl.sum(j+1,n);
        ans=(ans+lsl*power(2,n-1-i)%MOD)%MOD;
        btr.add(j,lsl+btx.sum(0,j));
        btl.add(j,lsr);
        ll rsr=btr.sum(j+1,n), rsl=btr.sum(0,j);
        ans=(ans+rsr*power(2,n-1-i)%MOD)%MOD;
        btl.add(j,rsr+btx.sum(j+1,n));
        btr.add(j,rsl);
    }
    cout << ans << endl;
    return 0;
}
0