結果
問題 | No.404 部分門松列 |
ユーザー | Kurl |
提出日時 | 2024-10-13 00:44:04 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 250 ms / 2,000 ms |
コード長 | 2,109 bytes |
コンパイル時間 | 1,677 ms |
コンパイル使用メモリ | 177,348 KB |
実行使用メモリ | 23,736 KB |
最終ジャッジ日時 | 2024-10-13 00:44:14 |
合計ジャッジ時間 | 8,335 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
17,544 KB |
testcase_01 | AC | 7 ms
17,444 KB |
testcase_02 | AC | 6 ms
17,824 KB |
testcase_03 | AC | 6 ms
17,428 KB |
testcase_04 | AC | 7 ms
17,636 KB |
testcase_05 | AC | 7 ms
17,388 KB |
testcase_06 | AC | 8 ms
17,252 KB |
testcase_07 | AC | 8 ms
18,204 KB |
testcase_08 | AC | 8 ms
18,128 KB |
testcase_09 | AC | 7 ms
17,472 KB |
testcase_10 | AC | 6 ms
17,596 KB |
testcase_11 | AC | 7 ms
17,896 KB |
testcase_12 | AC | 7 ms
17,124 KB |
testcase_13 | AC | 114 ms
20,328 KB |
testcase_14 | AC | 91 ms
19,480 KB |
testcase_15 | AC | 93 ms
19,236 KB |
testcase_16 | AC | 118 ms
21,540 KB |
testcase_17 | AC | 172 ms
21,892 KB |
testcase_18 | AC | 84 ms
18,168 KB |
testcase_19 | AC | 59 ms
19,268 KB |
testcase_20 | AC | 104 ms
20,612 KB |
testcase_21 | AC | 179 ms
21,140 KB |
testcase_22 | AC | 103 ms
18,336 KB |
testcase_23 | AC | 132 ms
20,736 KB |
testcase_24 | AC | 166 ms
21,148 KB |
testcase_25 | AC | 250 ms
23,736 KB |
testcase_26 | AC | 230 ms
22,484 KB |
testcase_27 | AC | 53 ms
19,000 KB |
testcase_28 | AC | 138 ms
19,520 KB |
testcase_29 | AC | 182 ms
21,904 KB |
testcase_30 | AC | 114 ms
19,196 KB |
testcase_31 | AC | 33 ms
17,736 KB |
testcase_32 | AC | 154 ms
21,656 KB |
testcase_33 | AC | 161 ms
21,132 KB |
testcase_34 | AC | 148 ms
19,844 KB |
ソースコード
# include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 200010; ll n, cnt, godamn, q; ll a[N], b[N]; ll lt[N], rt[N]; ll c[N]; vector <ll> G[N]; vector <ll> sum(N), ans(N); map <ll, ll> id; ll lowbit(ll x) {return x & (-x);} void add(ll x, ll ADD) { for (int i = x; i <= n; i += lowbit(i)) c[i] += ADD; } ll ask(ll x) { ll res; res = 0; for (int i = x; i; i -= lowbit(i)) res += c[i]; return res; } ll find(ll x, ll y) {return lower_bound(b, b + y, x) - b;} int main() { scanf("%lld", &n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]), b[i] = a[i]; sort(b, b + n); cnt = unique(b, b + n) - b; for (int i = 0; i < n; i++) a[i] = find(a[i], cnt); for (int i = 0; i < n; i++) G[a[i]].push_back(i); // cout << cnt << endl; // cout<<"?1\n"; for (int i = 0; i < cnt; i++) { for (ll j = 0; j < G[i].size(); j++) { lt[G[i][j]] = j; rt[G[i][j]] = G[i].size() - 1 - j; // cout << lt[G[i][j]] << " " << rt[G[i][j]] << endl; } } // cout<<"?2\n"; for (ll i = 0, ed; i < cnt; i++) { ed = G[i].size() - 1; for (ll j = 0; j <= ed; j++) { sum[G[i][j] + 1] += ((j + 1) * (ed - j) - j * (ed - j + 1)); // cout << G[i][j] + 1 << " " << sum[G[i][j] + 1] << endl; } } // cout<<"?3\n"; for (ll i = 0; i < n; i++) { sum[i + 1] += sum[i]; ans[a[i] + 1] -= sum[i]; // cout << sum[i + 1] << " " << ans[a[i] + 1] << endl; } // cout<<"?4\n"; godamn = 0; for (ll i = 0; i < cnt; i++) { for (auto x : G[i]) { ll num, num2, sum, sum2; num = ask(x); num2 = x - num - lt[x]; sum = godamn - num; sum2 = (n - 1 - x) - sum - rt[x]; ans[i + 1] += num * sum + num2 * sum2; // cout << num << " " << num2 << " " << sum << " " << sum2 << " " << ans[i + 1] << endl; } for (ll j = 0; j < G[i].size(); j++) ans[i + 1] += (G[i].size() - j) * j; godamn += G[i].size(); for (auto x : G[i]) add(x + 1, 1); } // cout<<"?5\n"; for (ll i = 0; i < cnt; i++) ans[i + 1] += ans[i]; scanf("%lld", &q); while (q--) { ll l, h; scanf("%lld%lld", &l, &h); printf("%lld\n", ans[find(h + 1, cnt)] - ans[find(l, cnt)]); } return 0; }