QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#741197 | #9738. Make It Divisible | ir101 | WA | 6ms | 14996kb | C++20 | 3.4kb | 2024-11-13 13:46:26 | 2024-11-13 13:46:26 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-14 09:10:13]
- hack成功,自动添加数据
- (/hack/1178)
- [2024-11-13 13:46:26]
- 提交
answer
#include <bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define PI4 pair<int,array<int,3>>
#define endl '\n'
//#define int long long
#define i64 long long
#define lc p<<1
#define rc p<<1|1
using namespace std;
const int N = 1e6 + 10;
int st[N][20],b[N];//区间长度最大不超过2^20
int Log[N];
int query(int l,int r)
{
if(l>r)return 0;
int k=Log[r-l+1];
return gcd(st[l][k],st[r-(1<<k)+1][k]);
}
int prime[1000006],cnt;
bool vis[1000006];
void get_prime(int n){
for(int i=2;i<=n;i++){
if(!vis[i]){
prime[cnt++]=i;
}
for(int j=0;i*prime[j]<=n;j++){
vis[i*prime[j]]=1;
if(i%prime[j]==0)
break;
}
}
}
vector<PII>mp;
vector<int>inv;
void dfs(int x, int s) {
if (x == mp.size()) {
inv.push_back(s);
return;
}
for (int i = 0; i <= mp[x].second; i++) {
dfs(x + 1, s);
s *= mp[x].first;
}
}
void solve() {
int n,k;
cin >> n >> k;
vector<int>L(n+3),R(n+3),a(n+3);
mp.clear();
inv.clear();
vector<int> qx;
int f = 1;
int mi = 1;
for (int i = 1; i <= n; i++) {
L[i] = 0;
R[i] = n + 1;
cin >> a[i];
if (i > 1) {
if (a[i] == a[i - 1]) {
continue;
} else {
f = 0;
mi = i;
}
st[i - 1][0] = abs(a[i] - a[i - 1]);
}
}
vector<PII > q;
q.push_back({a[n], n});
for (int i = n - 1; i >= 1; i--) {
while (q.size() && a[i] < q.back().first) {
L[q.back().second] = i;
q.pop_back();
}
q.push_back({a[i], i});
}
q.clear();
q.push_back({a[1], 1});
for (int i = 2; i <= n; i++) {
while (q.size() && a[i] < q.back().first) {
R[q.back().second] = i;
q.pop_back();
}
q.push_back({a[i], i});
}
for (int j = 1; j <= Log[n]; j++) {
for (int i = 1; i < n; i++) {
st[i][j] = gcd(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
}
}
if (f) {
cout << k << ' ' << k * (k + 1) / 2 << endl;
return;
}
int t = abs(a[mi] - a[mi - 1]);
for (int i = 0; i <cnt and prime[i]*prime[i]<=t ; ++i) {
int s = 0;
while (t % prime[i] == 0) {
t /= prime[i];
s++;
}
if (s) {
mp.push_back({prime[i], s});
}
}
if (t > 1) {
mp.push_back({t, 1});
}
dfs(0, 1);
int m = min(a[mi], a[mi - 1]);
for (int i = 0; i < inv.size(); i++) {
if (inv[i] > m && inv[i] - m <= k) {
qx.push_back(inv[i] - m);
}
}
int cc = 0;
int sum = 0;
for (auto x: qx) {
int f = 1;
for (int i = 1; i <= n; i++) {
if (query(L[i] + 1, R[i] - 2) % (a[i] + x) == 0) {
} else {
f = 0;
break;
}
}
if (f) {
cc++;
sum += x;
}
}
cout << cc << ' ' << sum << endl;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
ll t = 1;
cin >> t;
get_prime(1000000);
Log[1] = 0;
for (int i = 2; i < N; i++)
Log[i] = Log[i / 2] + 1;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 14720kb
input:
3 5 10 7 79 1 7 1 2 1000000000 1 2 1 100 1000000000
output:
3 8 0 0 100 5050
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 3ms
memory: 14996kb
input:
4 201 1000000000 1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...
output:
0 0 0 0 0 0 0 0
result:
ok 4 lines
Test #3:
score: -100
Wrong Answer
time: 6ms
memory: 13040kb
input:
500 4 1000000000 8 14 24 18 4 1000000000 17 10 18 14 4 1000000000 6 17 19 19 4 1000000000 15 14 15 25 4 1000000000 16 16 5 25 4 1000000000 4 30 20 5 4 1000000000 11 4 23 9 4 1000000000 14 25 13 2 4 1000000000 18 18 1 15 4 1000000000 22 22 22 28 4 1000000000 15 17 17 10 4 1000000000 22 14 13 25 4 100...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 78th lines differ - expected: '2 4', found: '0 0'