結果

問題 No.1496 不思議な数え上げ
ユーザー penguinmanpenguinman
提出日時 2021-04-28 03:48:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,857 bytes
コンパイル時間 2,517 ms
コンパイル使用メモリ 208,388 KB
実行使用メモリ 16,944 KB
最終ジャッジ日時 2023-09-23 03:31:19
合計ジャッジ時間 9,070 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 108 ms
15,376 KB
testcase_04 AC 110 ms
15,488 KB
testcase_05 AC 107 ms
15,644 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
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++)
#define per(i,j,k) for(int i=int(j); int(k)<=i; i--)

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int N; cin >> N;
    vector<int> P(N), rev(N);
    rep(i,0,N) cin >> P[i];
    vector<ll> sum(N+1);
    rep(i,0,N){
        sum[i+1] = sum[i]+P[i];
        rev[--P[i]] = i;
    }
    std::set<int> set;
    set.insert(-1);
    set.insert(N);
    rep(i,0,N){
        ll A; cin >> A;
        auto itr = set.lower_bound(rev[i]);
        int right = *itr;
        itr--;
        int left = *itr;
        ll ans = 0;
        if(right-rev[i] < rev[i]-left){
            int L = left+1;
            rep(r,rev[i],right){
                //右端固定
                //left < l ≤ rev[i] を満たす必要がある
                for(;;L++){
                    if(sum[r+1]-sum[L] <= A) break;
                }
                int l = L;
                l = std::max(l, left+1);
                l = std::min(l, rev[i]+1);
                ans += rev[i]-l+1;
            }
        }
        else{
            int R = right;
            per(l,rev[i],left+1){
                //左端固定
                for(;;R--){
                    if(sum[R]-sum[l] <= A) break;
                }
                int r = R-1;
                //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