QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#81963#4860. Longest Common SubsequenceSorting#AC ✓1770ms57532kbC++14906b2023-02-26 19:18:252023-02-26 19:18:28

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-26 19:18:28]
  • 评测
  • 测评结果:AC
  • 用时:1770ms
  • 内存:57532kb
  • [2023-02-26 19:18:25]
  • 提交

answer

#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include <numeric>

typedef long long ll;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

    while(t--){
        ll n, m, p, x, a, b, c;
        cin >> n >> m >> p >> x >> a >> b >> c;

        vector<int> s(n), t(m);
        map<int, int> first;
        for(int i = 0; i < n; ++i){
            x = (a * x % p * x + b * x + c) % p;
            s[i] = x;
            if(!first.count(x))
                first[x] = i;
        }
        int ans = 0;
        for(int i = 0; i < m; ++i){
            x = (a * x % p * x + b * x + c) % p;
            t[i] = x;
            if(first.count(x)){
                ans = max(ans, (int)min(m - i, n - first[x]));
            }
        }
        cout << ans << "\n";
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3276kb

input:

2
4 3 1024 1 1 1 1
3 4 1024 0 0 0 0

output:

0
3

result:

ok 2 number(s): "0 3"

Test #2:

score: 0
Accepted
time: 1687ms
memory: 57460kb

input:

1
1000000 1000000 999999937 0 0 11 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1382ms
memory: 57532kb

input:

1
1000000 1000000 1000000000 0 0 2 1

output:

437492

result:

ok 1 number(s): "437492"

Test #4:

score: 0
Accepted
time: 62ms
memory: 10764kb

input:

1
1000000 1000000 1000000000 0 0 0 0

output:

1000000

result:

ok 1 number(s): "1000000"

Test #5:

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

input:

1000
3 1 6 0 5 3 4
12 1 3 2 0 2 2
2 10 1 0 0 0 0
8 1 1 0 0 0 0
5 10 1 0 0 0 0
3 3 9 0 8 2 7
7 2 5 0 4 2 4
2 2 3 1 2 2 1
13 17 4 3 3 3 3
6 9 6 0 4 5 3
5 21 9 1 6 2 0
5 2 8 6 0 4 1
21 7 10 5 3 6 7
23 11 2 1 0 0 1
14 3 10 5 4 6 3
3 33 8 0 7 3 0
2 4 5 4 0 2 0
43 3 9 2 6 8 4
10 10 4 3 2 0 1
16 32 2 1 1 1...

output:

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

result:

ok 1000 numbers

Test #6:

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

input:

1000
14 6 7 1 1 5 5
6 2 6 3 2 5 2
13 10 5 0 2 1 4
7 2 1 0 0 0 0
7 18 2 1 0 0 1
22 1 8 7 1 6 4
15 1 3 2 1 1 1
3 14 4 3 2 0 1
21 5 4 1 0 1 2
4 8 3 2 2 2 2
12 3 9 4 6 3 2
13 16 1 0 0 0 0
12 21 9 0 1 8 5
2 1 8 1 0 1 5
8 51 10 7 0 6 8
6 1 5 0 3 1 4
3 18 5 0 0 4 2
8 32 8 4 2 0 2
20 6 5 4 0 3 3
20 2 9 0 4 ...

output:

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

result:

ok 1000 numbers

Test #7:

score: 0
Accepted
time: 0ms
memory: 3352kb

input:

1000
11 3 4 3 2 2 1
7 11 1 0 0 0 0
4 1 1 0 0 0 0
5 13 8 1 7 3 7
8 24 3 2 1 2 1
13 7 5 4 1 0 2
6 2 6 1 1 0 1
2 26 2 0 0 1 0
3 14 6 5 3 1 3
9 47 10 2 2 6 1
6 7 9 3 0 0 8
6 7 5 2 3 4 3
10 8 2 1 0 0 0
6 5 1 0 0 0 0
7 1 10 1 4 9 2
29 15 8 0 3 5 2
1 6 10 9 8 3 9
13 3 8 4 2 5 4
12 18 6 1 5 3 2
18 7 4 0 2 3...

output:

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

result:

ok 1000 numbers

Test #8:

score: 0
Accepted
time: 3ms
memory: 3280kb

input:

1000
33 16 5 3 1 0 0
45 2 10 7 5 5 5
16 8 5 0 3 2 3
13 4 5 0 2 0 1
4 12 4 2 2 0 0
22 6 1 0 0 0 0
12 17 3 2 0 2 2
5 1 1 0 0 0 0
12 12 10 3 7 9 2
2 1 7 3 2 3 5
5 1 7 1 4 3 6
1 6 10 1 9 3 9
16 2 3 2 0 2 2
5 1 4 0 3 2 2
12 7 4 0 2 0 0
2 21 4 0 1 3 1
1 3 1 0 0 0 0
11 3 3 1 0 2 0
2 23 5 2 3 0 3
3 1 8 2 1 ...

output:

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

result:

ok 1000 numbers

Test #9:

score: 0
Accepted
time: 3ms
memory: 3372kb

input:

1000
5 9 6 5 1 2 1
15 7 5 4 4 3 1
6 22 8 5 6 0 1
10 41 1 0 0 0 0
3 8 1 0 0 0 0
3 10 5 0 4 1 4
8 25 10 2 1 6 8
10 4 7 4 5 4 0
12 25 1 0 0 0 0
10 1 3 2 1 1 2
13 8 8 7 2 2 3
16 7 7 0 1 2 5
19 1 1 0 0 0 0
30 3 9 5 6 5 5
3 7 5 0 4 1 2
3 7 1 0 0 0 0
1 2 6 0 2 3 0
4 4 4 0 1 0 1
2 3 4 2 3 2 3
1 1 4 3 2 3 3
...

output:

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

result:

ok 1000 numbers

Test #10:

score: 0
Accepted
time: 3ms
memory: 3416kb

input:

1000
7 14 4 1 2 1 3
4 2 9 7 4 1 8
10 1 5 2 0 4 0
10 3 4 2 0 0 3
4 10 3 2 0 2 1
5 2 9 6 6 8 0
9 13 2 0 0 0 0
10 2 6 0 1 0 2
1 1 9 3 2 4 2
26 14 4 0 2 0 3
8 39 6 5 3 3 5
5 29 1 0 0 0 0
7 6 5 0 2 2 1
6 6 8 3 1 7 2
2 14 6 0 5 3 1
1 6 7 1 6 1 6
5 1 9 8 3 2 0
1 8 4 2 0 0 2
17 10 8 6 1 7 4
4 7 7 0 5 3 5
4 ...

output:

7
2
1
3
4
2
9
2
0
14
8
5
6
4
2
1
0
1
10
4
4
3
3
6
1
8
10
1
4
12
9
4
3
4
2
5
2
13
7
13
5
6
5
1
9
1
1
4
2
1
19
23
5
6
9
6
8
7
3
6
2
4
1
2
1
3
2
15
4
14
7
7
3
3
3
2
2
8
1
2
3
17
2
14
9
1
3
9
1
2
8
3
1
6
14
1
3
8
13
9
2
3
4
3
7
9
18
3
2
2
25
0
1
4
1
5
2
1
1
2
21
10
2
7
2
8
4
9
2
4
1
5
17
2
5
2
1
2
1
19
...

result:

ok 1000 numbers

Test #11:

score: 0
Accepted
time: 4ms
memory: 3360kb

input:

1000
11 17 364842564 82604785 37722477 127540201 348362558
1 9 901635804 270985425 297435912 869439619 220374725
2 1 37302871 5111534 30668704 32082155 31325822
3 4 99577587 77936588 43641803 21097237 21318455
8 5 712082931 351941911 501914122 261694155 309605826
14 6 651864103 92791431 550378703 26...

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
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
0
0
...

result:

ok 1000 numbers

Test #12:

score: 0
Accepted
time: 297ms
memory: 3644kb

input:

1000
1209 987 999999937 291305504 0 68216322 530194456
2238 1471 999999937 76673153 0 341886819 860681688
873 419 999999937 589293002 0 55260699 22543183
61 2048 999999937 552210226 0 134882182 117614359
224 2146 999999937 766154827 0 729854833 937145275
552 1605 999999937 419027830 0 371762614 3161...

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
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
0
0
...

result:

ok 1000 numbers

Test #13:

score: 0
Accepted
time: 396ms
memory: 5780kb

input:

100
9061 20999 999999937 826477073 0 976276173 745907744
2501 19362 999999937 572675777 0 952968022 202640042
17940 7222 999999937 640174501 0 354424767 107328583
12360 3249 999999937 190243697 0 278031114 383018510
43163 6201 999999937 548839274 0 367395998 137385764
14163 4696 999999937 772376900 ...

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

ok 100 numbers

Test #14:

score: 0
Accepted
time: 642ms
memory: 14060kb

input:

10
57614 201647 999999937 341573321 0 419175243 223164026
74551 9126 999999937 882666158 0 607958120 989764309
43376 115407 999999937 895009360 0 731815180 833739060
51789 59509 999999937 259524677 0 419408925 263911926
152779 140117 999999937 693285102 0 127584127 882756530
59391 45747 999999937 92...

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 numbers

Test #15:

score: 0
Accepted
time: 1770ms
memory: 57464kb

input:

1
1000000 1000000 999999937 250663119 0 119564793 257785165

output:

0

result:

ok 1 number(s): "0"