QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#741302 | #9738. Make It Divisible | 5720226849 | WA | 36ms | 8020kb | C++14 | 2.9kb | 2024-11-13 14:03:00 | 2024-11-13 14:03:01 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-14 09:10:13]
- hack成功,自动添加数据
- (/hack/1178)
- [2024-11-13 14:03:00]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define x first
#define y second
#define ls u << 1
#define rs u << 1 | 1
#define PII pair<int,int>
const int N = 5e4 + 10, inf = 1e18, mod1 = 998244353, mod2 = 1e9 + 7, M = 18;
int lg[N];
int gcd(int a, int b) {
return (b == 0 ? a : gcd(b, a % b));
}
int lowbit(int x) {
return x & -x;
}
PII pos[N];
int tr[N];
void add(int x) {
for(; x < N; x += lowbit(x)) tr[x] ++;
}
int query(int x) {
int res = 0;
for(; x; x -= lowbit(x)) res += tr[x];
return res;
}
int f[N][M];
int get(int l, int r) {
int k = lg[r - l + 1];
return gcd(f[l][k], f[r - (1 << k) + 1][k]);
}
void solve() {
int n;
long long k; cin >> n >> k;
vector<int>a(n + 1); int mi = inf;
vector<PII>vec;
for(int i = 1; i <= n; i ++) cin >> a[i], mi = min(mi, a[i]), vec.push_back({a[i], i}), tr[i] = 0;
sort(vec.begin(), vec.end());
for(int i = 0; i < n; i ++) {
vector<int>vv; vv.push_back(vec[i].y);
while(i < n - 1 && vec[i + 1].x == vec[i].x) vv.push_back(vec[i + 1].y), i ++;
for(int j = 0; j < vv.size(); j ++) add(vv[j]);
for(int j = 0; j < vv.size(); j ++) {
int l = 0, r = vv[j] - 1;
while(l <= r) {
int mid = l + r >> 1;
if(query(mid) == query(vv[j]) - 1) r = mid - 1;
else l = mid + 1;
}
pos[vv[j]].x = l + 1;
l = vv[j] + 1, r = n;
while(l <= r) {
int mid = l + r >> 1;
if(query(mid) == query(vv[j])) l = mid + 1;
else r = mid - 1;
}
pos[vv[j]].y = r;
}
}
int d = 0;
for(int i = 1; i < n; i ++) d = gcd(d, abs(a[i] - a[i + 1]));
if(d == 0) {
cout << k << ' ' << k * (k + 1) / 2 << '\n';
return;
}
vector<int>v;
for(int i = 1; i * i <= d; i ++)
if(d % i == 0) {
v.push_back(i);
if(i != d / i) v.push_back(d / i);
}
int cnt = 0;
long long res = 0;
for(auto x : v) {
if(x <= mi || x - mi > k) continue;
int y = x - mi;
for(int i = 1; i <= n; i ++) f[i][0] = a[i] + y;
bool ok = true;
for(int i = 1; i <= n; i ++) {
int d = a[i] + y, mi = a[i] + y;
for(int j = 1; j < 50 && i + j <= n; j ++) {
d = gcd(d, a[i + j] + y), mi = min(mi, a[i + j] + y);
if(d != mi) {
ok = false;
break;
}
}
}
if(ok) cnt ++, res += y;
}
cout << cnt << ' ' << res << '\n';
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t = 1; cin >> t;
for(int i = 2; i < N; i ++) lg[i] = lg[i / 2] + 1;
while(t --)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5792kb
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: 4016kb
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: 0
Accepted
time: 1ms
memory: 3780kb
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:
ok 500 lines
Test #4:
score: -100
Wrong Answer
time: 36ms
memory: 8020kb
input:
1 50000 1000000000 230 286458 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 41263680 ...
output:
1 96
result:
wrong answer 1st lines differ - expected: '0 0', found: '1 96'