QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#786227#9726. AUSqinsj#WA 0ms3572kbC++202.6kb2024-11-26 20:48:252024-11-26 20:48:25

Judging History

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

  • [2024-11-26 20:48:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3572kb
  • [2024-11-26 20:48:25]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;
typedef pair<int, int> PII;
typedef long long LL;


const int B = 20;
struct ST {
    #define lg2(n) (63 - __builtin_clzll((long long)(n)))
    vector<int> &a;
    vector<array<int, B>> mi;
    ST (int n, vector<int> &a): a(a) {
        mi.assign(n + 5, {});
        for (int i = 1; i <= n; i++) mi[i][0] = i;
        for (int j = 1; j < B; j++) {
            for (int i = 1; i + (1 << j) - 1 <= n; i++) {
                int ml = mi[i][j - 1], mr = mi[i + (1 << j - 1)][j - 1];
                mi[i][j] = a[ml] <= a[mr] ? ml : mr;
            }
        }
    }
    int pmi(int l, int r) {
        int k = lg2(r - l + 1);
        int ml = mi[l][k], mr = mi[r - (1 << k) + 1][k];
        return a[ml] <= a[mr] ? ml : mr;
    }
};

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 5);
    for (int i = 1; i <= n; i++) cin >> a[i];

    int same = true;
    for (int i = 1; i <= n; i++) if (a[i] != a[1]) same = false;

    if (same) {
        cout << k << ' ' << 1ll * k * (k + 1) / 2 << "\n";
        return ;
    }

    int mn = 1e9;
    for (int i = 1; i <= n; i++) mn = min(mn, a[i]);
    int mn2 = 1e9;
    for (int i = 1; i <= n; i++) if (a[i] != mn) mn2 = min(mn2, a[i]);

    LL num = 0, res = 0;

    auto check = [&](LL x)->void {
        assert((mn2 - (x + 1) * mn) % x == 0);
        x = (mn2 - (x + 1) * mn) / x;
        if (x > k) return ;
        vector<int> b(n + 5);
        for (int i = 1; i <= n; i++) b[i] = a[i] + x;

        ST stb(n, b);
        auto dfs = [&](auto self, int l, int r, int lst)->int {
            if (l > r) return true;
            int i = stb.pmi(l, r);
            // if (x == 5) cout << l << ' ' << r << ' ' << i << "\n";
            int x = b[i];
            if (x % lst) return false;
            while (1) {
                if (!self(self, l, i - 1, x)) return false;
                if (i == r) break;
                int nxt = stb.pmi(i + 1, r);
                if (b[nxt] != x) break;
                i = nxt;
            }
            return self(self, i + 1, r, x);
        };
        if (dfs(dfs, 1, n, 1)) {
            num++; res += x;
        }
    };

    int d = mn2 - mn;
    for (int i = 1; i * i <= d; i++) {
        if (d % i == 0) {
            check(i);
            if (i * i != d) check(d / i);
        }
    }
    cout << num << ' ' << res << "\n";
}   
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}
/*
g++ m.cpp -o m && ./m < in.txt > out.txt
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3572kb

input:

4
abab
cdcd
abce
abab
cdcd
abcd
abab
cdcd
abc
x
yz
def

output:

32535 529279380
32535 529279380
32535 529279380
32535 529279380

result:

wrong answer 1st lines differ - expected: 'YES', found: '32535 529279380'