QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743039 | #9738. Make It Divisible | H_ZzZ# | WA | 1ms | 5828kb | C++23 | 2.1kb | 2024-11-13 18:02:05 | 2024-11-13 18:02:06 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-14 09:10:13]
- hack成功,自动添加数据
- (/hack/1178)
- [2024-11-13 18:02:05]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
int __ = 1,n;
const int N = 1e5 + 5;
int b[N];
int mn,k;
bool check(int x)
{
return x > mn && x - mn <= k;
}
struct gc
{
int l,r,id;
};
struct node
{
int id;
}seg[N << 2];
using pii = pair<int,int>;
#define mid (l + r >> 1)
#define lson rt << 1,l,mid
#define rson rt << 1|1,mid + 1,r
void pushup(int x)
{
if(b[seg[x << 1].id] > b[seg[x << 1|1].id]) seg[x].id = seg[x << 1|1].id;
else seg[x].id = seg[x << 1].id;
}
void build(int rt,int l,int r)
{
if(l == r)
{
seg[rt].id = l;
return;
}
build(lson),build(rson);
pushup(rt);
}
int query(int rt,int l,int r,int L,int R)
{
if(l >= L && r <= R) return seg[rt].id;
int res = 0;
if(mid >= L) res = query(lson,L,R);
if(mid < R)
{
int t = query(rson,L,R);
if(b[t] < b[res]) res = t;
}
return res;
}
void solve(){
b[0] = 2e9;
int n;
cin >> n >> k;
mn = 1e9;
for(int i = 1; i <= n; i++) cin >> b[i], mn = min(mn,b[i]);
build(1,1,n);
int g = 0;
queue<gc> q;
q.push({1,n,query(1,1,n,1,n)});
while(q.size())
{
auto [l,r,id] = q.front();
q.pop();
if(l <= id - 1)
{
int mnl = query(1,1,n,l,id - 1);
g = gcd(g,b[mnl] - b[id]);
q.push({l,id - 1,mnl});
}
if(id + 1 <= r)
{
int mnr = query(1,1,n,id + 1,r);
g = gcd(g,b[mnr] - b[id]);
q.push({id + 1,r,mnr});
}
}
if(g == 0)
{
cout << k << ' ' << (1 + k) * k / 2 << endl;
return;
}
int cnt = 0, sum = 0;
for(int i = 1; i <= g / i; i++)
if(g % i == 0)
{
if(check(i)) cnt ++, sum += i - mn;
if(i * i != g && check(g/i)) cnt ++, sum += g / i - mn;
}
cout << cnt << ' ' << sum << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
cin >> __;
while (__--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5828kb
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: -100
Wrong Answer
time: 1ms
memory: 5560kb
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 1 1 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '0 0', found: '1 1'