結果

問題 No.2710 How many more?
ユーザー 👑 Nafmo2Nafmo2
提出日時 2024-01-22 19:35:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 431 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 4,325 ms
コンパイル使用メモリ 273,276 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-01-22 19:47:37
合計ジャッジ時間 9,796 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 296 ms
6,784 KB
testcase_03 AC 185 ms
7,040 KB
testcase_04 AC 164 ms
8,832 KB
testcase_05 AC 111 ms
6,676 KB
testcase_06 AC 136 ms
8,064 KB
testcase_07 AC 112 ms
6,676 KB
testcase_08 AC 92 ms
6,676 KB
testcase_09 AC 286 ms
7,808 KB
testcase_10 AC 145 ms
6,676 KB
testcase_11 AC 222 ms
6,676 KB
testcase_12 AC 367 ms
8,704 KB
testcase_13 AC 413 ms
9,216 KB
testcase_14 AC 392 ms
9,216 KB
testcase_15 AC 431 ms
9,216 KB
testcase_16 AC 390 ms
9,216 KB
testcase_17 AC 393 ms
9,216 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:19:19: warning: range-based 'for' loops with initializer only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions]
   19 |   for (int i = 1; auto x : B) {
      |                   ^~~~

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using namespace atcoder;
int main() {
  int ans = 0;
  int N, Q;
  cin >> N >> Q;
  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  auto B = A;
  sort(B.rbegin(), B.rend());
  map<int, int> M;
  vector S(B.size() + 1, 0);
  B.erase(unique(B.begin(), B.end()), B.end());
  for (int i = 1; auto x : B) {
    M[x] = i;
    i++;
  }
  for (auto x : A) {
    S[M[x]]++;
  }
  for (int i = 0; i < S.size() - 1; i++) {
    S[i + 1] += S[i];
  }
  while (Q--) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << max(S[M[A[y]] - 1] - S[M[A[x]]], 0) << endl;
  }
}
0