結果

問題 No.2710 How many more?
ユーザー namahamu0909
提出日時 2024-11-01 20:48:40
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 852 bytes
コンパイル時間 7,283 ms
コンパイル使用メモリ 337,644 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-01 20:48:52
合計ジャッジ時間 10,574 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 mint = modint998244353;
const ll INF=9e18;

int main() {
    ll N,Q;
    cin>>N>>Q;
    vector<ll> A (N);
    vector<pair<ll,ll>> hai (N);
    for (ll a = 0; a < N; a++){
        cin>>A[a];
        hai[a]={A[a],a+1};
    }
    sort(hai.begin(),hai.end());
    vector<ll> doko (N+1);
    ll count=1;
    for (ll a = 0; a < N; a++){
        ll hito=hai[a].second;
        doko[hito]=count;
        count++;
        if(a!=0){
            if(A[hai[a-1].second]==A[hito]){
                doko[hito]=doko[hai[a-1].second];
            }
        }

    }
    for (ll a = 0; a < Q; a++){
        ll x,y;
        cin>>x>>y;
        ll x_juni=doko[x];
        ll y_juni=doko[y];
        cout<<max(0LL,x_juni-y_juni-1)<<endl;

    }
    
}
0