QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#72339 | #5091. 大冬天题 | zhoukangyang | 100 ✓ | 256ms | 58812kb | C++17 | 5.0kb | 2023-01-15 14:52:16 | 2023-01-15 14:53:03 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); i++)
#define R(i, j, k) for(int i = (j); i >= (k); i--)
#define ll long long
#define ull unsigned long long
#define sz(a) ((int) a.size())
#define vi vector<int>
#define me(a, x) memset(a, x, sizeof(a))
using namespace std;
const int N = 2e6 + 7;
namespace fastgcd {
const int v = 2000000, radio = 1454;
int np[v + 10], prime[v + 10], cnt;
int k[v + 10][3];
int _gcd[radio + 10][radio + 10];
inline bool gcd(int a, int b) {
if(!a) return b == 1;
for(int i = 0; i < 3; i++) {
if(k[a][i] > radio) {
if(b % k[a][i] == 0) return false;
}
else if(k[a][i] > 1 && !_gcd[k[a][i]][b % k[a][i]]) return false;
}
return true;
}
int Main() {
k[1][0] = k[1][1] = k[1][2] = 1;
np[1] = 1;
for(int i = 2; i <= v; i++) {
if(!np[i]) prime[++cnt] = i, k[i][2] = i, k[i][1] = k[i][0] = 1;
for(int j = 1; prime[j] * i <= v; j++) {
np[i * prime[j]] = 1;
int *tmp = k[i * prime[j]];
tmp[0] = k[i][0] * prime[j];
tmp[1] = k[i][1];
tmp[2] = k[i][2];
if(tmp[1] < tmp[0]) swap(tmp[1], tmp[0]);
if(tmp[2] < tmp[1]) swap(tmp[2], tmp[1]);
if(i % prime[j] == 0) break;
}
}
_gcd[1][0] = _gcd[0][1] = true;
for(int _max = 1; _max <= radio; _max++)
for(int i = 1; i <= _max; i++)
_gcd[i][_max] = _gcd[_max][i] = _gcd[_max % i][i];
return 0;
}
}
int n, MOD[N], mat[N];
string xn;
// gcd(n + 2j + 1, n - 2k + 2i + 1) = 1
// gcd(M_{j + k - i} + 2j + 1, j + k - i) = 1
bool vis[N];
int arr[N], tot;
bool fi;
mt19937_64 orz;
inline int gcd(int x, int y) {
assert(y > 0);
return fastgcd :: gcd(y, x);
}
vi st, g;
int del;
bool dfs(int x) {
if(sz(st)) {
R(p, sz(st) - 1, 0) {
int i = st[p];
if(gcd(MOD[i + n - x] + 2 * i + 1, i + n - x)) {
mat[i] = x;
del = i;
return true;
}
}
}
if(!fi) {
fi = true;
L(u, 0, 30) {
int i = (x + 4000 + u) % n;
if(!vis[i] && !~mat[i] && gcd(MOD[i + n - x] + 2 * i + 1, i + n - x)) {
vis[i] = true;
arr[++tot] = i;
if(!~mat[i] || dfs(mat[i])) {
return mat[i] = x, true;
}
// matrix casacde.
}
}
L(u, 0, n - 1) {
int i = (x + 4000 + u) % n;
if(!vis[i] && gcd(MOD[i + n - x] + 2 * i + 1, i + n - x)) {
vis[i] = true;
arr[++tot] = i;
if(!~mat[i] || dfs(mat[i])) {
return mat[i] = x, true;
}
// matrix casacde.
}
}
} else {
int i = orz() % n;
L(u, 0, n - 1) {
if(!vis[i] && gcd(MOD[i + n - x] + 2 * i + 1, i + n - x) == 1) {
vis[i] = true;
arr[++tot] = i;
if(!~mat[i] || dfs(mat[i]))
return mat[i] = x, true;
arr[++tot] = i;
// matrix casacde.
}
++i;
if(i >= n) i -= n;
}
}
return false;
}
bool Prime[N], tmp[N];
int prime[N], xtot, ns[N];
ll M = -1;
inline int Get(int md) {
int cur = 0;
for(auto u : xn)
cur = (cur * 10 + u - '0') % md;
return cur;
}
void init() {
if(M != -1) {
L(i, 1, n * 2) MOD[i] = M % (i * 2);
return ;
}
MOD[1] = Get(2);
L(i, 2, n * 2) {
if(!Prime[i]) prime[++xtot] = i, MOD[i] = Get(i * 2);
for(int j = 1; j <= xtot && prime[j] * i <= n * 2; j++) {
Prime[i * prime[j]] = 1;
if(i % prime[j] == 0) {
int x = i, y = prime[j];
while(x % prime[j] == 0) x /= prime[j], y *= prime[j];
if(x == 1) {
MOD[i * prime[j]] = Get(y * 2);
continue;
}
if(y > 350) {
MOD[i * prime[j]] = Get(i * prime[j] * 2);
break;
}
for(int cur = MOD[x]; ; cur += x * 2)
if(cur % (y * 2) == MOD[y]) {
MOD[i * prime[j]] = cur;
break;
}
break;
}
if(prime[j] > 350) {
MOD[i * prime[j]] = Get(i * prime[j] * 2);
continue;
}
for(int cur = MOD[i]; ; cur += i * 2)
if(cur % (prime[j] * 2) == MOD[prime[j]]) {
MOD[i * prime[j]] = cur;
break;
}
}
}
}
int main () {
ios :: sync_with_stdio(false);
cin.tie (0); cout.tie(0);
// xn = "2000000", n = 1e6;
cin >> xn >> n;
fastgcd :: Main();
//
// L(i, 1, n * 2) {
// int md = i * 2, cur = 0;
// for(auto u : xn)
// cur = (cur * 10 + u - '0') % md;
// MOD[i] = cur;
// }
if(sz(xn) <= 10) {
M = 0;
for(auto u : xn)
M = M * 10 + u - '0';
}
init();
L(i, 0, n - 1)
mat[i] = -1;
if(n < 1e5) {
L(i, 0, n - 1) {
fi = 0;
dfs(i);
L(j, 1, tot)
vis[arr[j]] = false;
tot = 0;
}
} else {
const int T = n - 5000;
L(i, 0, T) {
fi = 0;
dfs(i);
L(j, 1, tot)
vis[arr[j]] = false;
tot = 0;
}
L(i, 0, n - 1)
if(mat[i] == -1)
st.emplace_back(i);
L(i, T + 1, n - 1) {
fi = 0;
dfs(i);
L(j, 1, tot) vis[arr[j]] = false;
tot = 0;
st.erase(lower_bound(st.begin(), st.end(), del));
}
}
cout << n << '\n';
L(i, 0, n - 1) {
cout << n - mat[i] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 33ms
memory: 49624kb
input:
527901620 3
output:
3 1 3 2
result:
ok Accepted.
Test #2:
score: 5
Accepted
time: 36ms
memory: 50308kb
input:
423744200 1
output:
1 1
result:
ok Accepted.
Test #3:
score: 5
Accepted
time: 29ms
memory: 49280kb
input:
870873520 8
output:
8 8 7 6 5 4 3 2 1
result:
ok Accepted.
Test #4:
score: 5
Accepted
time: 36ms
memory: 47628kb
input:
796450080 10
output:
10 10 9 1 8 7 6 5 4 3 2
result:
ok Accepted.
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #5:
score: 5
Accepted
time: 45ms
memory: 47916kb
input:
691352244 2
output:
2 2 1
result:
ok Accepted.
Test #6:
score: 5
Accepted
time: 38ms
memory: 45544kb
input:
537735946 4
output:
4 4 3 2 1
result:
ok Accepted.
Test #7:
score: 5
Accepted
time: 37ms
memory: 45576kb
input:
964421466 6
output:
6 6 4 5 1 3 2
result:
ok Accepted.
Test #8:
score: 5
Accepted
time: 31ms
memory: 47616kb
input:
804640404 8
output:
8 8 7 6 5 4 3 2 1
result:
ok Accepted.
Subtask #3:
score: 15
Accepted
Dependency #2:
100%
Accepted
Test #9:
score: 15
Accepted
time: 36ms
memory: 45548kb
input:
815904616 163
output:
163 69 96 153 89 85 84 4 82 81 80 79 78 77 76 75 74 71 128 50 13 143 31 142 93 140 146 98 65 61 60 163 6 57 2 55 54 144 64 51 22 58 48 38 47 30 68 162 42 88 40 39 151 37 36 19 34 141 32 46 158 43 28 26 147 10 24 23 56 21 70 137 72 35 16 15 14 8 12 7 62 9 118 44 18 5 11 3 1 156 59 49 53 66 91 157 27 ...
result:
ok Accepted.
Test #10:
score: 15
Accepted
time: 35ms
memory: 48700kb
input:
261467732 174
output:
174 172 1 171 170 169 168 167 166 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 101 100 102 99...
result:
ok Accepted.
Test #11:
score: 15
Accepted
time: 40ms
memory: 45524kb
input:
170135212 52
output:
52 41 48 14 49 46 45 43 4 42 28 47 38 39 29 36 7 32 5 19 31 30 13 34 27 2 26 23 24 25 21 20 18 12 33 17 15 40 16 11 52 10 8 9 44 6 22 35 3 1 51 50 37
result:
ok Accepted.
Test #12:
score: 15
Accepted
time: 37ms
memory: 49312kb
input:
914972990 139
output:
139 109 36 56 106 76 69 103 102 101 100 45 98 97 96 66 41 93 92 59 90 89 88 34 86 85 84 83 82 3 80 79 63 77 8 75 57 71 10 61 136 107 95 67 81 48 73 99 62 44 19 13 70 129 18 55 60 53 52 51 50 49 24 47 128 23 120 104 42 54 40 39 64 37 68 35 26 4 32 31 33 30 29 27 28 43 25 105 22 87 20 130 21 17 16 6 1...
result:
ok Accepted.
Subtask #4:
score: 10
Accepted
Dependency #3:
100%
Accepted
Test #13:
score: 10
Accepted
time: 36ms
memory: 45728kb
input:
303514006 1401
output:
1401 730 358 497 187 937 789 677 1340 1058 1192 778 1188 1189 1017 317 831 883 1289 473 508 413 703 360 614 592 578 434 601 333 1170 679 431 632 204 17 1307 713 357 336 424 277 1401 622 892 633 426 877 758 378 864 104 952 1182 11 489 1035 1215 791 571 1065 64 1389 1116 49 580 732 418 457 9 727 364 6...
result:
ok Accepted.
Test #14:
score: 10
Accepted
time: 39ms
memory: 48716kb
input:
651391026 1584
output:
1584 150 831 1259 830 829 828 827 825 826 824 618 1548 1065 589 218 819 1294 816 815 814 350 811 733 1148 333 934 404 1305 804 377 1292 1324 1421 891 997 1271 1078 939 1478 130 793 77 263 790 1337 1405 834 35 497 298 1391 56 679 782 1508 4 278 1273 1140 894 773 1150 875 1187 769 1416 768 766 767 120...
result:
ok Accepted.
Test #15:
score: 10
Accepted
time: 40ms
memory: 49308kb
input:
196126306 1766
output:
1766 1447 1613 467 1729 1419 1472 1228 1481 323 1549 116 509 698 1182 5 817 663 1143 1231 400 599 868 103 840 312 428 885 412 1527 888 906 260 975 1092 1420 1253 445 115 582 877 559 1257 958 592 215 714 1649 437 613 1393 1352 913 491 417 1162 1726 242 181 619 1409 1043 1079 1739 253 407 999 84 14 62...
result:
ok Accepted.
Test #16:
score: 10
Accepted
time: 34ms
memory: 49364kb
input:
904263684 1948
output:
1948 1168 103 671 1937 102 101 100 1330 98 97 96 150 94 1867 92 983 90 839 1811 87 86 1430 117 83 82 937 280 79 78 77 1259 75 74 73 72 71 70 426 68 67 1084 1140 64 63 62 61 60 59 58 387 56 55 691 53 51 52 758 804 48 89 46 45 44 1927 42 41 1328 39 38 37 36 35 34 33 1381 31 850 270 28 27 26 1048 1126 ...
result:
ok Accepted.
Subtask #5:
score: 25
Accepted
Test #17:
score: 25
Accepted
time: 104ms
memory: 55904kb
input:
1434450 717225
output:
717225 1 3 2 5 4 6 8 7 9 11 10 12 14 13 15 16 18 17 20 19 21 23 22 24 26 25 27 29 28 30 31 33 32 35 34 36 38 37 39 41 40 42 44 43 45 46 48 47 50 49 51 53 52 54 56 55 57 59 58 60 61 63 62 64 66 65 68 67 69 71 70 72 74 73 75 76 78 77 80 79 81 83 82 84 86 85 87 89 88 90 91 93 92 95 94 96 98 97 99 101 1...
result:
ok Accepted.
Test #18:
score: 25
Accepted
time: 129ms
memory: 57504kb
input:
1666706 833353
output:
833353 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 98 99 100 1...
result:
ok Accepted.
Test #19:
score: 25
Accepted
time: 116ms
memory: 54816kb
input:
1768146 884073
output:
884073 2 1 3 5 4 6 8 7 11 9 10 12 14 13 15 17 16 18 20 19 21 26 22 23 24 25 27 28 31 29 32 30 33 35 34 36 38 37 41 39 40 42 44 43 45 47 46 48 50 49 51 53 52 56 54 55 57 59 58 60 62 61 63 65 64 66 68 67 71 69 70 72 74 73 75 77 76 78 80 79 81 83 82 86 84 85 87 89 88 90 92 91 93 95 94 96 98 97 101 99 1...
result:
ok Accepted.
Test #20:
score: 25
Accepted
time: 98ms
memory: 52020kb
input:
1333926 666963
output:
666963 2 1 3 5 4 7 8 6 11 9 10 12 14 13 15 17 16 18 20 19 21 23 22 26 24 25 28 29 27 30 32 31 33 35 34 36 38 37 41 39 40 42 44 43 45 47 46 49 50 48 51 53 52 56 54 55 57 59 58 60 62 61 63 65 64 66 68 67 69 70 72 71 74 73 75 77 76 78 80 79 81 82 84 86 83 85 87 88 91 89 92 90 93 95 94 96 98 97 101 99 1...
result:
ok Accepted.
Subtask #6:
score: 10
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 10
Accepted
time: 46ms
memory: 45688kb
input:
121768078 34399
output:
34399 1057 25031 23606 27601 27735 29133 14437 3675 31388 4038 14861 2603 34336 13161 21885 1897 3987 26454 24584 30873 710 33217 31871 23286 18508 2958 29058 7603 2841 9198 22783 30234 29750 14643 21439 16506 34201 25773 23868 7217 3965 3638 30836 5218 29522 18937 24036 7409 31954 18382 9657 8989 2...
result:
ok Accepted.
Test #22:
score: 10
Accepted
time: 44ms
memory: 45920kb
input:
567903556 38581
output:
38581 2770 31787 28442 20609 38494 3998 10651 29846 33605 3994 22086 4862 30867 3990 3989 1257 3987 3986 853 3984 3983 31014 3981 3980 3979 5852 3977 36783 153 3974 30423 24609 25946 3970 18503 37313 2803 3697 24465 3964 3091 3962 23492 14773 33309 3958 3957 20706 10155 20333 3953 34826 29855 3950 1...
result:
ok Accepted.
Test #23:
score: 10
Accepted
time: 47ms
memory: 46524kb
input:
414440938 42763
output:
42763 37315 18667 11903 42174 742 35268 4648 1075 21296 30159 21661 34712 29920 3991 13637 15158 3987 3986 3988 3985 3984 33535 3981 28515 3982 16011 9110 3977 8536 26651 4759 30842 31733 39568 42587 3113 29091 31447 10931 7212 37163 19110 29042 24085 3959 35854 39599 14988 27799 7646 3954 28150 224...
result:
ok Accepted.
Test #24:
score: 10
Accepted
time: 55ms
memory: 47796kb
input:
310652458 46946
output:
46946 9351 1893 16338 4984 27830 24675 25723 6110 42330 13521 25152 32049 24687 34650 11067 22269 11554 42575 13221 10242 33753 43825 23227 25118 11788 32803 41222 15648 36743 43457 24110 9665 16521 6073 8700 34022 41416 11000 2135 13459 4360 12266 24094 15829 19149 17509 13545 25749 9225 504 20766 ...
result:
ok Accepted.
Subtask #7:
score: 15
Accepted
Dependency #6:
100%
Accepted
Test #25:
score: 15
Accepted
time: 141ms
memory: 56208kb
input:
385664412 991454
output:
991454 2 1 3 5 4 6 8 7 9 11 10 12 14 13 15 17 16 19 20 18 23 21 22 24 26 25 27 29 28 30 32 31 33 35 34 36 38 39 37 41 40 42 45 43 44 47 46 48 50 49 51 53 52 56 54 55 57 58 60 59 62 61 63 65 64 66 68 67 69 71 70 72 74 73 76 77 75 78 79 81 80 83 82 84 89 85 86 87 88 90 92 91 93 95 94 96 98 97 99 100 1...
result:
ok Accepted.
Test #26:
score: 15
Accepted
time: 57ms
memory: 48780kb
input:
795580394 295636
output:
295636 1 3 4 2 5 6 7 8 10 11 9 12 13 14 15 16 18 17 19 20 21 22 24 25 23 26 27 28 29 30 32 31 33 34 35 36 37 39 38 40 41 42 43 45 46 44 47 48 49 50 51 53 52 54 55 56 57 58 60 59 61 62 63 64 66 67 65 68 69 70 71 72 74 73 75 76 77 78 80 81 79 82 83 84 85 87 88 86 89 90 91 92 93 95 94 96 97 98 99 100 1...
result:
ok Accepted.
Test #27:
score: 15
Accepted
time: 87ms
memory: 51148kb
input:
639325794 599818
output:
599818 2 1 3 5 4 6 8 7 10 11 9 12 14 13 15 17 16 18 20 19 21 23 22 25 26 24 27 29 28 30 32 31 33 35 34 36 38 37 40 41 39 42 44 43 45 46 48 47 50 49 51 53 52 55 56 54 59 57 58 60 62 61 63 65 64 66 68 67 70 71 69 72 74 73 75 77 76 78 80 79 81 83 82 85 86 84 87 89 88 90 92 91 93 95 94 96 98 97 100 101 ...
result:
ok Accepted.
Test #28:
score: 15
Accepted
time: 117ms
memory: 55068kb
input:
514552014 904000
output:
904000 2 1 3 5 4 6 8 7 10 11 9 12 14 13 15 17 16 19 20 18 21 23 22 25 26 24 27 29 28 30 32 31 33 35 34 36 38 37 40 41 39 42 44 43 45 47 46 48 50 49 51 53 52 55 56 54 57 59 58 60 62 61 63 65 64 66 68 67 70 71 69 72 74 73 76 77 75 78 80 79 81 83 82 85 86 84 87 89 88 90 92 91 93 95 94 96 98 97 100 101 ...
result:
ok Accepted.
Subtask #8:
score: 15
Accepted
Dependency #5:
100%
Accepted
Dependency #7:
100%
Accepted
Test #29:
score: 15
Accepted
time: 89ms
memory: 46500kb
input:
4043938008620250853548463463670539178824136101118676039998249773600296234199890542107734673644890238 182956
output:
182956 1 2 3 4 5 6 7 9 8 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 25 27 28 29 30 31 32 33 34 35 36 37 38 39 40 43 41 42 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 59 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 77 76 78 79 80 81 82 83 84 85 86 87 88 89 90 91 94 92 93 95 96 97 98 99 100 1...
result:
ok Accepted.
Test #30:
score: 15
Accepted
time: 164ms
memory: 49060kb
input:
6809505726107869121835226914314324742765939751165985001014682212595145094113574992502730535886215434 358074
output:
358074 2 1 3 5 4 6 8 7 10 11 9 12 14 13 15 17 16 18 20 19 23 21 22 25 26 24 27 29 28 30 32 31 33 35 36 34 38 37 40 41 39 42 44 43 45 47 46 48 50 49 51 53 52 56 55 54 57 59 58 60 62 61 63 65 64 66 68 67 70 71 69 72 74 73 75 78 76 77 80 79 81 83 82 85 89 84 86 87 88 90 92 91 93 95 94 96 97 100 98 101 ...
result:
ok Accepted.
Test #31:
score: 15
Accepted
time: 248ms
memory: 58812kb
input:
2263258607536236028437491678008 1000000
output:
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 98 99 100 ...
result:
ok Accepted.
Test #32:
score: 15
Accepted
time: 256ms
memory: 58756kb
input:
36212137720579776454999866846484 1000000
output:
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 98 99 100 ...
result:
ok Accepted.