QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#743343 | #9738. Make It Divisible | H_ZzZ# | WA | 1ms | 5536kb | C++23 | 3.1kb | 2024-11-13 18:58:30 | 2024-11-13 18:58:34 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-14 09:10:13]
- hack成功,自动添加数据
- (/hack/1178)
- [2024-11-13 18:58:30]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
int __ = 1,n;
const int N = 1e5 + 5;
int b[N];
int 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;
}
vector<pii> lim;
void solve(){
b[0] = 2e9;
lim.clear();
int n;
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> b[i];
int c = b[1];
for(int i = 2; i <= n; i++) if(c != b[i]) c = -1;
if(c != -1)
{
cout << k << ' ' << (k + 1) * k / 2 << endl;
return;
}
build(1,1,n);
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);
if(b[mnl] != b[id])lim.push_back(pii(b[mnl] - b[id],b[id]));
q.push({l,id - 1,mnl});
}
if(id + 1 <= r)
{
int mnr = query(1,1,n,id + 1,r);
if(b[mnr] != b[id])lim.push_back(pii(b[mnr] - b[id],b[id]));
q.push({id + 1,r,mnr});
}
}
int cnt = 0, sum = 0;
queue<int> que;
int x=lim[0].first,y=lim[0].second;
for(int i = 1; i <= x / i; i++)
{
if(x % i == 0)
{
if(i > y && i - y <= k) que.push(i - y);
if(i * i != x)
{
if(x / i > y && x / i - y <= k) que.push(x/i - y);
}
}
}
for(int i=1;i<lim.size();i++)
{
int x=lim[i].first,y=lim[i].second;
int siz=q.size();
while(siz--)
{
int t = que.front();
que.pop();
if(x % (t + y) == 0) que.push(t);
}
}
while(que.size()) cnt ++, sum += que.front(),que.pop();
/*
unordered_map<int,int> mp;
for(auto [x,y] : lim)
{
for(int i = 1; i <= x / i; i++)
{
if(x % i == 0)
{
if(i > y) mp[i - y]++;
if(i * i != x)
{
if(x / i > y) mp[x/i - y]++;
}
}
}
}
for(auto [x,y] : mp) if(y == lim.size() && x <= k) cnt ++, sum += x;
*/
cout << cnt << ' ' << sum << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
cin >> __;
while (__--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
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: 5536kb
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 2 4 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '0 0', found: '2 4'