結果

問題 No.1975 Zigzag Sequence
ユーザー renren_utsrenren_uts
提出日時 2022-06-16 10:59:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 414 ms / 2,000 ms
コード長 2,166 bytes
コンパイル時間 1,621 ms
コンパイル使用メモリ 118,312 KB
実行使用メモリ 51,656 KB
最終ジャッジ日時 2024-04-15 21:57:09
合計ジャッジ時間 9,545 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
47,948 KB
testcase_01 AC 51 ms
47,836 KB
testcase_02 AC 51 ms
47,944 KB
testcase_03 AC 65 ms
47,556 KB
testcase_04 AC 52 ms
47,180 KB
testcase_05 AC 253 ms
51,016 KB
testcase_06 AC 208 ms
50,120 KB
testcase_07 AC 65 ms
47,688 KB
testcase_08 AC 128 ms
49,604 KB
testcase_09 AC 319 ms
50,636 KB
testcase_10 AC 200 ms
49,736 KB
testcase_11 AC 228 ms
50,504 KB
testcase_12 AC 73 ms
48,584 KB
testcase_13 AC 52 ms
47,944 KB
testcase_14 AC 50 ms
48,072 KB
testcase_15 AC 54 ms
48,068 KB
testcase_16 AC 48 ms
46,916 KB
testcase_17 AC 50 ms
47,944 KB
testcase_18 AC 118 ms
51,144 KB
testcase_19 AC 117 ms
51,020 KB
testcase_20 AC 239 ms
51,656 KB
testcase_21 AC 263 ms
51,656 KB
testcase_22 AC 174 ms
51,144 KB
testcase_23 AC 173 ms
51,272 KB
testcase_24 AC 189 ms
51,144 KB
testcase_25 AC 186 ms
51,272 KB
testcase_26 AC 222 ms
51,532 KB
testcase_27 AC 414 ms
51,532 KB
testcase_28 AC 182 ms
51,140 KB
testcase_29 AC 182 ms
51,148 KB
testcase_30 AC 181 ms
51,144 KB
testcase_31 AC 179 ms
51,272 KB
testcase_32 AC 116 ms
51,144 KB
testcase_33 AC 118 ms
51,076 KB
testcase_34 AC 293 ms
51,276 KB
testcase_35 AC 292 ms
51,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <tuple>
#include <bitset>
#include <map>
#include <queue>
#include <time.h>
#include <utility>
#include <numeric>
#include <deque>
#include <cassert>
#include <sstream>
#include <cctype>
#include <unordered_map>
#include <algorithm>
#include <chrono>
#define ll long long
#include <time.h>
#define mod % 1000000007
#define rep(i,n) for(long long i = 0;i < n;i ++)
ll MAX = 5'000'000'000'000'000'000LL;
using namespace std;

ll A = 17;
ll A2 = 1LL<<17;

struct fenwick_tree{
  vector<vector<ll>> v;
  void start(){
    vector<ll> V(A2,0);
    rep(i,A)v.push_back(V);
  }
  void add(ll n,ll val){
    for(int i = 0;i < A;i ++){
      v[i][n>>i] += val;
    }
  }
  ll sum(ll n){
      n ++;
      ll s = 0;
      ll u = 0;
      ll d = A2;
      for(ll i = A-1;i >= 0;i --){
          ll m = (u+d)/2;
          if(m == n){
              s += v[i][u>>i];
              break;
          }
          if(m<n){
              s += v[i][u>>i];
              u = m;
          }
          if(m>n){
              d = m;
          }
      }
      return s;
  }
};

vector<ll> conv(vector<ll> a){
  auto b = a;
  sort(b.begin(),b.end());
  ll c = b.size();
  map<ll,ll> mp;
  for(int i = c-2;i >= 0;i --){
    if(b[i] == b[i+1])b.erase(b.begin()+i);
  }
  c = b.size();
  rep(i,c){
    mp[b[i]] = i+2;
  }
  rep(i,int(a.size())){
    a[i] = mp[a[i]];
  }
  return a;
}

int main(){
  vector<ll> exp;
  exp.push_back(1);
  rep(i,1000000)exp.push_back((exp[i]*2)mod);
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n)cin >> a[i];
  a = conv(a);
  vector<ll> lup(n);
  vector<ll> ldown(n);
  fenwick_tree f;
  f.start();
  rep(i,n){
    lup[i] = (f.sum(A2-2)-f.sum(a[i])) mod;
    ldown[i] = f.sum(a[i]-1) mod;
    f.add(a[i],exp[i]);
  }
  vector<ll> rup(n);
  vector<ll> rdown(n);
  fenwick_tree g;
  g.start();
  rep(i,n){
    rup[n-1-i] = (g.sum(A2-2)-g.sum(a[n-1-i])) mod;
    rdown[n-1-i] = g.sum(a[n-1-i]-1) mod;
    g.add(a[n-1-i],exp[i]);
  }
  ll ans = 0;
  rep(i,n){
      ans += (rup[i]*lup[i]) mod;
      ans += (ldown[i]*rdown[i]) mod;
  }
  cout << ans mod << endl;
  
  
  return 0;
}
0