結果

問題 No.1496 不思議な数え上げ
ユーザー りあんりあん
提出日時 2021-04-30 22:23:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,404 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 207,720 KB
実行使用メモリ 16,552 KB
最終ジャッジ日時 2023-09-26 06:31:29
合計ジャッジ時間 12,091 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 242 ms
16,364 KB
testcase_28 AC 250 ms
16,252 KB
testcase_29 AC 241 ms
16,232 KB
testcase_30 AC 250 ms
16,204 KB
testcase_31 AC 229 ms
16,240 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 3 ms
4,384 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

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), a(n), idx(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