結果

問題 No.1496 不思議な数え上げ
ユーザー 👑 NachiaNachia
提出日時 2021-04-30 23:00:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,377 bytes
コンパイル時間 940 ms
コンパイル使用メモリ 83,336 KB
実行使用メモリ 33,252 KB
最終ジャッジ日時 2023-09-26 07:40:20
合計ジャッジ時間 7,950 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 124 ms
33,252 KB
testcase_07 AC 123 ms
33,156 KB
testcase_08 AC 125 ms
33,160 KB
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 AC 94 ms
11,484 KB
testcase_26 AC 93 ms
11,484 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/segtree>
using ll = long long;
using ull = unsigned long long;
using namespace std;

int RMQop(int l,int r){ return min(l,r); }
int RMQe(){ return 1001001001; }
using RMQ = atcoder::segtree<int,RMQop,RMQe>;

int N;
vector<ll> A;
vector<int> P;
vector<int> I;
vector<ll> SA;
vector<ll> ans;
RMQ G;

void solve(int l,int r){
  if(l == r) return;
  int v = G.prod(l,r);
  int vp = I[v];
  ll ansv = 0;
  if(vp-l > r-vp){
    int pl = l;
    for(int pr=vp+1; pr<=r; pr++){
      int pl = lower_bound(SA.begin()+l, SA.begin()+vp+1, SA[pr]-A[v]) - SA.begin();
      ansv += vp - pl + 1;
    }
  }
  else{
    for(int pl=vp; pl>=l; pl--){
      int pr = upper_bound(SA.begin()+vp, SA.begin()+r, SA[pl]+A[v]) - SA.begin();
      ansv += pr - vp;
    }
  }
  ans[v] = ansv;
  solve(l,vp);
  solve(vp+1,r);
}

int main(){
  cin >> N;
  P.resize(N); for(int i=0; i<N; i++){ cin>>P[i]; P[i]--; }
  A.resize(N); for(int i=0; i<N; i++) cin>>A[i];
  I.resize(N); for(int i=0; i<N; i++) I[P[i]] = i;
  SA.assign(N+1,0); for(int i=0; i<N; i++) SA[i+1] = SA[i] + P[i] + 1;
  ans.assign(N,0);
  G = RMQ(P);
  solve(0,N);
  for(int i=0; i<N; i++) cout << ans[i] << "\n";
  return 0;
}



struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;
0