結果
| 問題 | No.2710 How many more? | 
| コンテスト | |
| ユーザー |  kekenx | 
| 提出日時 | 2024-05-26 21:53:58 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 437 ms / 2,000 ms | 
| コード長 | 613 bytes | 
| コンパイル時間 | 846 ms | 
| コンパイル使用メモリ | 89,348 KB | 
| 最終ジャッジ日時 | 2025-02-21 16:50:27 | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 17 | 
ソースコード
#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main() {
  int N, Q; cin >> N >> Q;
  vector<int> A(N);
  for (int &a: A) {
    cin >> a;
    a = -a;
  }
  vector<int> b = A;
  sort(b.begin(), b.end());
  map<int, vector<int>> mp;
  for (int i = 0; i < N; i++) {
    mp[b[i]].push_back(i);
  }
  while (Q--) {
    int x, y; cin>> x>> y;
    x--; y--;
    int a1 = A[x], a2 = A[y];
    int frm = mp[a1].back(), to = mp[a2][0];
    if (frm >= to)
      cout << 0 << endl;
    else
      cout << to - frm - 1 << endl;
  } 
  return 0;
}
  
            
            
            
        