結果

問題 No.2710 How many more?
ユーザー akinyanakinyan
提出日時 2024-03-31 14:20:44
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 291 ms / 2,000 ms
コード長 1,518 bytes
コンパイル時間 3,389 ms
コンパイル使用メモリ 259,452 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-03-31 14:20:53
合計ジャッジ時間 7,609 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 229 ms
6,676 KB
testcase_03 AC 134 ms
6,676 KB
testcase_04 AC 104 ms
8,320 KB
testcase_05 AC 77 ms
6,676 KB
testcase_06 AC 90 ms
7,936 KB
testcase_07 AC 96 ms
6,676 KB
testcase_08 AC 72 ms
6,676 KB
testcase_09 AC 191 ms
7,808 KB
testcase_10 AC 110 ms
6,676 KB
testcase_11 AC 194 ms
6,676 KB
testcase_12 AC 256 ms
8,192 KB
testcase_13 AC 291 ms
8,576 KB
testcase_14 AC 269 ms
8,576 KB
testcase_15 AC 264 ms
8,576 KB
testcase_16 AC 264 ms
8,576 KB
testcase_17 AC 268 ms
8,576 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef akinyan
#define akinyan
#include <bits/stdc++.h>
using namespace std;
using ch = char;
using ll = long long;
using ld = long double;
using db = double;
using st = string;
using vdb = vector<db>;
using vvdb = vector<vdb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vs = vector<st>;
using vvs = vector<vs>;
using vc = vector<ch>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
const ll mod = 998244353;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000LL;
using pall = pair<ll,ll>;
using vp = vector<pall>;
#endif

#include <atcoder/segtree>

ll op(ll a, ll b){
    return a + b;
}

ll e(){
    return 0;
}

int main(){
    ll N,Q;
    cin>>N>>Q;
    vp A(N);
    set<ll> X;
    for(int i=0; i<N; i++){
        cin >> A[i].first;
        A[i].second = i;
    }
    vl P(N);
    sort(A.begin(),A.end());
    P[A[0].second] = 0;
    for(int i=1; i<N; i++){
        if(A[i-1].first == A[i].first){
            P[A[i].second] = P[A[i-1].second];
        }
        else{
            P[A[i].second] = P[A[i-1].second] + 1;
        }
    }
    atcoder::segtree<ll,op,e> Seg(N);
    for(int i=0; i<N; i++){
        Seg.set(P[i],Seg.get(P[i]) + 1);
    }
    while(Q--){
        ll x,y;
        cin>>x>>y;
        x--,y--;
        if(P[x] <= P[y]){
            cout << 0 << endl;
        }
        else{
            cout << Seg.prod(P[y] + 1,P[x]) << endl;
        }
    }
}
0