結果

問題 No.1496 不思議な数え上げ
ユーザー chocoruskchocorusk
提出日時 2021-04-30 23:04:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 563 ms / 3,000 ms
コード長 1,943 bytes
コンパイル時間 3,440 ms
コンパイル使用メモリ 190,128 KB
実行使用メモリ 9,460 KB
最終ジャッジ日時 2023-09-26 07:45:51
合計ジャッジ時間 25,365 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 499 ms
9,140 KB
testcase_04 AC 501 ms
9,140 KB
testcase_05 AC 500 ms
9,236 KB
testcase_06 AC 523 ms
9,460 KB
testcase_07 AC 525 ms
9,280 KB
testcase_08 AC 563 ms
9,292 KB
testcase_09 AC 522 ms
9,144 KB
testcase_10 AC 525 ms
9,136 KB
testcase_11 AC 524 ms
9,136 KB
testcase_12 AC 512 ms
9,136 KB
testcase_13 AC 515 ms
9,132 KB
testcase_14 AC 515 ms
9,184 KB
testcase_15 AC 511 ms
9,188 KB
testcase_16 AC 511 ms
9,240 KB
testcase_17 AC 525 ms
9,240 KB
testcase_18 AC 526 ms
9,144 KB
testcase_19 AC 530 ms
9,272 KB
testcase_20 AC 530 ms
9,284 KB
testcase_21 AC 533 ms
9,276 KB
testcase_22 AC 530 ms
9,192 KB
testcase_23 AC 523 ms
9,144 KB
testcase_24 AC 532 ms
9,276 KB
testcase_25 AC 524 ms
9,208 KB
testcase_26 AC 519 ms
9,140 KB
testcase_27 AC 523 ms
9,188 KB
testcase_28 AC 515 ms
9,284 KB
testcase_29 AC 520 ms
9,284 KB
testcase_30 AC 514 ms
9,144 KB
testcase_31 AC 517 ms
9,136 KB
testcase_32 AC 458 ms
8,348 KB
testcase_33 AC 252 ms
6,216 KB
testcase_34 AC 232 ms
5,900 KB
testcase_35 AC 6 ms
4,380 KB
testcase_36 AC 473 ms
8,996 KB
testcase_37 AC 267 ms
6,424 KB
testcase_38 AC 247 ms
6,168 KB
testcase_39 AC 364 ms
7,228 KB
testcase_40 AC 195 ms
5,604 KB
testcase_41 AC 362 ms
7,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
int n;
int p[200020];
ll a[200020];
ll ans[200020];
void solve(int l, int r){
    if(l==r){
        if(p[l]<=a[p[l]]) ans[p[l]]++;
        return;
    }
    int m=(l+r)/2;
    solve(l, m);
    solve(m+1, r);
    vector<int> vl1(m-l+2), vr1(r-m+1);
    vector<ll> vl2(m-l+2), vr2(r-m+1);
    vl1[0]=1e9, vr1[0]=1e9;
    for(int i=m; i>=l; i--){
        vl1[m-i+1]=min(vl1[m-i], p[i]);
        vl2[m-i+1]=vl2[m-i]+p[i];
    }
    for(int i=m+1; i<=r; i++){
        vr1[i-m]=min(vr1[i-m-1], p[i]);
        vr2[i-m]=vr2[i-m-1]+p[i];
    }
    for(int i=1; i<=m-l+1; i++){
        int mn=vl1[i];
        ll s=vl2[i];
        int k1=lower_bound(vr1.begin(), vr1.end(), mn, greater<int>())-vr1.begin();
        int k2=upper_bound(vr2.begin(), vr2.end(), a[mn]-s)-vr2.begin();
        if(min(k1, k2)>0) ans[mn]+=min(k1, k2)-1;
    }
    for(int i=1; i<=r-m; i++){
        int mn=vr1[i];
        ll s=vr2[i];
        int k1=lower_bound(vl1.begin(), vl1.end(), mn, greater<int>())-vl1.begin();
        int k2=upper_bound(vl2.begin(), vl2.end(), a[mn]-s)-vl2.begin();
        if(min(k1, k2)>0) ans[mn]+=min(k1, k2)-1;
    }
}
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>p[i];
    }
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    solve(1, n);
    for(int i=1; i<=n; i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}
0