結果

問題 No.2710 How many more?
ユーザー yansi819
提出日時 2024-04-02 17:55:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 584 bytes
コンパイル時間 4,651 ms
コンパイル使用メモリ 258,112 KB
最終ジャッジ日時 2025-02-20 19:40:33
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 6 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;

int N, Q, A[101010], pos[101010];
map<int, int> mp;

int main() {
  cin >> N >> Q;
  for (int i = 1; i <= N; i++) cin >> A[i];
  for (int i = 1; i <= N; i++) pos[i] = i;
  sort(pos + 1, pos + N + 1, [&](int a, int b) {
    return A[a] < A[b];
  });
  for (int i = 1; i <= N; i++) mp[pos[i]] = i;
  while (Q--) {
    int x, y; cin >> x >> y;
    if (A[x] <= A[y]) cout << 0 << endl;
    else cout << mp[x] - mp[y] - 1 << endl;
  }
  return 0;
}
0