QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#741383#9738. Make It Divisible5720226849WA 1ms6028kbC++142.9kb2024-11-13 14:15:012024-11-13 14:15:02

Judging History

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

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

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]);
}

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;
            while(l <= r) {
                int mid = l + r >> 1;
                if(query(mid) == query(vv[j]) - 1) 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) == query(vv[j])) 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;
        for(int i = 1; i < n; i ++) {
            int aa = a[i] + y, bb = a[i + 1] + y;
            if(aa % bb != 0 && bb % aa != 0) {
                ok = false;
                break;
            }
        }
        for(int i = 1; i < n; i ++)
            if(gcd(gcd(a[pos[i].x] + y, a[pos[i].y] + y), a[i] + y) != a[i] + y) {
                ok = false;
                break;
            }
        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: 6028kb

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

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'