結果
| 問題 | No.2710 How many more? | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-03-31 14:40:12 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 205 ms / 2,000 ms | 
| コード長 | 1,021 bytes | 
| コンパイル時間 | 1,229 ms | 
| コンパイル使用メモリ | 105,124 KB | 
| 最終ジャッジ日時 | 2025-02-20 17:21:59 | 
| ジャッジサーバーID (参考情報) | judge1 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 17 | 
ソースコード
#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;
}
            
            
            
        