結果

問題 No.2709 1975 Powers
ユーザー umezoumezo
提出日時 2024-03-31 14:15:43
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,751 bytes
コンパイル時間 3,175 ms
コンパイル使用メモリ 267,580 KB
実行使用メモリ 81,396 KB
最終ジャッジ日時 2024-03-31 14:15:58
合計ジャッジ時間 13,206 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
81,388 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 217 ms
81,396 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>; //B(n,V<int>(n))

template<typename T>
struct BIT{
private:
  vector<T> A;
  const int n;
  
public:
  BIT(int _n) : A(_n+1,0), n(_n){}
  
  T sum(int i){
    i++;
    T s=0;
    while(i>0){
      s+=A[i];
      i-=i&-i;
    }
    return s;
  }
  
  T sum(int i,int j){
    return sum(j)-sum(i-1);
  }
  
  void add(int i,T x){
    i++;
    while(i<=n){
      A[i]+=x;
      i+=i&-i;
    }
  }

  void update(int i,T x){
    T tmp=sum(i,i);
    if(tmp!=x) add(i,x-tmp);
  }

  int lower_bound(T w){ 
    if(w<=0) return 0;
    if(sum(n-1)<w) return n;
    int x=0,r=1;
    while(r<n) r=r<<1;
    for(int len=r;len>0;len=len>>1){
      if(x+len<n && A[x+len]<w){
        w-=A[x+len];
        x+=len;
      }
    }
    return x;
  }
};
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll n,p,q;
  cin>>n>>p>>q;
  V<ll> A(n);
  rep(i,n) cin>>A[i];
  sort(ALL(A));
  
  VV<ll> B(4,V<ll>(2002002));
  rep(i,4) B[i][0]=1;
  rep(j,2002000) B[0][j+1]=B[0][j]*10%p;
  rep(j,2002000) B[1][j+1]=B[1][j]*9%p;
  rep(j,2002000) B[2][j+1]=B[2][j]*7%p;
  rep(j,2002000) B[3][j+1]=B[3][j]*5%p;
  
  set<ll> s;
  rep(j,n) s.insert(B[3][j]);
  int now=0;
  map<ll,ll> m;
  for(auto x:s){
    m[x]=now++;
  }
  BIT<ll> bit(now);
  
  ll ans=0;
  for(int c=n-2;c>=2;c--){
    bit.add(m[B[3][A[c+1]]],1);
    for(int b=c-1;b>=1;b--){
      for(int a=b-1;a>=0;a--){
        ll tmp=(B[0][A[a]]+B[1][A[b]]+B[2][A[c]])%p;
        ans+=bit.sum(m[(q-tmp+p)%p],m[(q-tmp+p)%p]);
      }
    }
  }
  cout<<ans<<endl;
    
  return 0;
}
0