結果

問題 No.1975 Zigzag Sequence
ユーザー kabipoyokabipoyo
提出日時 2022-06-10 22:09:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 1,519 bytes
コンパイル時間 5,213 ms
コンパイル使用メモリ 277,220 KB
実行使用メモリ 19,788 KB
最終ジャッジ日時 2023-10-21 05:15:10
合計ジャッジ時間 9,610 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 15 ms
4,748 KB
testcase_04 AC 7 ms
4,348 KB
testcase_05 AC 100 ms
7,116 KB
testcase_06 AC 85 ms
8,700 KB
testcase_07 AC 16 ms
4,764 KB
testcase_08 AC 62 ms
5,268 KB
testcase_09 AC 133 ms
11,076 KB
testcase_10 AC 80 ms
7,116 KB
testcase_11 AC 88 ms
7,644 KB
testcase_12 AC 18 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 74 ms
5,268 KB
testcase_19 AC 74 ms
5,268 KB
testcase_20 AC 84 ms
6,588 KB
testcase_21 AC 83 ms
6,588 KB
testcase_22 AC 151 ms
19,788 KB
testcase_23 AC 154 ms
19,788 KB
testcase_24 AC 163 ms
19,788 KB
testcase_25 AC 161 ms
19,788 KB
testcase_26 AC 98 ms
6,588 KB
testcase_27 AC 180 ms
12,924 KB
testcase_28 AC 153 ms
19,788 KB
testcase_29 AC 151 ms
19,788 KB
testcase_30 AC 157 ms
19,788 KB
testcase_31 AC 156 ms
19,788 KB
testcase_32 AC 74 ms
5,268 KB
testcase_33 AC 75 ms
5,268 KB
testcase_34 AC 102 ms
7,644 KB
testcase_35 AC 101 ms
7,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;
using mint = modint1000000007;
using vm = vector<mint>;
template<class T> map<T, int> coord_comp(set<T> s) {
	int a = 0;
	map<T, int> m;
	for (auto u : s) m[u] = ++a;
	return m;
}

int main() {
	lint N;
	cin >> N;
	vi v(N);
	vin(v);

	mint a=0, b=0, c=0;
	lint x, y, z;
	set<lint> s;
	rep(i, N) s.insert(v[i]);
	map<lint, int> m = coord_comp(s);
	fenwick_tree<mint> l(N+2), r(N+2), f(N+2);
	a = 1, b = ((mint)2).pow(N-1);
	rep(i, N) {
		x = m[v[i]];
		c += l.sum(0, x)*b;
		c += r.sum(x+1, N+2)*b;
		f.add(x, a);
		l.add(x, f.sum(x+1, N+2));
		r.add(x, f.sum(0, x));
		a *= 2;
		b /= 2;
	}
	std::cout << c.val() << '\n';
}
0