QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645834#6399. Classic: Classical Problemcrimsonsunset#RE 0ms3640kbC++202.9kb2024-10-16 20:01:252024-10-16 20:01:26

Judging History

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

  • [2024-10-16 20:01:26]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3640kb
  • [2024-10-16 20:01:25]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
#define int ll
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

mt19937 rnd(1329);

int mod;

int fastpow(int a, int b) {
    if (b == 0) return 1;
    int t = fastpow(a, b / 2);
    t = 1ll * t * t % mod;
    if (b % 2) {
        t = 1ll * t * a % mod;
    }
    return t;
}

int lol(int a) {
    return 1 * fastpow(a, mod - 2);
}

bool used[(int)2e5 + 10];

void solve() {
    int n, p;
    cin >> n >> p;
    mod = p;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (auto e : a) used[e] = 1;
    if (used[0] == 0) {
//        cout << "lol ";
        cout << "1 1\n0\n";
        for (auto e : a) used[e] = 0;
        return;
    }
    sort(all(a));
    if (n == 1) {
        for (auto e : a) used[e] = 0;
        cout << p << ' ' << 1 << '\n';
        for (int i = 0; i < p; ++i) cout << i << ' ';
        cout << '\n';
        return;
    }
    int ans = 0;
    while (used[ans]) ans++;
    set<int> anss; anss.insert(1);
    if (ans == 1) anss.insert(0);
    vector<int> nota;
    for (int i = 0; i < n - 1; ++i) for (int j = a[i] + 1; j < a[i + 1]; ++j) nota.push_back(j);
    for (int j = a[n - 1] + 1; j < p; ++j) nota.push_back(j);
    vector<int> ord(p);
    iota(all(ord), 0);
    for (auto x : ord) {
        if (x == 0) continue;
        if (!used[1ll * fastpow(x, mod - 2) % mod]) continue;
        bool ok = 1;
//        cout << x << '\n';
        for (int i = 0; i < 300; ++i) {
            if (ans == 1) break;
            int j = rnd() % (ans - 1) + 1;
            if (used[1ll * j * fastpow(x, mod - 2) % mod]) continue;
            ok = 0;
            break;
        }
        for (int i = 0; i < 300; ++i) {
            if (ans == 1) break;
            int j = nota[rnd() % (nota.size())];
            if ((j * x % mod) < ans) {
//                cout << x << ' ' << j << '\n';
                ok = 0;
                break;
            }
        }
//        cout << x << ' ' << ok << '\n';
        if (!ok) continue;
        for (int j = 1; j < ans; ++j) {
            if (used[1ll * j * fastpow(x, mod - 2) % mod]) continue;
            ok = 0;
            break;
        }
        if (!ok) continue;
        if (ans == p) {
            anss.insert(x);
            continue;
        }
        if (used[1ll * ans * fastpow(x, mod - 2) % mod]) {
            anss.clear();
            while (ans < p && used[1ll * ans * fastpow(x, mod - 2) % mod]) ans++;
        }
        anss.insert(x);
    }
    cout << anss.size() << ' ' << ans << '\n';
    for (auto e : anss) cout << e << ' '; cout << '\n';
    for (auto e : a) used[e] = 0;
}


signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 3
0 2
3 5
2 3 4
3 5
0 2 3

output:

1 2
2 
1 1
0
2 2
2 3 

result:

ok 6 lines

Test #2:

score: -100
Runtime Error

input:

3
1 2
0
1 2
1
2 2
1 0

output:


result: