QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#742104 | #9738. Make It Divisible | Legend_dy# | TL | 0ms | 3732kb | C++20 | 2.4kb | 2024-11-13 15:52:02 | 2024-11-13 15:52:03 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-14 09:10:13]
- hack成功,自动添加数据
- (/hack/1178)
- [2024-11-13 15:52:02]
- 提交
answer
#include <bits/stdc++.h>
#define endl '\n'
// #define int long long
using namespace std;
const int INF = 1e9 + 7;
struct Node {
int l, r, lstP, nowP;
};
void solve() {
int n, k, mn = INF, mx = -1;
cin >> n >> k;
vector<int> b(n + 1);
priority_queue<pair<int, int>> pq;
for(int i = 1; i <= n; i++) {
cin >> b[i];
pq.push({-b[i], -i});
mn = min(mn, b[i]);
mx = max(mx, b[i]);
}
long long ans0 = 0, ans1 = 0;
if(mn == mx) {
ans0 = k;
ans1 = 1ll * (1 + k) * k / 2;
cout << ans0 << ' ' << ans1 << endl;
return;
}
vector<Node> v;
v.push_back({1, n, 0, 0});
int hd = 0;
while(hd < v.size()) {
// cout << "hd = " << hd << " L = " << v[hd].l << " R = " << v[hd].r << " nowP = " << v[hd].nowP << endl;
int mn = INF;
vector<int> nxt;//{pos}
if(v[hd].l == v[hd].r) {
v[hd].nowP = v[hd].l;
hd++;
continue;
}
nxt.push_back(v[hd].l - 1);
while(1) {
if(pq.empty()) break;
int vl = -pq.top().first;
int p = -pq.top().second;
if(vl > mn || p > v[hd].r)
break;
// cout << "get vl = " << vl << " p = " << p << endl;
pq.pop();
nxt.push_back(p);
mn = vl;
v[hd].nowP = p;
}
nxt.push_back(v[hd].r + 1);
for(int i = 1; i < nxt.size(); i++) {
int L = nxt[i - 1] + 1, R = nxt[i] - 1;
if(L > R) continue;
v.push_back({L, R, v[hd].nowP, 0});
}
hd++;
}
auto cal = [&](int x) {
x -= mn;
if(x < 1 || x > k)
return;
for(int i = 1; i < v.size(); i++) {
if(v[i].lstP == 0) continue;
if((b[v[i].nowP] + x) % (b[v[i].lstP] + x) != 0)
return;
}
ans0++;
ans1 += x;
};
int T = mx - mn, sT = sqrt(T);
for(int i = 1; i <= sT; i++)
if(T % i == 0) {
cal(i);
if(i * i != T)
cal(T / i);
}
cout << ans0 << ' ' << ans1 << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
while(T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3732kb
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: 0ms
memory: 3608kb
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
Time Limit Exceeded
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...