結果

問題 No.2709 1975 Powers
ユーザー BBhorse
提出日時 2024-03-31 14:50:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 179,668 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-30 20:00:57
合計ジャッジ時間 4,612 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll=long long;
#define rep(i,s,n) for (ll i = (s); i < (n); i++)
using namespace std;
using Graph = vector<vector<ll>>;
ll MOD=998244353;
const ll INF=1e18;

ll mod;

ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1) res=(res*a)%mod;
    a=(a*a)%mod;
    n>>=1;
  }
  return res;
}

int main(){
  ll N,P,Q;
  cin>>N>>P>>Q;
  mod=P;
  vector<ll> A(N);
  rep(i,0,N){
    cin>>A[i];
  }
  vector<vector<ll>> L(3,vector<ll> (N));
  vector<pair<ll,ll>> X(N);
  rep(i,0,N){
    L[0][i]=modpow(10,A[i]);
  }
  rep(i,0,N){
    L[1][i]=modpow(9,A[i]);
  }
  rep(i,0,N){
    L[2][i]=modpow(7,A[i]);
  }
  rep(i,0,N){
    X[i]={modpow(5,A[i]),i};
  }
  sort(X.begin(), X.end());

  ll ans=0;

  rep(i,0,N){
    rep(j,0,N){
      rep(k,0,N){
        if(!(A[i]<A[j]&&A[j]<A[k])) continue;
        ll s=L[0][i]+L[1][j]+L[2][k];
        s%=mod;
        ll a=(Q+mod-s)%mod;
        ll l=distance(X.begin(), lower_bound(X.begin(), X.end(), make_pair(a,(ll)0)));
        ll r=distance(X.begin(), lower_bound(X.begin(), X.end(), make_pair(a+1,(ll)0)));
        //cout<<a<<endl;
        if(X[l].first==a){
          rep(x,l,r){
            if(A[k]<A[X[x].second]){
              ans++;
              //cout<<i<<j<<k<<X[x].first<<X[x].second<<endl;
            }
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  
}
0