結果

問題 No.2710 How many more?
ユーザー KKT89KKT89
提出日時 2024-03-31 13:37:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 910 bytes
コンパイル時間 3,071 ms
コンパイル使用メモリ 226,836 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-03-31 13:37:07
合計ジャッジ時間 5,429 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 81 ms
7,040 KB
testcase_03 AC 60 ms
7,296 KB
testcase_04 AC 69 ms
9,216 KB
testcase_05 AC 39 ms
6,676 KB
testcase_06 AC 60 ms
8,320 KB
testcase_07 AC 21 ms
6,676 KB
testcase_08 AC 26 ms
6,676 KB
testcase_09 AC 83 ms
8,192 KB
testcase_10 AC 44 ms
6,676 KB
testcase_11 AC 66 ms
6,676 KB
testcase_12 AC 109 ms
9,088 KB
testcase_13 AC 120 ms
9,600 KB
testcase_14 AC 122 ms
9,600 KB
testcase_15 AC 119 ms
9,600 KB
testcase_16 AC 119 ms
9,600 KB
testcase_17 AC 119 ms
9,600 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,q; cin >> n >> q;
    vector<int> a(n);
    vector<pair<int,int>> v(n);
    map<int,int> mp;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        v[i] = {a[i], i};
        mp[a[i]] += 1;
    }
    sort(v.begin(), v.end());
    vector<int> u(n);
    for (int i = 0; i < n; ) {
        int j = i;
        while (v[i].first == v[j].first) {
            u[v[i].second] = j;
            i += 1;
        }
    }
    while (q--) {
        int x, y; cin >> x >> y;
        x -= 1, y -= 1;
        int res = u[x] - u[y] - mp[a[y]];
        cout << max(0,res) << "\n";
    }
}
0