結果

問題 No.1496 不思議な数え上げ
ユーザー SSRSSSRS
提出日時 2021-04-30 23:04:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,258 bytes
コンパイル時間 1,860 ms
コンパイル使用メモリ 175,728 KB
実行使用メモリ 22,476 KB
最終ジャッジ日時 2023-09-26 07:44:43
合計ジャッジ時間 8,885 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,764 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
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>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P[i];
  }
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<long long> S(N + 1);
  S[0] = 0;
  for (int i = 0; i < N; i++){
    S[i + 1] = S[i] + P[i];
  }
  vector<int> p(N);
  for (int i = 0; i < N; i++){
    p[P[i] - 1] = i;
  }
  set<int> st;
  st.insert(-1);
  st.insert(N);
  vector<int> L(N), R(N);
  for (int i = 0; i < N; i++){
    auto itr1 = prev(st.lower_bound(p[i]));
    L[i] = *itr1 + 1;
    auto itr2 = st.lower_bound(p[i]);
    R[i] = *itr2;
    st.insert(p[i]);
  }
  for (int i = 0; i < N; i++){
    int Lcnt = p[i] - L[i] + 1;
    int Rcnt = R[i] - p[i];
    if (true){
      long long ans = 0;
      for (int j = L[i]; j <= p[i]; j++){
        auto itr = upper_bound(S.begin() + p[i] + 1, S.begin() + R[i] + 1, A[i] + S[j]);
        ans += itr - (S.begin() + p[i] + 1);
      }
      cout << ans << endl;
    } else {
      long long ans = 0;
      for (int j = p[i] + 1; j <= R[i]; j++){
        auto itr = lower_bound(S.begin() + L[i], S.begin() + p[i] + 1, S[j] - A[i]);
        ans += (S.begin() + p[i] + 1) - itr;
      }
      cout << ans << endl;
    }
  }
}
0