xxxxxxxxxx
using namespace std;
vector<pair<int, int>> bunkai(int x){
vector<pair<int, int>> res;
for(long long a = 2; a * a <= x; a++){
if(x % a != 0){
continue;
}
int e = 0;
while(x % a == 0){
e++;
x /= a;
}
res.push_back({a, e});
}
if(x != 1){
res.push_back({x, 1});
}
return res;
}
int main(){
long long ans = 0;
int n, x, y;
cin >> n >> x >> y;
vector<int> A(n);
for(int i = 0; i < n; i++){
cin >> A[i];
}
vector<pair<int, int>> X = bunkai(x), Y = bunkai(y);
vector<vector<int>> P(X.size(), vector<int>(n + 1, 0)), Q(Y.size(), vector<int>(n + 1, 0));
for(int i = 0; i < n; i++){
for(int j = 0; j < X.size(); j++){
int a = A[i];
int e = 0;
while(a % X[j].first == 0){
e++;
a /= X[j].first;
}
P[j][i + 1] = e + P[j][i];
}
for(int j = 0; j < Y.size(); j++){
int a = A[i];
int e = 0;
while(a % Y[j].first == 0){
e++;
a /= Y[j].first;
}
Q[j][i + 1] = e + Q[j][i];
}
}
for(int i = 0; i < n; i++){
int okx = n, ngx = i - 1;
while(okx - ngx > 1){
int mid = (okx + ngx) / 2;
bool flag = true;
for(int j = 0; j < X.size(); j++){
if(P[j][mid + 1] - P[j][i] < X[j].second){
flag = false;
break;
}
}
if(flag) okx = mid;
else ngx = mid;
}
int oky = n, ngy = i - 1;
while(oky - ngy > 1){
int mid = (oky + ngy) / 2;
bool flag = true;
for(int j = 0; j < Y.size(); j++){
if(Q[j][mid + 1] - Q[j][i] < Y[j].second){
flag = false;
break;
}
}
if(flag) oky = mid;
else ngy = mid;
}
ans += abs(okx - oky);
}
cout << ans << endl;
}
提出日時 | |
ユーザー | ![]() |
言語 | C++ (GCC 9.3.0) |
結果 | AC |
実行時間 | 167 ms |
メモリ | 54584 kb |
テストケース名 | 結果 | 実行時間 | メモリ |
---|---|---|---|
hand01.txt | AC | 122 ms | 54584 kb |
hand02.txt | AC | 167 ms | 54584 kb |
max01.txt | AC | 116 ms | 54584 kb |
max02.txt | AC | 110 ms | 54584 kb |
max03.txt | AC | 101 ms | 54584 kb |
random01.txt | AC | 82 ms | 54584 kb |
random02.txt | AC | 80 ms | 54584 kb |
random03.txt | AC | 31 ms | 54584 kb |
random04.txt | AC | 77 ms | 54584 kb |
random05.txt | AC | 118 ms | 54584 kb |
random06.txt | AC | 28 ms | 54584 kb |
random07.txt | AC | 26 ms | 54584 kb |
random08.txt | AC | 85 ms | 54584 kb |
random09.txt | AC | 83 ms | 54584 kb |
random10.txt | AC | 91 ms | 54584 kb |
random11.txt | AC | 33 ms | 54584 kb |
random12.txt | AC | 21 ms | 54584 kb |
random13.txt | AC | 45 ms | 54584 kb |
random14.txt | AC | 47 ms | 54584 kb |
random15.txt | AC | 34 ms | 54584 kb |
random16.txt | AC | 103 ms | 54584 kb |
random17.txt | AC | 6 ms | 54584 kb |
random18.txt | AC | 64 ms | 54584 kb |
random19.txt | AC | 92 ms | 54584 kb |
random20.txt | AC | 7 ms | 54584 kb |
sample01.txt | AC | 3 ms | 54584 kb |
sample02.txt | AC | 3 ms | 54584 kb |