結果
| 問題 | No.2710 How many more? | 
| コンテスト | |
| ユーザー |  graythunder1 | 
| 提出日時 | 2024-08-25 02:52:17 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 342 ms / 2,000 ms | 
| コード長 | 1,039 bytes | 
| コンパイル時間 | 1,875 ms | 
| コンパイル使用メモリ | 173,548 KB | 
| 実行使用メモリ | 12,632 KB | 
| 最終ジャッジ日時 | 2024-08-25 02:52:25 | 
| 合計ジャッジ時間 | 7,509 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 17 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007
//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;
int main(){
  ll N, Q;
  cin >> N >> Q;
  ll A[N];
  rep(i, N) cin >> A[i];
  vector<pll> queries;
  rep(i, Q) {
    ll x, y;
    cin >> x >> y;
    queries.emplace_back(x, y);
  }
  ll sorted_A[N];
  copy(A, A+N, sorted_A);
  sort(sorted_A, sorted_A+N);
  map<ll, pll> idx_map;
  ll bidx = 0;
  rep(i, N) {
    if (i == N-1 || sorted_A[i] != sorted_A[i+1]) {
      idx_map.emplace(sorted_A[i], make_pair(bidx, i));
      bidx = i+1;
    }
  }
  rep(q, Q) {
    ll x, y, ans;
    x = queries[q].first - 1;
    y = queries[q].second - 1;
    if (A[x] <= A[y]) ans = 0;
    else ans = idx_map[A[x]].first - idx_map[A[y]].second - 1;
    cout << ans << endl;
  }
  return 0;
}
            
            
            
        