QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#127847#6399. Classic: Classical ProblemUNos_mariconesWA 479ms8936kbC++203.2kb2023-07-20 09:46:062023-07-20 09:46:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 09:46:09]
  • 评测
  • 测评结果:WA
  • 用时:479ms
  • 内存:8936kb
  • [2023-07-20 09:46:06]
  • 提交

answer

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

#define ff    first
#define ss    second
#define pb    push_back

typedef long long    ll;
typedef pair<ll,int>    ii;
typedef long double    lf;


mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll SQ = 320;
const ll N = 2e5+5;
const ll mod = 998244353;
const ll oo = 1e14+5;

bitset<N> bt[40002];

int powmod (int a, int b, int p) {
    int res = 1;
    while (b)
        if (b & 1)
            res = int (res * 1ll * a % p),  --b;
        else
            a = int (a * 1ll * a % p),  b >>= 1;
    return res;
}

int generator (int p) {
    vector<int> fact;
    int phi = p-1,  n = phi;
    for (int i=2; i*i<=n; ++i)
        if (n % i == 0) {
            fact.push_back (i);
            while (n % i == 0)
                n /= i;
        }
    if (n > 1)
        fact.push_back (n);

    for (int res=2; res<=p; ++res) {
        bool ok = true;
        for (size_t i=0; i<fact.size() && ok; ++i)
            ok &= powmod (res, phi / fact[i], p) != 1;
        if (ok)  return res;
    }
    return -1;
}


