QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#741627#9738. Make It Divisible5720226849WA 1ms5868kbC++143.4kb2024-11-13 14:50:102024-11-13 14:50:10

Judging History

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

  • [2024-11-27 18:44:44]
  • hack成功,自动添加数据
  • (/hack/1263)
  • [2024-11-14 09:10:13]
  • hack成功,自动添加数据
  • (/hack/1178)
  • [2024-11-13 14:50:10]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5868kb
  • [2024-11-13 14:50:10]
  • 提交

answer

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

// #define int long long
#define x first
#define y second 
#define ls u << 1
#define rs u << 1 | 1
#define PII pair<int,int>  

const int N = 5e4 + 10, inf = 1e18, mod1 = 998244353, mod2 = 1e9 + 7, M = 18;

int lg[N];

int gcd(int a, int b) {
    return (b == 0 ? a : gcd(b, a % b));
}

int lowbit(int x) {
    return x & -x;
}

PII pos[N];
int tr[N];

void add(int x) {
    for(; x < N; x += lowbit(x)) tr[x] ++;
}

int query(int x) {
    int res = 0;
    for(; x; x -= lowbit(x)) res += tr[x];
    return res;
}

int f[N][M];

int get(int l, int r) {
    int k = lg[r - l + 1];
    return gcd(f[l][k], f[r - (1 << k) + 1][k]);
}


struct node {
    int l, r, d;
    bool operator < (const node& A) const {
        return l < A.l;
    }
};

void solve() {
    int n;
    long long k; cin >> n >> k; 
    vector<int>a(n + 1); int mi = inf;
    vector<PII>vec;
    for(int i = 1; i <= n; i ++) cin >> a[i], mi = min(mi, a[i]), vec.push_back({a[i], i}), tr[i] = 0;
    sort(vec.begin(), vec.end());
    for(int i = 0; i < n; i ++) {
        vector<int>vv; vv.push_back(vec[i].y);
        while(i < n - 1 && vec[i + 1].x == vec[i].x) vv.push_back(vec[i + 1].y), i ++;
        for(int j = 0; j < vv.size(); j ++) add(vv[j]);
        for(int j = 0; j < vv.size(); j ++) {
            int l = 0, r = vv[j] - 1;
            int ss = query(vv[j]) - 1;
            while(l <= r) {
                int mid = l + r >> 1;
                if(query(mid) == ss) r = mid - 1;
                else l = mid + 1;
            }
            pos[vv[j]].x = l + 1;
            l = vv[j] + 1, r = n;
            while(l <= r) {
                int mid = l + r >> 1;
                if(query(mid) == ss) l = mid + 1;
                else r = mid - 1;
            }
            pos[vv[j]].y = r;
        }
    }
    int d = 0;
    for(int i = 1; i < n; i ++) d = gcd(d, abs(a[i] - a[i + 1]));
    if(d == 0) {
        cout << k << ' ' << k * (k + 1) / 2 << '\n';
        return;
    }
    vector<int>v;
    for(int i = 1; i * i <= d; i ++)
        if(d % i == 0) {
            v.push_back(i);
            if(i != d / i) v.push_back(d / i);
        }
    int cnt = 0;
    long long res = 0;
    for(auto x : v) {
        if(x <= mi || x - mi > k) continue;
        int y = x - mi;
        bool ok = true;
        set<node>s;
        for(int i = 1; i <= n; i ++) s.insert({i, i, a[i] + y});
        for(int i = vec.size() - 1; i >= 0; i --) {
            int u = vec[i].y;
            int l = pos[u].x, r = pos[u].y;
            int d = a[u] + y;
            while(true) {
                auto it = s.lower_bound({l, 0, 0});
                if(it != s.end()) {
                    if((*it).r <= r) {
                        d = gcd(d, (*it).d);
                    }
                    else break;
                }
                else break;
                s.erase(it);
            }
            if(d != a[u] + y) {
                ok = false;
                break;
            }
            s.insert({l, r, d});
        }
        if(ok) cnt ++, res += y;
    }
    cout << cnt << ' ' << res << '\n';
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1; cin >> t;
    for(int i = 2; i < N; i ++) lg[i] = lg[i / 2] + 1;
    while(t --)
        solve();
    return 0;
}

詳細信息

Test #1:

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

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

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: 1ms
memory: 4016kb

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
1 1
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
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 15th lines differ - expected: '0 0', found: '1 1'