QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745478 | #9738. Make It Divisible | hanmx | Compile Error | / | / | C++17 | 2.5kb | 2024-11-14 10:14:31 | 2024-11-14 10:14:32 |
Judging History
你现在查看的是最新测评结果
- [2024-11-27 18:44:44]
- hack成功,自动添加数据
- (/hack/1263)
- [2024-11-14 10:14:32]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2024-11-14 10:14:31]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using i64=long long;
using u64=unsigned long long;
template<class T>
T func(T x,T y){
return gcd(x,y);
}
template <class T>
struct SparseTable {
int n;
vector<vector<T>> a;
SparseTable(const vector<T> &init) : n(init.size()){
int lg = __lg(n);
a.assign(lg + 1, vector<T>(n));
a[0] = init;
for (int i = 1; i <= lg; i++) {
for (int j = 0; j <= n - (1 << i); j++) {
a[i][j] = func(a[i - 1][j], a[i - 1][(1 << (i - 1)) + j]);
}
}
}
T get(int l, int r) { // [l, r)
l--;
int lg = __lg(r - l);
return func(a[lg][l], a[lg][r - (1 << lg)]);
}
};
void solve(){
ll n,k;
cin>>n>>k;
vector<int> a(n+1);
vector<int> b(n);
int mn=1e9;
for(int i=1;i<=n;i++){
cin>>a[i];
mn=min(a[i],mn);
}
if(n==1){
cout<<k<<" "<<k*(k+1)/2<<'\n';
return;
}
for(int i=2;i<=n;i++){
b[i-2]=a[i]-a[i-1];
}
SparseTable<int> st(b);
vector<int> sta;
vector<int> l(n+1,1);
vector<int> r(n+1,n);
for(int i=1;i<=n;i++){
while(!sta.empty()&&a[sta.back()]>a[i]) sta.pop_back();
if(sta.size()){
if(sta.back()==1){
l[i]=sta.back()+1;
}
else l[i]=i;
sta.push_back(i);
}
sta.clear();
for(int i=n;i>=1;i--){
while(!sta.empty()&&a[sta.back()]>a[i]) sta.pop_back();
if(sta.size()) {
r[i]=sta.back()-1;
}
else r[i]=i;
sta.push_back(i);
}
vector<pair<int,int>> p;
for(int i=1;i<=n;i++){
if(l[i]==r[i]) p.push_back({a[i],a[i]});
else p.push_back({a[i],st.get(l[i],r[i]-1)});
}
int mx=st.get(1,n-1);
set<int> s;
for(int i=1;i<=sqrt(mx);i++){
if(mx%i==0){
int x=mx/i;
int y=i;
if(x-mn<=k&&x!=mn) s.insert(x-mn);
if(y-mn<=k&&y!=mn) s.insert(y-mn);
}
}
for(auto [x,y]:p){
for(auto z:s){
if(x==y) continue;
if(y%(x+z)==0) continue;
else s.erase(z);
}
}
cout<<s.size()<<" ";
ll ans=0;
for(auto x:s){
ans+=x;
}
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--) solve();
return 0;
}
Details
answer.code: In function ‘void solve()’: answer.code:100:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 100 | int main(){ | ^~ answer.code:100:9: note: remove parentheses to default-initialize a variable 100 | int main(){ | ^~ | -- answer.code:100:9: note: or replace parentheses with braces to value-initialize a variable answer.code:100:11: error: a function-definition is not allowed here before ‘{’ token 100 | int main(){ | ^ answer.code:107:2: error: expected ‘}’ at end of input 107 | } | ^ answer.code:31:13: note: to match this ‘{’ 31 | void solve(){ | ^