QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#864830 | #9738. Make It Divisible | linxuanrui | WA | 1ms | 3840kb | C++14 | 1.8kb | 2025-01-21 09:43:35 | 2025-01-21 09:43:36 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 5e4 + 5;
int qwq,n,k,a[N],st[N][20],lg[N],x,y,cnt,ans;
int get(int x,int y){return (a[x] < a[y] ? x : y);}
int query(int l,int r){
int k = lg[r - l + 1];
return get(st[l][k],st[r - (1 << k) + 1][k]);
}
void dfs(int l,int r){
if(x && y)return;
int pos = query(l,r);
if(pos != l){
int lpos = query(l,pos - 1);
if(a[pos] != a[lpos]){
x = pos,y = lpos;
return;
}else dfs(l,pos - 1);
}
if(pos != r){
int rpos = query(pos + 1,r);
if(a[pos] != a[rpos]){
x = pos,y = rpos;
return;
}else dfs(pos + 1,r);
}
}
bool check(int x,int l,int r){
int pos = query(l,r);
bool flag = true;
if(pos != l){
int lpos = query(l,pos - 1);
flag &= ((a[lpos] + x) % (a[pos] + x) == 0);
flag &= check(x,l,pos - 1);
}
if(pos != r){
int rpos = query(pos + 1,r);
flag &= ((a[rpos] + x) % (a[pos] + x) == 0);
flag &= check(x,pos + 1,r);
}
return flag;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> qwq;
while(qwq--){
cin >> n >> k;
lg[0] = -1;
for(int i = 1;i <= n;i++)cin >> a[i],lg[i] = lg[i >> 1] + 1,st[i][0] = i;
if(*max_element(a + 1,a + n + 1) == *min_element(a + 1,a + n + 1)){
cout << k << " " << k * (k + 1) / 2 << endl;
continue;
}
for(int j = 1;j <= lg[n];j++){
for(int i = 1;i + (1 << j) - 1 <= n;i++)st[i][j] = get(st[i][j - 1],st[i + (1 << j - 1)][j - 1]);
}
x = y = 0;
dfs(1,n);
assert(x && y);
x = a[x],y = a[y];
cnt = ans = 0;
for(int i = 1;i * i <= y - x;i++){
if((y - x) % i == 0){
int t = i - x;
if(t > 0 && check(t,1,n))ans += t,cnt++;
t = (y - x) / i - x;
if(t > 0 && check(t,1,n))ans += t,cnt++;
}
}
cout << cnt << " " << ans << endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
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: 1ms
memory: 3840kb
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: 0ms
memory: 3584kb
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: '3 5'