QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#711989 | #7949. K-Lottery | kizen# | WA | 1415ms | 82592kb | C++20 | 4.2kb | 2024-11-05 14:13:03 | 2024-11-05 14:13:11 |
Judging History
answer
#include <bits/stdc++.h>
#ifndef LOCAL
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#endif
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define pi array<int, 2>
#define comp(v) (sort(all(v)), v.erase(unique(all(v)), v.end()))
#define lb(v, x) (lower_bound(all(v), x) - v.begin())
using namespace std;
#define int long long
const pi v1 = {2, 1610612741};
// const pi v1 = {97, 805306457};
struct Seg{
int n;
vector<int> tr;
Seg(int m){
n = m + 4;
tr.resize(n * 4 + 4);
}
void push(int x, int s, int e, int pos, int val){
if(s == e){
tr[x] = val;
return;
}
int m = s + e >> 1;
if(pos <= m) push(x * 2, s, m, pos, val);
else push(x * 2 + 1, m + 1, e, pos, val);
tr[x] = (tr[x * 2] + tr[x * 2 + 1]) % v1[1];
}
int get(int x, int s, int e, int fs, int fe){
if(fe < s || fs > e || fs > fe) return 0;
if(fs <= s && fe >= e) return tr[x];
int m = s + e >> 1;
return (get(x * 2, s, m, fs, fe) + get(x * 2 + 1, m + 1, e, fs, fe)) % v1[1];
}
};
int pw(int x, int y, int md){
if(!y) return 1;
if(y == 1) return x % md;
int v = pw(x, y >> 1, md);
(v *= v) %= md;
if(y & 1) (v *= x) %= md;
return v;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int k, m, n; cin >> k >> m >> n;
vector<vector<int>> a(m, vector<int>(k));
for(int i = 0; i < m; ++i){
for(int j = 0; j < k; ++j){
cin >> a[i][j]; --a[i][j];
}
}
vector<int> hsh(m + 1);
for(int i = 0; i < m; ++i){
Seg tr(k + 4);
for(int j = 0; j < k; ++j){
int rv = tr.get(1, 0, k - 1, a[i][j], k - 1);
(rv *= pw(v1[0], j, v1[1])) %= v1[1];
(hsh[i] += rv) %= v1[1];
tr.push(1, 0, k - 1, a[i][j], pw(v1[0], j * k, v1[1]));
}
}
vector<int> p(n);
for(int i = 0; i < n; ++i){
cin >> p[i];
}
auto srt = p;
comp(srt);
for(int i = 0; i < n; ++i){
p[i] = lb(srt, p[i]);
}
Seg tr(n + 4), rt(n + 4);
for(int j = 0; j < k; ++j){
int rv = tr.get(1, 0, n - 1, p[j], n - 1);
(rv *= pw(v1[0], j, v1[1])) %= v1[1];
(hsh[m] += rv) %= v1[1];
tr.push(1, 0, n - 1, p[j], pw(v1[0], j * k, v1[1]));
rt.push(1, 0, n - 1, p[j], pw(v1[0], j, v1[1]));
}
vector<int> id(m);
iota(all(id), 0);
sort(all(id), [&](int x, int y){return hsh[x] < hsh[y];});
int inv1 = pw(v1[0], v1[1] - 2, v1[1]);
int inv1k1 = pw(inv1, k + 1, v1[1]);
int inv1k = pw(inv1, k, v1[1]);
int k1 = pw(v1[0], k - 1, v1[1]);
int inv1kinv = pw(inv1k, v1[1] - 2, v1[1]);
// for(int i = 0; i <= m; ++i){
// cout << hsh[i] << endl;
// }
int trgop = 1, rtgop = 1;
int trgopinv = 1, rtgopinv = 1;
for(int i = 0; i + k <= n; ++i){
int pos = lower_bound(id.begin(), id.end(), m, [&](int x, int y){return hsh[x] < hsh[y];}) - id.begin();
if(pos < sz(id) && hsh[id[pos]] == hsh[m]){
for(int j = 0; j < k; ++j){
cout << a[id[pos]][j] + 1 << ' ';
}
return 0;
}
if(i + k < n){
rt.push(1, 0, n - 1, p[i], 0);
tr.push(1, 0, n - 1, p[i], 0);
// cout << hsh[m] << ' ';
(hsh[m] += v1[1] - rt.get(1, 0, n - 1, 0, p[i] - 1) * rtgop % v1[1]) %= v1[1];
// cout << hsh[m] << ' ';
(hsh[m] *= inv1k1) %= v1[1];
(trgop *= inv1k) %= v1[1];
(rtgop *= inv1) %= v1[1];
(trgopinv *= inv1kinv) %= v1[1];
(rtgopinv *= v1[0]) %= v1[1];
// cout << hsh[m] << ' ';
int rv = tr.get(1, 0, n - 1, p[i + k], n - 1) * trgop % v1[1];
(rv *= k1) %= v1[1];
(hsh[m] += rv) %= v1[1];
tr.push(1, 0, n - 1, p[i + k], pw(k1, k, v1[1]) * trgopinv % v1[1]);
rt.push(1, 0, n - 1, p[i + k], k1 * rtgopinv % v1[1]);
// cout << endl;
}
}
cout << 0;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
input:
3 2 10 1 2 3 1 3 2 20 35 10 7 99 53 72 33 88 16
output:
1 3 2
result:
ok single line: '1 3 2 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
4 5 10 1 2 3 4 1 2 4 3 3 4 1 2 4 1 2 3 4 2 3 1 19 31 9 1 89 48 63 30 78 12
output:
4 2 3 1
result:
ok single line: '4 2 3 1 '
Test #3:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
3 3 7 1 3 2 2 3 1 2 1 3 11 22 33 44 55 66 77
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 830ms
memory: 82592kb
input:
10000 10 1000000 1 5001 2 5002 3 5003 4 5004 5 5005 6 5006 7 5007 8 5008 9 5009 10 5010 11 5011 12 5012 13 5013 14 5014 15 5015 16 5016 17 5017 18 5018 19 5019 20 5020 21 5021 22 5022 23 5023 24 5024 25 5025 26 5026 27 5027 28 5028 29 5029 30 5030 31 5031 32 5032 33 5033 34 5034 35 5035 36 5036 37 5...
output:
1 5001 2 5002 3 5003 4 5004 5 5005 6 5006 7 5007 8 5008 9 5009 10 5010 11 5011 12 5012 13 5013 14 5014 15 5015 16 5016 17 5017 18 5018 19 5019 20 5020 21 5021 22 5022 23 5023 24 5024 25 5025 26 5026 27 5027 28 5028 29 5029 30 5030 31 5031 32 5032 33 5033 34 5034 35 5035 36 5036 37 5037 38 5038 39 50...
result:
ok single line: '1 5001 2 5002 3 5003 4 5004 5 ...4998 9998 4999 9999 5000 10000 '
Test #5:
score: 0
Accepted
time: 1415ms
memory: 82388kb
input:
10000 10 1000000 7171 4541 8189 3253 6694 2078 7384 1786 7847 5040 953 4126 4806 3532 7875 8531 3543 2706 8565 1509 2092 4125 6110 5251 6314 4574 6726 8900 9328 8639 3990 5234 9012 5023 3289 2825 8038 3593 2249 337 6252 3831 7967 3839 2815 540 3754 1009 8772 2939 2845 5067 6587 2615 375 7252 9940 18...
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 810ms
memory: 82540kb
input:
10000 10 1000000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1399ms
memory: 82296kb
input:
10000 10 1000000 3 7 8 1 4 10 2 5 9 6 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 1415ms
memory: 82324kb
input:
10000 10 1000000 1 3 7 10 6 4 9 8 2 5 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 1370ms
memory: 82224kb
input:
100 1000 1000000 34 82 39 96 30 85 83 16 8 31 51 63 76 49 3 7 58 17 42 94 41 9 11 47 89 6 86 19 100 77 37 93 40 15 36 71 23 46 48 55 2 92 64 18 22 21 12 72 1 99 70 81 56 57 53 62 50 35 65 43 73 60 97 24 4 98 20 90 26 68 66 25 74 87 14 67 45 95 33 32 52 29 5 88 54 13 91 10 59 80 28 38 78 61 79 75 69 ...
output:
0
result:
ok single line: '0'
Test #10:
score: -100
Wrong Answer
time: 468ms
memory: 82064kb
input:
100 1000 1000000 45 10 54 59 1 86 77 71 61 27 62 26 39 23 21 88 24 85 32 66 53 70 78 90 22 7 72 35 42 76 5 14 16 15 17 51 38 2 46 20 41 56 28 4 57 49 25 97 64 44 8 58 96 29 63 52 89 33 18 94 69 36 43 74 98 40 73 87 65 11 100 60 93 30 13 84 19 80 34 79 31 48 37 12 99 82 92 3 9 67 83 47 50 68 55 91 6 ...
output:
27 26 61 64 13 66 93 80 88 11 34 28 53 32 10 35 60 83 65 15 41 43 50 77 78 14 71 49 38 92 76 94 59 70 36 67 74 85 6 87 57 72 97 73 23 100 55 48 9 40 31 24 18 42 95 44 39 86 29 3 69 21 30 84 12 7 22 91 98 51 79 2 90 62 17 25 33 20 63 5 46 56 52 37 1 75 68 96 47 19 99 45 4 58 54 8 82 16 81 89
result:
wrong answer 1st lines differ - expected: '0', found: '27 26 61 64 13 66 93 80 88 11 ...19 99 45 4 58 54 8 82 16 81 89 '