結果
問題 | No.2710 How many more? |
ユーザー |
![]() |
提出日時 | 2024-11-01 21:01:23 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,041 bytes |
コンパイル時間 | 6,603 ms |
コンパイル使用メモリ | 338,648 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-01 21:01:34 |
合計ジャッジ時間 | 10,252 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 6 WA * 11 |
ソースコード
#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>> narabikae (N); for (ll a = 0; a < N; a++){ cin>>A[a]; narabikae[a]={A[a],a}; } //順位を求める ll now=0; vector<ll> num (N); sort(narabikae.begin(),narabikae.end()); for (ll a = 0; a < N; a++){ ll hito=narabikae[a].second; num[hito]=now; now++; if(a!=0){ ll maeno_hito=narabikae[a-1].second; // 同じ場所にいるなら同じ順位 if(narabikae[a-1].first==narabikae[a].first){ num[hito]=num[maeno_hito]; } } } for (ll a = 0; a < Q; a++){ ll x,y; cin>>x>>y; x--;y--; ll x_num=num[x]; ll y_num=num[y]; ll sa = x_num-y_num; cout<<max(0LL,sa-1)<<endl; } }