結果

問題 No.2710 How many more?
ユーザー shinchanshinchan
提出日時 2024-03-31 13:59:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 906 bytes
コンパイル時間 2,857 ms
コンパイル使用メモリ 211,252 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-03-31 13:59:32
合計ジャッジ時間 6,281 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 193 ms
8,064 KB
testcase_03 AC 129 ms
8,320 KB
testcase_04 AC 140 ms
10,624 KB
testcase_05 AC 78 ms
7,040 KB
testcase_06 AC 117 ms
9,600 KB
testcase_07 AC 77 ms
6,548 KB
testcase_08 AC 61 ms
6,548 KB
testcase_09 AC 181 ms
9,344 KB
testcase_10 AC 97 ms
6,548 KB
testcase_11 AC 143 ms
6,548 KB
testcase_12 AC 244 ms
10,496 KB
testcase_13 AC 274 ms
11,136 KB
testcase_14 AC 269 ms
11,136 KB
testcase_15 AC 258 ms
11,136 KB
testcase_16 AC 262 ms
11,136 KB
testcase_17 AC 270 ms
11,136 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto&& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    map<ll, ll> mp;
    rep(i, n) {
        cin >> a[i];
        mp[a[i]] ++;
    }
    int id = 1;
    for(auto [x, y] : mp) {
        mp[x] = id ++;
    }

    rep(i, n) a[i] = mp[a[i]];
    vector<ll> sum(id + 1, 0);
    foa(e, a) sum[e] ++;
    for(int i = 0; i < id; i ++) sum[i + 1] += sum[i];
    rep(i, q) {
        int x, y;
        cin >> x >> y;
        x --; y --;
        cout << max(0LL, sum[a[x] - 1] - sum[a[y]]) << endl;
    }
    return 0;
}
0