QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#744549 | #9738. Make It Divisible | Sunwking | WA | 24ms | 21032kb | C++20 | 3.0kb | 2024-11-13 22:21:57 | 2024-11-13 22:21:59 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-14 09:10:13]
- hack成功,自动添加数据
- (/hack/1178)
- [2024-11-13 22:21:57]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 5e4 + 10;
int LOG[N];
int f[N][20] , f1[N][20] , g[N][20];
int id[N][20];
int getId(int l , int r){
int k = LOG[r - l + 1];
if(f1[l][k] <= f1[r - (1 << k) + 1][k])
return id[l][k];
return id[r - (1 << k) + 1][k];
}
int getMax(int l , int r){
int k = LOG[r - l + 1];
return max(f[l][k] , f[r - (1 << k) + 1][k]);
}
int getGcd(int l , int r){
int k = LOG[r - l + 1];
return gcd(g[l][k] , g[r - (1 << k) + 1][k]);
}
vector<int> G[100 * N];
map<int , int> mp;
int t = 1;
void solved(){
int n , k;
cin >> n >> k;
int mx = 1e9;
vector<int> a(n + 1);
for(int i = 1 ; i <= n ; i ++ ){
cin >> a[i];
mx = min(mx , a[i]);
f[i][0] = f1[i][0] = a[i];
g[i][0] = abs(a[i] - a[i - 1]);
id[i][0] = i;
}
for(int j = 1 ; j < 20 ; j ++ )
for(int i = 1 ; i + (1 << j - 1) <= n ; i ++ ){
f[i][j] = max(f[i][j - 1] , f[i + (1 << j - 1)][j - 1]);
if(f1[i][j - 1] <= f1[i + (1 << j - 1)][j - 1])
f1[i][j] = f1[i][j - 1] , id[i][j] = id[i][j - 1];
else f1[i][j] = f1[i + (1 << j - 1)][j - 1] , id[i][j] = id[i + (1 << j - 1)][j - 1];
g[i][j] = gcd(g[i][j - 1] , g[i + (1 << j)][j - 1]);
}
map<int , int> sum;
int cnt = 0;
auto dfs = [&](auto self , int l , int r) ->void{
if(l >= r) return ;
if(getMax(l , r) == a[getId(l , r)])
return ;
cnt ++ ;
int k1 = getId(l , r) , d = getGcd(l + 1 , r);
// cout << l << " " << k1 << " " << r << " " << d << endl;
if(!mp.count(d)){
for(int i = 1 ; i <= d / i ; i ++ )
if(d % i == 0){
G[t].push_back(i);
if(i != d / i)
G[t].push_back(d / i);
}
mp[d] = t ++;
}
for(int x : G[mp[d]]){
if(x <= a[k1]) continue;
if(k + a[k1] < x) continue;
sum[x - a[k1]] ++;
}
self(self , l , k1 - 1);
self(self , k1 + 1 , r);
};
dfs(dfs , 1 , n);
if(!cnt){
cout << k << " " << 1ll * k * (k + 1) / 2 << "\n";
return ;
}
int ans = 0;
LL res = 0;
for(auto [x , y] : sum)
if(y == cnt){
ans ++ , res += x;
}
if(ans == 1 && res == 1){
int d = 0;
for(int i = 1 ; i <= n ; i ++ )
d = gcd(d , a[i] + 1);
if(d != a[getId(1 , n)] + 1){
cout << "0 0\n";
return ;
}
}
cout << ans << " " << res << "\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for(int i = 1 ; i < N ; i ++ )
LOG[i] = log2(i);
int T;
cin >> T;
while(T -- )
solved();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 12268kb
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: 6ms
memory: 11988kb
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: 0ms
memory: 12200kb
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: 0
Accepted
time: 24ms
memory: 21032kb
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:
0 0
result:
ok single line: '0 0'
Test #5:
score: 0
Accepted
time: 9ms
memory: 20628kb
input:
1 50000 1000000000 12087 1196491 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 55314643 553146...
output:
0 0
result:
ok single line: '0 0'
Test #6:
score: 0
Accepted
time: 15ms
memory: 20264kb
input:
1 50000 1000000000 2138984 42249920 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 358123541 3581...
output:
0 0
result:
ok single line: '0 0'
Test #7:
score: -100
Wrong Answer
time: 18ms
memory: 12384kb
input:
500 39 1000000000 75 7 7 381 41 1197 177 177 41 109 109 16 1197 177 41 381 1605 381 381 7 177 177 177 177 177 177 177 177 7 7 143 143 143 143 143 653 143 823 7 61 1000000000 327 327 327 327 405153474 327 405153474 327 810306621 810306621 810306621 810306621 810306621 810306621 810306621 810306621 81...
output:
0 0 25 631568356 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000000 500000000500000000 0 0 1000000000 500000000500000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1288 0 0 0 0 0 0 0 0 0 0 0 0 2 4 1 1 1000000000 500000000500000000 0 0 0 0 0 0 1000000000 500000000500000000 1 1 0 0 ...
result:
wrong answer 3rd lines differ - expected: '13 18925862', found: '0 0'