結果

問題 No.1496 不思議な数え上げ
ユーザー 👑 NachiaNachia
提出日時 2021-04-30 21:40:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,337 bytes
コンパイル時間 1,251 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 21,964 KB
最終ジャッジ日時 2023-09-26 05:33:06
合計ジャッジ時間 8,820 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 71 ms
11,568 KB
testcase_04 AC 93 ms
11,516 KB
testcase_05 AC 71 ms
11,564 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 <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++){
      while(SA[pr] - SA[pl] > A[v]) pl++;
      if(pl <= vp) ansv += vp - pl + 1;
    }
  }
  else{
    int pr = r;
    for(int pl=vp; pl>=l; pl--){
      while(SA[pr] - SA[pl] > A[v]) pr--;
      if(pr >= vp+1) 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