結果

問題 No.2710 How many more?
ユーザー takumi152takumi152
提出日時 2024-03-31 14:40:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 1,021 bytes
コンパイル時間 1,151 ms
コンパイル使用メモリ 110,188 KB
実行使用メモリ 10,192 KB
最終ジャッジ日時 2024-03-31 14:40:18
合計ジャッジ時間 4,563 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 177 ms
9,472 KB
testcase_03 AC 99 ms
6,784 KB
testcase_04 AC 63 ms
6,676 KB
testcase_05 AC 54 ms
6,676 KB
testcase_06 AC 55 ms
6,676 KB
testcase_07 AC 85 ms
6,676 KB
testcase_08 AC 57 ms
6,676 KB
testcase_09 AC 143 ms
8,320 KB
testcase_10 AC 82 ms
6,676 KB
testcase_11 AC 167 ms
8,448 KB
testcase_12 AC 190 ms
9,728 KB
testcase_13 AC 197 ms
10,192 KB
testcase_14 AC 200 ms
10,192 KB
testcase_15 AC 199 ms
10,192 KB
testcase_16 AC 199 ms
10,192 KB
testcase_17 AC 200 ms
10,192 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (auto &x: a) cin >> x;
  vector<vector<int>> queries(q, vector<int>(2));
  for (auto &x: queries) {
    cin >> x[0] >> x[1];
    x[0]--;
    x[1]--;
  }

  vector<int> a_sorted(a);
  sort(a_sorted.begin(), a_sorted.end());

  vector<int> ans;
  for (auto &query: queries) {
    int r = query[0];
    int l = query[1];
    int al = upper_bound(a_sorted.begin(), a_sorted.end(), a[l]) - a_sorted.begin();
    int ar = lower_bound(a_sorted.begin(), a_sorted.end(), a[r]) - a_sorted.begin();
    ans.push_back(max(0, ar - al));
  }

  for (auto &x: ans) cout << x << endl;

  return 0;
}
0