結果

問題 No.2710 How many more?
ユーザー rurunrurun
提出日時 2024-03-31 14:36:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 209,756 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 14:36:39
合計ジャッジ時間 5,837 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 209 ms
6,676 KB
testcase_03 AC 125 ms
6,676 KB
testcase_04 AC 95 ms
6,676 KB
testcase_05 AC 71 ms
6,676 KB
testcase_06 AC 82 ms
6,676 KB
testcase_07 AC 92 ms
6,676 KB
testcase_08 AC 68 ms
6,676 KB
testcase_09 AC 176 ms
6,676 KB
testcase_10 AC 103 ms
6,676 KB
testcase_11 AC 167 ms
6,676 KB
testcase_12 AC 230 ms
6,676 KB
testcase_13 AC 246 ms
6,676 KB
testcase_14 AC 245 ms
6,676 KB
testcase_15 AC 246 ms
6,676 KB
testcase_16 AC 246 ms
6,676 KB
testcase_17 AC 245 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int main() {
  int n, q;
  cin >> n >> q;
  vector<pair<int, int>> kyori(n);
  vector<int> pos(n), pos2(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    kyori[i] = {a, i};
  }
  sort(kyori.begin(), kyori.end());
  for (int i = 0; i < n; i++) {
    if (i != 0 && kyori[i-1].first == kyori[i].first) {
      pos[kyori[i].second] = pos[kyori[i-1].second];
    }
    else {
      pos[kyori[i].second] = i;
    }
  }
  for (int i = n-1; i >= 0; i--) {
    if (i != n-1 && kyori[i+1].first == kyori[i].first) {
      pos2[kyori[i].second] = pos2[kyori[i+1].second];
    }
    else {
      pos2[kyori[i].second] = i;
    }
  }
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << max(0, pos[x]-pos2[y]-1) << endl;
  }
}
0