int main(){
  #ifdef LOCAL
  freopen("input.txt","r",stdin);
  #endif // LOCAL
  ios_base::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);

  int t; cin >> t;
  while (t--) {
    int n, p; cin >> n >> p;
    int c = generator(p);

    vector <int> a(n);
    vector <int> ap(p);
    for (auto &e : a) cin >> e, ap[e] = 1;
    sort(a.begin(), a.end());

    if (a[0] == 0) {
      if (n == 1) {
        cout << p << " 1\n";
        for (int i = 0; i < p; ++i) cout << i << ' ';
        cout << '\n';
      }
      else {
        vector <int> seq;
        int curre = 1;
        for (int i = 0; i < p - 1; ++i) seq.pb(curre), curre = (curre * c) % p;


        int ya = 0;
        vector <int> ans;
        bitset<N> curr;
        curr.set();
        for (int j = 0; j < 5 && !ya; ++j) {
          int L = j * 40000 + 1, R = (j + 1) * 40000;
          bitset<N> up, down;
          for (int i = 0; i < p - 1; ++i) {
            if (ap[seq[i]]) down[p-1-i]=1;
          }
          for (int i = 0; i < p - 1; ++i) {
  //          cout << seq[i]<<'\n';
            if (ap[seq[i]]) {
              down[p-1]=0;
              up[0]=1;
            }
            if (L <= seq[i] && seq[i] <= R)
              bt[seq[i]-L] = up|down;

            up<<=1;
            down<<=1;
  //          for (int j = 0; j < p; ++j) {
  //            if (bt[seq[i]][j]==1)cout<<1;
  //            else cout<<0;
  //          }
  //          cout<<'\n';
          }
          for (int i = 0; i <= R-L; ++i) {
            if ((curr & bt[i]).any()) {
              curr &= bt[i];
            }
            else {
              cout << curr.count() << ' ' << i+L << '\n';
              for (int j = 0; j < p; ++j) {
                if (curr[j] == 1) ans.pb(seq[j]);
              }
              sort(ans.begin(), ans.end());
              for (auto &e : ans) cout << e << ' ';

              cout << '\n';
              ya = 1;
              break;
            }
  //          cout << i << endl;
          }
        }
      }
    }
    else {
      cout << "1 1\n0\n";
    }
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 1ms
memory: 3588kb

input:

3
1 2
0
1 2
1
2 2
1 0

output:

2 1
0 1 
1 1
0
1 2
1 

result:

ok 6 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

7
1 3
0
1 3
1
2 3
1 0
1 3
2
2 3
2 0
2 3
1 2
3 3
0 1 2

output:

3 1
0 1 2 
1 1
0
1 2
1 
1 1
0
1 2
2 
1 1
0
2 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 
1 1
0
1 2
2 
1 1
0
1 3
2 
1 1
0
1 3
4 
1 1
0
3 3
1 2 4 
1 1
0
2 2
2 5 
1 1
0
1 3
2 
1 1
0
1 3
4 
1 1
0
1 5
1 
1 1
0
1 2
3 
1 1
0
2 2
1 3 
1 1
0
2 2
3 4 
1 1
0
1 3
1 
1 1
0
1 3
3 
1 1
0
1...

result:

ok 254 lines

Test #6:

score: 0
Accepted
time: 35ms
memory: 3892kb

input:

2047
1 11
0
1 11
1
2 11
0 1
1 11
2
2 11
0 2
2 11
2 1
3 11
1 0 2
1 11
3
2 11
3 0
2 11
3 1
3 11
0 3 1
2 11
2 3
3 11
0 2 3
3 11
2 1 3
4 11
1 0 3 2
1 11
4
2 11
0 4
2 11
4 1
3 11
1 4 0
2 11
2 4
3 11
2 0 4
3 11
2 1 4
4 11
0 2 1 4
2 11
3 4
3 11
3 4 0
3 11
3 1 4
4 11
4 1 3 0
3 11
4 3 2
4 11
3 4 0 2
4 11
3 1...

output:

11 1
0 1 2 3 4 5 6 7 8 9 10 
1 1
0
1 2
1 
1 1
0
1 2
6 
1 1
0
1 3
1 
1 1
0
1 2
4 
1 1
0
2 2
1 4 
1 1
0
2 2
4 6 
1 1
0
1 4
1 
1 1
0
1 2
3 
1 1
0
2 2
1 3 
1 1
0
1 3
6 
1 1
0
2 3
1 6 
1 1
0
2 2
3 4 
1 1
0
3 2
1 3 4 
1 1
0
1 3
6 
1 1
0
1 5
1 
1 1
0
1 2
9 
1 1
0
2 2
1 9 
1 1
0
2 2
6 9 
1 1
0
1 3
1 
1 1
0
...

result:

ok 4094 lines

Test #7:

score: 0
Accepted
time: 175ms
memory: 3920kb

input:

8191
1 13
0
1 13
1
2 13
0 1
1 13
2
2 13
2 0
2 13
2 1
3 13
2 1 0
1 13
3
2 13
0 3
2 13
1 3
3 13
1 0 3
2 13
2 3
3 13
2 0 3
3 13
3 1 2
4 13
1 3 2 0
1 13
4
2 13
4 0
2 13
4 1
3 13
0 1 4
2 13
2 4
3 13
0 2 4
3 13
2 4 1
4 13
0 1 4 2
2 13
3 4
3 13
3 0 4
3 13
4 1 3
4 13
4 1 0 3
3 13
4 2 3
4 13
3 2 0 4
4 13
3 4...

output:

13 1
0 1 2 3 4 5 6 7 8 9 10 11 12 
1 1
0
1 2
1 
1 1
0
1 2
7 
1 1
0
1 3
1 
1 1
0
1 2
9 
1 1
0
2 2
1 9 
1 1
0
2 2
7 9 
1 1
0
1 4
1 
1 1
0
1 2
10 
1 1
0
2 2
1 10 
1 1
0
1 3
7 
1 1
0
2 3
1 7 
1 1
0
2 2
9 10 
1 1
0
3 2
1 9 10 
1 1
0
1 3
7 
1 1
0
1 5
1 
1 1
0
1 2
8 
1 1
0
2 2
1 8 
1 1
0
2 2
7 8 
1 1
0
1 3...

result:

ok 16382 lines

Test #8:

score: 0
Accepted
time: 311ms
memory: 4016kb

input:

11764
1 17
0
1 17
1
2 17
0 1
1 17
2
2 17
0 2
2 17
2 1
3 17
2 1 0
1 17
3
2 17
3 0
2 17
1 3
3 17
3 0 1
2 17
2 3
3 17
0 3 2
3 17
3 2 1
4 17
3 2 0 1
1 17
4
2 17
0 4
2 17
4 1
3 17
1 4 0
2 17
4 2
3 17
0 2 4
3 17
2 1 4
4 17
2 4 1 0
2 17
3 4
3 17
3 4 0
3 17
4 1 3
4 17
4 1 0 3
3 17
2 4 3
4 17
2 0 3 4
4 17
2 ...

output:

17 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
1 1
0
1 2
1 
1 1
0
1 2
9 
1 1
0
1 3
1 
1 1
0
1 2
6 
1 1
0
2 2
1 6 
1 1
0
2 2
6 9 
1 1
0
1 4
1 
1 1
0
1 2
13 
1 1
0
2 2
1 13 
1 1
0
1 3
9 
1 1
0
2 3
1 9 
1 1
0
2 2
6 13 
1 1
0
3 2
1 6 13 
1 1
0
1 3
9 
1 1
0
1 5
1 
1 1
0
1 2
7 
1 1
0
2 2
1 7 
1 1
0
2 2
7 ...

result:

ok 23528 lines

Test #9:

score: 0
Accepted
time: 298ms
memory: 6088kb

input:

10526
1 19
0
1 19
1
2 19
0 1
1 19
2
2 19
2 0
2 19
2 1
3 19
0 2 1
1 19
3
2 19
0 3
2 19
3 1
3 19
1 0 3
2 19
3 2
3 19
2 0 3
3 19
1 3 2
4 19
1 2 0 3
1 19
4
2 19
0 4
2 19
4 1
3 19
0 1 4
2 19
4 2
3 19
4 0 2
3 19
2 4 1
4 19
4 2 0 1
2 19
4 3
3 19
0 3 4
3 19
1 3 4
4 19
3 4 0 1
3 19
4 3 2
4 19
0 4 3 2
4 19
1 ...

output:

19 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 
1 1
0
1 2
1 
1 1
0
1 2
10 
1 1
0
1 3
1 
1 1
0
1 2
13 
1 1
0
2 2
1 13 
1 1
0
2 2
10 13 
1 1
0
1 4
1 
1 1
0
1 2
5 
1 1
0
2 2
1 5 
1 1
0
1 3
10 
1 1
0
2 3
1 10 
1 1
0
2 2
5 13 
1 1
0
3 2
1 5 13 
1 1
0
1 3
10 
1 1
0
1 5
1 
1 1
0
1 2
4 
1 1
0
2 2
1 4 
...

result:

ok 21052 lines

Test #10:

score: -100
Wrong Answer
time: 479ms
memory: 8936kb

input:

10000
9 83
60 35 63 59 58 81 0 13 71
1 5
0
1 7
0
2 61
39 0
2 7
0 4
1 7
0
2 19
0 14
1 2
0
3 23
14 10 0
3 11
0 5 2
1 5
0
2 7
0 4
2 3
0 2
2 3
0 1
1 13
0
5 47
10 2 34 15 0
1 2
0
1 17
0
1 11
0
2 7
1 0
1 7
0
2 23
0 17
2 13
10 0
2 7
1 0
6 31
19 13 6 29 0 24
4 23
0 5 18 17
2 19
0 5
1 7
0
2 13
7 0
3 17
0 6 1...

output:

2 3
38 76 
5 1
0 1 2 3 4 
7 1
0 1 2 3 4 5 6 
1 2
36 
1 2
2 
7 1
0 1 2 3 4 5 6 
1 2
15 
2 1
0 1 
2 2
5 7 
2 2
6 9 
5 1
0 1 2 3 4 
1 2
2 
1 2
2 
1 2
1 
13 1
0 1 2 3 4 5 6 7 8 9 10 11 12 
4 2
18 22 24 33 
2 1
0 1 
17 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
11 1
0 1 2 3 4 5 6 7 8 9 10 
1 2
1 
7 1
0 ...

result:

wrong answer 403rd lines differ - expected: '1 2', found: '1 3'