結果

問題 No.1496 不思議な数え上げ
ユーザー penguinmanpenguinman
提出日時 2021-04-28 04:07:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,548 bytes
コンパイル時間 4,549 ms
コンパイル使用メモリ 206,068 KB
実行使用メモリ 17,256 KB
最終ジャッジ日時 2023-09-23 03:32:48
合計ジャッジ時間 15,381 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,500 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 591 ms
17,016 KB
testcase_04 AC 587 ms
17,256 KB
testcase_05 AC 589 ms
17,068 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 566 ms
17,108 KB
testcase_10 AC 561 ms
16,908 KB
testcase_11 AC 565 ms
16,968 KB
testcase_12 AC 562 ms
17,108 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using ll = long long;
#define rep(i,j,k) for(int i=int(j); i<int(k); i++)
#define REP(i,j,k) for(int i=int(j); i<=int(k); i++)

int main(){
    ll N; cin >> N;
    vector<ll> P(N);
    rep(i,0,N) cin >> P[i];
    bool flag = false;
    rep(i,0,N) if(P[i] != N-i) flag = true;
    assert(flag);
    vector<ll> sum(N+1), rev(N);
    rep(i,0,N){
        sum[i+1] = sum[i]+P[i];
        rev[--P[i]] = i;
    }
    std::set<ll> set;
    set.insert(-1);
    set.insert(N);
    rep(i,0,N){
        ll A; cin >> A;
        auto itr = set.lower_bound(rev[i]);
        ll right = *itr;
        itr--;
        ll left = *itr;
        ll ans = 0;
        if(false){
            rep(r,rev[i],right){
                //右端固定
                ll l = std::lower_bound(sum.begin(),sum.end(),sum[r+1]-A)-sum.begin();
                //left < l ≤ rev[i] を満たす必要がある
                l = std::max(l, left+1);
                l = std::min(l, rev[i]+1);
                ans += rev[i]-l+1;
            }
        }
        else{
            REP(l,left+1,rev[i]){
                //左端固定
                ll r = std::upper_bound(sum.begin(),sum.end(),sum[l]+A)-sum.begin()-2;
                //rev[i] ≤ r < right を満たす必要がある
                r = std::min(r, right-1);
                r = std::max(r, rev[i]-1);
                ans += r-rev[i]+1;
            }
        }
        cout << ans << "\n";
        set.insert(rev[i]);
    }
}
0