結果

問題 No.878 Range High-Element Query
ユーザー 0w10w1
提出日時 2019-10-12 15:43:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 868 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 208,652 KB
実行使用メモリ 14,640 KB
最終ジャッジ日時 2023-08-18 18:15:51
合計ジャッジ時間 5,379 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N, Q;
  cin >> N >> Q;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  vector<vector<int>> nxt2(17, vector<int>(N, N + 1)); {
    map<int, int> mp;
    for (int i = N - 1; ~i; --i) {
      auto it = mp.upper_bound(A[i]);
      if (it != mp.end()) nxt2[0][i] = it->second;
      mp[A[i]] = i;
    }
    for (int i = 0; i + 1 < nxt2.size(); ++i) {
      for (int u = 0; u < N; ++u) {
        int v = nxt2[i][u];
        if (v < N) nxt2[i + 1][u] = nxt2[i][v];
      }
    }
  }

  while (Q--) {
    int P, L, R;
    cin >> P >> L >> R;
    --L;

    int ans = 1;
    for (int i = nxt2.size() - 1; ~i; --i) {
      if (nxt2[i][L] <= R) {
        ans += 1 << i;
        L = nxt2[i][L];
      }
    }

    cout << ans << endl;
  }

  return 0;
}
0