結果

問題 No.1496 不思議な数え上げ
ユーザー りあんりあん
提出日時 2021-04-30 22:30:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 260 ms / 3,000 ms
コード長 1,426 bytes
コンパイル時間 2,465 ms
コンパイル使用メモリ 208,796 KB
実行使用メモリ 17,324 KB
最終ジャッジ日時 2023-09-26 06:45:22
合計ジャッジ時間 13,330 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 135 ms
17,032 KB
testcase_04 AC 138 ms
17,156 KB
testcase_05 AC 132 ms
17,092 KB
testcase_06 AC 154 ms
17,092 KB
testcase_07 AC 151 ms
17,032 KB
testcase_08 AC 153 ms
17,080 KB
testcase_09 AC 150 ms
17,088 KB
testcase_10 AC 150 ms
17,288 KB
testcase_11 AC 151 ms
17,028 KB
testcase_12 AC 130 ms
17,240 KB
testcase_13 AC 136 ms
17,200 KB
testcase_14 AC 138 ms
17,156 KB
testcase_15 AC 137 ms
17,100 KB
testcase_16 AC 141 ms
17,080 KB
testcase_17 AC 252 ms
17,076 KB
testcase_18 AC 258 ms
17,032 KB
testcase_19 AC 241 ms
17,032 KB
testcase_20 AC 240 ms
17,324 KB
testcase_21 AC 236 ms
17,092 KB
testcase_22 AC 235 ms
17,156 KB
testcase_23 AC 230 ms
17,032 KB
testcase_24 AC 235 ms
17,088 KB
testcase_25 AC 235 ms
17,028 KB
testcase_26 AC 229 ms
17,032 KB
testcase_27 AC 253 ms
17,152 KB
testcase_28 AC 260 ms
17,096 KB
testcase_29 AC 255 ms
17,160 KB
testcase_30 AC 258 ms
17,096 KB
testcase_31 AC 260 ms
17,156 KB
testcase_32 AC 197 ms
15,564 KB
testcase_33 AC 92 ms
10,160 KB
testcase_34 AC 84 ms
9,496 KB
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 202 ms
15,780 KB
testcase_37 AC 96 ms
10,548 KB
testcase_38 AC 90 ms
10,152 KB
testcase_39 AC 131 ms
12,608 KB
testcase_40 AC 69 ms
8,632 KB
testcase_41 AC 149 ms
13,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;
// const int M = 998244353;
const long long LM = 1LL << 60;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> p(n), idx(n);
    vector<long long> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        idx[p[i] - 1] = i;
    }
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<long long> imos(n + 1);
    for (int i = 0; i < n; ++i) {
        imos[i + 1] = imos[i] + p[i];
    }
    set<int> se;
    se.insert(-1);
    se.insert(n);
    for (int k = 0; k < n; ++k) {
        long long ans = 0;
        int i = idx[k];
        int l, r;
        {
            auto ptr = se.insert(i).first;
            l = *prev(ptr) + 1;
            r = *next(ptr);
        }
        int dl = i - l + 1;
        int dr = r - i;
        if (dl <= dr) {
            for (int j = l; j <= i; ++j) {
                auto ptr = upper_bound(imos.begin(), imos.begin() + r + 1, a[k] + imos[j]);
                ans += max(ptr - (imos.begin() + i) - 1, 0L);
            }
        }
        else {
            for (int j = i + 1; j <= r; ++j) {
                auto ptr = lower_bound(imos.begin() + l, imos.end(), imos[j] - a[k]);
                ans += max((imos.begin() + i) - ptr + 1, 0L);
            }
        }
        cout << ans << '\n';
    }


    return 0;
}
0