結果

問題 No.2710 How many more?
ユーザー くけくけ
提出日時 2024-03-31 15:26:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 1,170 bytes
コンパイル時間 4,628 ms
コンパイル使用メモリ 267,928 KB
実行使用メモリ 7,140 KB
最終ジャッジ日時 2024-03-31 15:26:37
合計ジャッジ時間 8,353 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 234 ms
6,676 KB
testcase_03 AC 138 ms
6,676 KB
testcase_04 AC 106 ms
7,032 KB
testcase_05 AC 80 ms
6,676 KB
testcase_06 AC 90 ms
6,832 KB
testcase_07 AC 100 ms
6,676 KB
testcase_08 AC 75 ms
6,676 KB
testcase_09 AC 200 ms
6,768 KB
testcase_10 AC 114 ms
6,676 KB
testcase_11 AC 185 ms
6,676 KB
testcase_12 AC 262 ms
6,996 KB
testcase_13 AC 281 ms
7,140 KB
testcase_14 AC 283 ms
7,140 KB
testcase_15 AC 285 ms
7,140 KB
testcase_16 AC 281 ms
7,140 KB
testcase_17 AC 282 ms
7,140 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
   ll n , q ;
   cin >> n >> q ;
   vector<pair<ll,ll>> A ;
   vector<pair<ll,ll>> B(n) ;
   rep(i,n){
      cin >> B[i].first ;
      B[i].second = i ;
      A.push_back(B[i]) ;
   }
   sort(A.begin(),A.end()) ;
   rep(i,q){
      ll x , y ;
      cin >> x >> y ;
      x-- , y-- ;
      ll l = 0 , r = n ;
      while ( r - l > 1 )
      {
         ll m = ( r + l ) / 2 ;
         if( B[x].first >= A[m].first ) l = m ;
         else r = m ;
      }
      ll a = l ;
      l = 0 , r = n ;
      while ( r - l > 1 )
      {
         ll m = ( r + l ) / 2 ;
         if( B[y].first >= A[m].first ) l = m ;
         else r = m ;
      }
      ll b = l ;
      if( a+1 < n && A[a+1].first == B[x].first ) a++ ;
      if( b+1 < n && A[b+1].first == B[x].first ) b++ ;
      if( a-1 >= 0 && A[a-1].first == B[x].first ) a-- ;
      if( b-1 >= 0 && A[b-1].first == B[x].first ) b-- ;
      cout << max((ll)a-b-1,0LL) << endl ;
   }
}
0