結果

問題 No.1975 Zigzag Sequence
ユーザー monnumonnu
提出日時 2022-06-11 00:21:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,692 bytes
コンパイル時間 4,264 ms
コンパイル使用メモリ 236,336 KB
実行使用メモリ 8,900 KB
最終ジャッジ日時 2023-10-21 06:19:43
合計ジャッジ時間 7,393 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 10 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 52 ms
6,296 KB
testcase_07 AC 11 ms
4,348 KB
testcase_08 AC 55 ms
6,560 KB
testcase_09 AC 78 ms
7,352 KB
testcase_10 AC 56 ms
6,296 KB
testcase_11 AC 62 ms
6,560 KB
testcase_12 WA -
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 67 ms
8,900 KB
testcase_19 AC 67 ms
8,900 KB
testcase_20 AC 74 ms
8,900 KB
testcase_21 AC 73 ms
8,900 KB
testcase_22 AC 72 ms
8,144 KB
testcase_23 AC 71 ms
8,144 KB
testcase_24 AC 77 ms
8,144 KB
testcase_25 WA -
testcase_26 AC 88 ms
8,144 KB
testcase_27 AC 94 ms
8,144 KB
testcase_28 AC 75 ms
8,144 KB
testcase_29 AC 75 ms
8,144 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 68 ms
8,640 KB
testcase_33 AC 69 ms
8,640 KB
testcase_34 WA -
testcase_35 AC 81 ms
8,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define INF 1000000000000000000
#define MOD 1000000007
#define MAX 500

class BIT{
  int n;
  vector<ll> a;
public:
  BIT(int n_):n(n_){
    a.resize(n+1,0);
  }
  void add(int i,ll x){
    while(i<=n){
      a[i]+=x;
      a[i]%=MOD;
      i+=i&(-i);
    }
  }
  ll sum(int i){
    ll ret=0;
    while(i>0){
      ret+=a[i];
      i-=i&(-i);
    }
    return ret;
  }
  ll sum(int l,int r){
    return (sum(r)+MOD-sum(l-1))%MOD;
  }
};

int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i].first;
    A[i].second=i;
  }
  sort(A.begin(),A.end());

  vector<ll> p2(N+1,1);
  for(int i=0;i<N;i++){
    p2[i+1]=2*p2[i]%MOD;
  }

  ll ans=0;
  BIT left_tree1(N);
  BIT right_tree1(N);
  int i=0;

  while(i<N){
    int a=A[i].first;
    vector<int> index;
    while(i<N&&A[i].first==a){
      index.push_back(A[i].second);
      i++;
    }
    for(int k:index){
      ans+=left_tree1.sum(k+1)*right_tree1.sum(k+1,N)%MOD;
      ans%=MOD;
    }
    for(int k:index){
      left_tree1.add(k+1,p2[k]);
      right_tree1.add(k+1,p2[N-(k+1)]);
    }
  }

  reverse(A.begin(),A.end());
  BIT left_tree2(N);
  BIT right_tree2(N);
  i=0;
  while(i<N){
    int a=A[i].first;
    vector<int> index;
    while(i<N&&A[i].first==a){
      index.push_back(A[i].second);
      i++;
    }
    for(int k:index){
      ans+=left_tree2.sum(k+1)*right_tree2.sum(k+1,N)%MOD;
      ans%=MOD;
    }
    for(int k:index){
      left_tree2.add(k+1,p2[k]);
      right_tree2.add(k+1,p2[N-(k+1)]);
    }
  }

  cout<<ans<<'\n';
}
0