QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#801232 | #9738. Make It Divisible | Proaes | WA | 0ms | 3656kb | C++11 | 4.7kb | 2024-12-06 19:59:59 | 2024-12-06 20:00:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define all(x) (x).begin() ,(x).end()
template <typename T>
class SparseTable1 {
using VT = vector<T>;
using VVT = vector<VT>;
using func_type = function<T(const T &, const T &)>;
VVT ST;
static T default_func(const T &t1, const T &t2) { return __gcd(t1, t2); }
func_type op;
public:
SparseTable1(const vector<T> &v, func_type _func = default_func) {
op = _func;
int len = v.size(), l1 = ceil(log2(len)) + 1;
ST.assign(len, VT(l1, 0));
for (int i = 0; i < len; ++i) {
ST[i][0] = v[i];
}
for (int j = 1; j < l1; ++j) {
int pj = (1 << (j - 1));
for (int i = 0; i + pj < len; ++i) {
ST[i][j] = op(ST[i][j - 1], ST[i + (1 << (j - 1))][j - 1]);
}
}
}
T query(int l, int r) {
int lt = r - l + 1;
int q = floor(log2(lt));
return op(ST[l][q], ST[r - (1 << q) + 1][q]);
}
};
template <typename T>
class SparseTable2 {
using VT = vector<T>;
using VVT = vector<VT>;
using func_type = function<T(const T &, const T &)>;
VVT ST;
static T default_func(const T &t1, const T &t2) { return min(t1, t2); }
func_type op;
public:
SparseTable2(const vector<T> &v, func_type _func = default_func) {
op = _func;
int len = v.size(), l1 = ceil(log2(len)) + 1;
ST.assign(len, VT(l1, 0));
for (int i = 0; i < len; ++i) {
ST[i][0] = v[i];
}
for (int j = 1; j < l1; ++j) {
int pj = (1 << (j - 1));
for (int i = 0; i + pj < len; ++i) {
ST[i][j] = op(ST[i][j - 1], ST[i + (1 << (j - 1))][j - 1]);
}
}
}
T query(int l, int r) {
int lt = r - l + 1;
int q = floor(log2(lt));
return op(ST[l][q], ST[r - (1 << q) + 1][q]);
}
};
int FQ_check(vector<int>& b){
int g = 0;
for(int x : b) g = __gcd(g , x);
int mi = *min_element(b.begin(),b.end());
if(mi != g){
return 0;
}
int n = b.size();
SparseTable1<int> stg(b);
SparseTable2<int> stmin(b);
int ok = 1;
for(int i =0;i<n;i++){
int p = i;
while(p<n){
int l = p , r = n;
int ng = stg.query(i,p);
while(l+1!=r){
int m = l+r>>1;
if(stg.query(i,m) == ng){
l = m;
}else r = m;
}
p = l;
if(stg.query(i,p) != stmin.query(i,p)){
ok = 0;break;
}
p++;
if(p>=n) break;
if(stg.query(i,p)!=stmin.query(i,p)){
ok = 0;break;
}
}
if(ok == 0) break;
}
return ok;
}
vector<int> lpos(vector<int> b){
vector<int> stk;
int n = b.size();
vector<int> res(n,0);
for(int i = 0;i<n;i++){
while(stk.size() && b[stk.back()] >= b[i]) stk.pop_back();
if(stk.size()){
res[i] = stk.back() + 1;
}
stk.push_back(i);
}
return res;
}
int check(vector<int>& b){
SparseTable2<int> stmin(b);
int n = b.size();
auto lp = lpos(b);
reverse(all(b));
auto rp = lpos(b);
reverse(all(rp));reverse(all(b));
for(int i = 0;i<n;i++) rp[i] = n-1 - rp[i];
for(int i =0;i<n;i+=1){
int l = lp[i] , r = rp[i];
if(l==i && r == i) continue;
int lval = 0 ,rval = 0;
if(l < i) lval = stmin.query(l,i-1);
if(r > i) rval = stmin.query(i+1,r);
int g = __gcd(lval , rval);
if(g < b[i] || g%b[i]) return 0;
}
return 1;
}
void solve(){
int n , k ;cin>>n>>k;
vector<int> a(n);
for(int&x:a) cin>>x;
int mx = *max_element(a.begin(),a.end());
int mi = *min_element(a.begin(),a.end());
if(mx == mi){
cout<<k<<" ";
cout<<1ll * (1 + k) * k /2<<endl;
return;
}
auto c = a;sort(c.begin(),c.end());
vector<int> ck;
int yd = c[0];
int d = 0;
for(int i =1;i<n;i++){
d = __gcd(d , c[i] - c[0]);
}
for(int i = 1;i*i<=d;i++){
if(d % i == 0){
ck.push_back(i);
if(i*i!=d) ck.push_back(d/i);
}
}
vector<int> ans;
ll ans1= 0 ,ans2 = 0;
mi = *min_element(a.begin(),a.end());
for(int x : ck){
int g = 0;
x -= yd;
if(x <1 || x > k) continue;
int d = x;
auto b = a;
for(int i =0;i<n;i+=1) b[i] += d;
if(check(b)){
ans1 += 1;ans2 = ans2 + x;
}
}
cout<<ans1<<" "<<ans2<<endl;
}
signed main(){
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(0);
int t;cin>>t;while(t--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
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: 3600kb
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
Wrong Answer
time: 0ms
memory: 3656kb
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:
wrong answer 273rd lines differ - expected: '0 0', found: '2 10'