QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#797053#9738. Make It DivisibletilennWA 1ms3936kbC++144.5kb2024-12-02 15:03:452024-12-02 15:03:48

Judging History

你现在查看的是最新测评结果

  • [2024-12-02 15:03:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3936kb
  • [2024-12-02 15:03:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
typedef long long LL;
const int N = 1e5;
vector<int> primes;
vector<int> st(N + 1);

void init(){
    for(int i = 2;i <= N;i++){
        if(!st[i]){
            st[i] = i;
            primes.push_back(i);
        }
        for(auto j : primes){
            if(i * j > N)break;
            st[i * j] = j;
            if(i % j == 0)break;
        }
    }
}

template<class T = int,class Cmp = std::less<T>>
struct RMQ{
    const Cmp cmp = Cmp();
    int n,lg;
    vector<vector<T>> st;
    RMQ(){}
    RMQ(vector<T> &v){
        init(v);
    }
    void init(vector<T> &v){
        n = (int)v.size() - 1;
        lg = __lg(n) + 1;
        st.assign(lg,vector<T>(n + 1));
        for(int i = 1;i <= n;i++)st[0][i] = v[i];
        for(int i = 1;i < lg;i++){
            for(int j = 1;j <= n;j++){
                st[i][j] = min(st[i - 1][j],st[i - 1][min(j + (1 << i - 1),n)],cmp);
            }
        }
    }
    T operator()(int l,int r){
        int t = __lg(r - l + 1);
        return min(st[t][l],st[t][r - (1 << t) + 1],cmp);
    }
};

template<class T,class Cmp>
struct ST{
    const Cmp cmp = Cmp();
    int n,lg;
    vector<vector<T>> st;
    ST(){}
    ST(vector<T> &v){
        init(v);
    }
    void init(vector<T> &v){
        n = (int)v.size() - 1;
        lg = __lg(n) + 1;
        st.assign(lg,vector<T>(n + 1));
        for(int i = 1;i <= n;i++)st[0][i] = v[i];
        for(int i = 1;i < lg;i++){
            for(int j = 1;j <= n;j++){
                st[i][j] = cmp(st[i - 1][j],st[i - 1][min(j + (1 << i - 1),n)]);
            }
        }
    }
    T operator()(int l,int r){
        int t = __lg(r - l + 1);
        return cmp(st[t][l],st[t][r - (1 << t) + 1]);
    }
};

template<class T>
struct Cmp{
    T operator()(const T& x,const T& y)const{return __gcd(x,y);}
};

void solve(){
    LL n,k;
    cin >> n >> k;
    vector<LL> a(n + 1);
    vector<LL> d(n + 1);
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        d[i] = abs(a[i] - a[i - 1]);
    }
    if(count(a.begin() + 1,a.end(),a[1]) == n){
        cout << k << " " << k * (k + 1) / 2 << endl;
        return;
    }
    ST<LL,Cmp<LL>> f(d);
    RMQ<LL,less<LL>> mi(a);
    unordered_map<int,int> res;
    map<LL,vector<int>> fg;
    auto work = [&](int l,int r,LL x)->void{
        if(fg.count(x)){
            for(auto it : fg[x]){
                res[it]++;
            }
            return;
        }
        vector<pair<int,int>> w;
        LL X = x;
        for(auto p : primes){
            if(p > x)break;
            if(x % p == 0){
                int c = 0;
                while(x % p == 0){
                    x /= p;
                    c++;
                }
                w.push_back({p,c});
            }
            if(x <= N)break;
        }
        if(x > 1 && x <= N){
            while(x > 1){
                int p = st[x],c = 0;
                while(x % p == 0){
                    x /= p;
                    c++;
                }
                w.push_back({p,c});
            }
        }
        if(x > 1)w.push_back({x,1});

        int m = mi(l,r);
        auto dfs = [&](auto self,int i,LL s)->void{
            if(i == w.size()){
                if(s > m && s - m <= k && (a[l] + s - m) % s == 0){
                    res[s - m]++;
                    fg[X].push_back(s - m);
                }
                return;
            }
            self(self,i + 1,s);
            for(int j = 1;j <= w[i].second;j++){
                s *= w[i].first;
                self(self,i + 1,s);
            }
        };
        dfs(dfs,0,1);
    };
    int c = 0;
    for(int i = 1;i <= n;i++){
        int p = i + 1,t = 0;
        while(p <= n){
            int l = p,r = n + 1;
            while(l < r){
                int mid = (l + r) >> 1;
                if(f(i + 1,mid) == t)l = mid + 1;
                else r = mid;
            }
            p = l;
            if(p <= n){
                t = f(i + 1,p);
                work(i,p,t);
                c++;
            }
        }   
    }   
    LL cnt = 0,s = 0;
    for(auto it : res){
        if(it.second == c){
            cnt++;
            s += it.first;
        }
    }
    cout << cnt << " " << s << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    init();
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3640kb

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: 3936kb

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
1 1
0 0
0 0

result:

wrong answer 2nd lines differ - expected: '0 0', found: '1 1'