QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#8994 | #1220. 屠龙勇士 | Qingyu | 100 ✓ | 371ms | 10880kb | C++17 | 2.5kb | 2021-04-06 21:48:39 | 2021-12-19 11:21:50 |
Judging History
answer
#include <algorithm>
#include <cstdio>
#include <set>
typedef long long ll;
inline int read()
{
char c = getchar();
int x = 0, ft = 1;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-')
ft = -1;
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return x * ft;
}
inline ll ll_read()
{
char c = getchar();
ll x = 0, ft = 1;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-')
ft = -1;
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return x * ft;
}
const int N = 1e5 + 5;
int n, q;
ll a[N], b[N], m[N], r[N];
std::multiset<ll> atk;
std::multiset<ll> :: iterator it;
inline void exgcd(ll a, ll b, ll &x, ll &y, ll &d)
{
if (!b)
{
x = 1;
y = 0;
d = a;
return;
}
exgcd(b, a % b, y, x, d);
y -= (a / b) * x;
}
inline ll mul(ll a, ll b, ll mod)
{
ll tmp = (long double)a * b / mod;
return ((a * b - tmp * mod) % mod + mod) % mod;
}
inline ll excrt()
{
ll A, B, C, x, y, d, lcm = 1, ans = 0;
for (int i = 1; i <= n; ++i)
{
A = a[i] * lcm;
B = m[i];
C = (b[i] + m[i] - a[i] * ans % m[i]) % m[i];
exgcd(A, B, x, y, d);
if (C % d)
return -1;
x = mul(x, C / d, B / d);
ans += x * lcm;
lcm *= B / d;
ans = (ans % lcm + lcm) % lcm;
}
return ans;
}
inline bool check_p()
{
for (int i = 1; i <= n; ++i)
if (m[i] != 1)
return 0;
return 1;
}
inline ll work()
{
ll ans = 0;
for (int i = 1; i <= n; ++i)
{
ans = std::max(ans, (b[i] + a[i] - 1) / a[i]);
}
return ans;
}
inline void solve()
{
n = read();
q = read();
atk.clear();
for (int i = 1; i <= n; ++i)
b[i] = ll_read();
for (int i = 1; i <= n; ++i)
m[i] = ll_read();
for (int i = 1; i <= n; ++i)
r[i] = ll_read();
for (int i = 1; i <= q; ++i)
atk.insert(ll_read());
for (int i = 1; i <= n; ++i)
{
it = atk.upper_bound(b[i]);
if (it != atk.begin())
--it;
a[i] = (*it);
atk.erase(it);
atk.insert(r[i]);
}
printf("%lld\n", check_p() ? work() : excrt());
}
int main()
{
int cases = read();
while (cases--)
solve();
fclose(stdin);
fclose(stdout);
return 0;
}
详细
Test #1:
score: 5
Accepted
time: 40ms
memory: 6264kb
input:
5 100000 1 5189 4056 5605 4954 20 3670 5827 1196 5570 1803 6355 1957 2366 564 5137 192 6416 1596 764 4879 1673 6462 390 5763 5999 3382 702 6341 5282 6201 5463 6411 5122 2979 4286 1451 6508 311 4628 5933 4116 1745 45 3694 5272 4101 5294 1611 821 2035 1599 1414 296 4431 4933 4287 6262 3779 5353 5596 3476 1478 1740 2156 4771 5236 4683 5587 3804 976 2557 121 6251 1661 5748 6400 363 1030 2719 1217 2416 6455 1304 4893 6108 3439 1659 657 5670 1913 2015 3080 5260 6223 4762 4496 84 5332 1933 5272 6277 56...
output:
6655 6509 5621 4755 4079
result:
ok 5 lines
Test #2:
score: 5
Accepted
time: 47ms
memory: 6184kb
input:
5 100000 1 771 11 1127 1381 4565 3880 3730 6201 7607 5645 7942 6411 2741 1721 5341 6739 1445 7601 579 2433 6232 3935 4730 2518 3889 1707 1196 3948 2431 5178 6543 2961 3813 7139 280 438 5315 4994 5622 3082 1855 1334 4069 6974 7626 7290 4934 4958 6344 6596 153 2708 8029 6789 624 3356 5981 1727 726 3232 2329 7312 5273 6569 7243 5755 8028 3398 4948 6941 1072 7099 7005 7386 696 5890 6123 6848 7583 985 175 6979 5197 6651 2225 7915 6073 2039 6442 6466 7857 4321 2776 1073 7971 2453 157 2008 3403 8089 37...
output:
8140 7924 6731 5644 5463
result:
ok 5 lines
Test #3:
score: 5
Accepted
time: 63ms
memory: 6288kb
input:
5 100000 1 493 547 1923 5289 1006 341 2786 315 3357 3905 2187 3529 7861 3852 7751 5330 3003 1320 2049 1769 2065 5678 425 3293 1921 434 7410 5492 2687 4759 7529 5853 4350 3554 5596 7502 2535 1855 7260 1948 7719 2367 4788 4347 7930 6194 1033 615 7450 4746 2562 6409 4394 341 576 796 5281 3129 2988 1188 6396 7237 4161 7284 6758 1332 5585 1663 3502 6945 177 2183 4686 8032 398 5597 214 2114 146 461 2592 2679 1363 5595 5323 2189 4315 306 2861 6756 1845 955 3143 1625 5197 4549 7884 7947 1537 6719 264 52...
output:
5009 5461 3033 5584 3170
result:
ok 5 lines
Test #4:
score: 5
Accepted
time: 52ms
memory: 6188kb
input:
5 100000 1 341 1121 104 130 2088 8832 6172 5005 1743 2892 5685 4108 621 4286 1826 4856 8645 5918 5353 3976 7664 8032 266 788 4969 195 2953 8840 4564 3552 2174 6051 4762 5799 8135 3085 8879 5896 5222 7090 7801 1800 4462 8307 7108 1736 6739 2336 3693 7101 6971 3265 2754 8451 1803 1480 2613 5145 570 4680 4137 1235 4514 3978 603 7857 4720 4550 5223 291 1663 5855 2235 1544 2675 4656 6130 8146 6179 8337 3143 4344 5033 7068 6651 610 1479 564 4997 3958 997 7072 2078 251 1382 6937 8168 1961 3115 2105 247...
output:
2899 2134 4879 4066 1754
result:
ok 5 lines
Test #5:
score: 5
Accepted
time: 4ms
memory: 3196kb
input:
5 1000 1000 4 25 4 23076 13786 8288 37280 72 27396 28288 16 4 7 48 2284 29024 104 12 29 12 28 3928 48364 7270 7 17804 112 5 40 6952 4340 8754 30448 54848 80 2247 12 5 2404 8401 2 60 11348 6152 164 11886 204 1780 34 5328 411 220 20 38 10544 15 51660 2756 41324 56 36 96 30262 4012 18882 30 20 340 8 8 2 5 11020 12 32 4 26064 5342 4 43960 17680 20 2331 186 8 24 2034 5298 12 923 2494 18300 2 18229 22408 204 4 16 152 208 12 52 4514 9140 15072 2720 29364 4428 1 4340 24312 20 108 252 67872 4 5176 4404 7...
output:
761092 842372 922557 931619 861853
result:
ok 5 lines
Test #6:
score: 5
Accepted
time: 4ms
memory: 5116kb
input:
5 1000 1000 6 11469 6 318 4546 60148 66 3455 4389 9 138 12 15615 27 959 35 326 58 5025 6957 9 137 546 27 995 54462 4530 3858 4536 10641 60 7581 81 5748 10720 19764 19318 54 4 2124 2733 2080 9192 24850 9 2 250 21 75 51 2329 105 520 117 100 48 10 4 75 24507 10689 81 35 18559 177 845 18 3 63 163 1056 1122 10359 81 11843 5 15390 129 17967 60 92 29 5 866 15 9 788 6 50 12 7790 2928 1720 1810 10 25137 60 123 9282 417 20488 7272 78 16806 2909 168 78 3 12 2829 3 9 8109 15 2163 1566 1918 15847 8348 6 4529...
output:
740067 875101 794460 872933 760438
result:
ok 5 lines
Test #7:
score: 5
Accepted
time: 4ms
memory: 5108kb
input:
5 1000 1000 8 44 2 88 3 3 4426 3 10 42744 3626 52 11914 142 4 20 60 14688 28040 17944 22012 2 92 40 18 6 57364 36788 232 12 132 56 17 10026 3824 3 3940 4812 26680 15484 10 17612 8 50808 73 88 16 28 8 3952 26844 1 90 16 9 64 2 16861 6392 53832 40 12586 3 8 5474 9004 6 1890 1 34724 4 30 26 5592 10 2012 8 15139 2 17400 144 186 202 34 10 4 18 3594 182 3228 2 26 18716 28 18442 4236 8 264 21976 40944 28 80 4206 24 12 13804 1972 23570 12 14138 460 21924 64 260 88 4 57952 10 32038 6 3730 66 32 4813 2 71...
output:
794396 776944 763888 875015 781872
result:
ok 5 lines
Test #8:
score: 5
Accepted
time: 2ms
memory: 5068kb
input:
5 1 1 1249378 99048079 1 801642 1 1 70666110 99056313 1 458586 1 1 61157145 81882641 1 647668 1 1 23532264 78789408 1 170372 1 1 59274385 99984865 1 829644
output:
72463170 6894995 50845317 18971898 82562630
result:
ok 5 lines
Test #9:
score: 5
Accepted
time: 2ms
memory: 3044kb
input:
5 1 1 17904094 99092902 1 119681 1 1 36484496 99896398 1 746110 1 1 4765223 87751171 1 629031 1 1 85241526 91041504 1 131107 1 1 45056037 99090357 1 177585
output:
20567054 14053507 43267852 13220754 30387740
result:
ok 5 lines
Test #10:
score: 5
Accepted
time: 0ms
memory: 3124kb
input:
5 1 1 49632512 99539840 1 886346 1 1 78328552 99820417 1 668799 1 1 26055638 86199301 1 531042 1 1 8968967 84287712 1 410909 1 1 26587288 99182928 1 602251
output:
43220992 98593971 51603213 51143635 3374152
result:
ok 5 lines
Test #11:
score: 5
Accepted
time: 1ms
memory: 2996kb
input:
5 1 1 73431777 99936884 1 570581 1 1 34612234 99831691 1 599139 1 1 34198644 80394179 1 218704 1 1 13500288 76801056 1 211116 1 1 42573845 99926689 1 828565
output:
13437761 33613038 50123742 5454672 26358849
result:
ok 5 lines
Test #12:
score: 5
Accepted
time: 2ms
memory: 3156kb
input:
5 1 1 75853293 99036838 1 428047 1 1 7818163 99350536 1 832005 1 1 40845420 97951681 1 255701 1 1 55215650 83068896 1 181207 1 1 21544076 99859384 1 371731
output:
67405855 32067471 46323807 77922062 87390820
result:
ok 5 lines
Test #13:
score: 5
Accepted
time: 0ms
memory: 3140kb
input:
5 1 1 72407888 99647008 1 964632 1 1 78775996 99166064 1 306638 1 1 49010001 97268177 1 267265 1 1 50714172 85565856 1 39309 1 1 72777420 99864180 1 389910
output:
6282814 30695562 71900715 14407020 1991016
result:
ok 5 lines
Test #14:
score: 5
Accepted
time: 371ms
memory: 10852kb
input:
5 100000 100000 77177366 46762434 47354301 18368057 59540793 34115484 38055445 737866 18944147 61262888 65574806 23550314 57144755 78088985 56200734 75632874 45029080 41326111 7224753 13831837 20650404 64453296 47812189 38675074 46280317 49435169 20773297 46171668 71873403 30447076 47571002 3981511 69419511 40441567 32029768 59606198 73919880 31590691 28686013 45610375 34559272 66749228 55774579 23226731 63139302 60491660 13640081 28897404 48785665 4731685 55780446 39227695 43936951 47840936 122...
output:
181 161 158 176 162
result:
ok 5 lines
Test #15:
score: 5
Accepted
time: 354ms
memory: 10876kb
input:
5 100000 100000 50325083 18321821 55084357 3471965 62354431 14101368 65254206 59663617 6785760 70220146 21301482 13915186 43043389 69904779 28091958 31473896 2272617 40260359 10692290 58122569 44894092 1825080 22946243 23335890 27462801 25534699 66592843 54511734 31970494 53631305 21925922 53845809 66284348 64318332 29110135 36509971 10702206 9659100 36499509 53923269 66603336 50923424 39209725 55207591 10930754 66642506 32991611 62146713 58314797 65174217 43784426 49461312 49475116 69108412 572...
output:
181 193 159 173 200
result:
ok 5 lines
Test #16:
score: 5
Accepted
time: 298ms
memory: 10876kb
input:
5 100000 100000 62 37336765 30242768 16926534 12729548 34 5044532 53 52 31926885 51 7 18677176 53 35 52240432 40 71722056 10949849 17 71 53922450 47 21 42 68 45650718 60284379 34388567 36112626 78 46259414 66 78 63 20 62 70062423 30661432 78 5765385 48 14 38832027 7 46219457 10207923 34298465 68289561 46407135 41 37490191 50 43 58780361 73861593 78 59400242 56173042 14 45895108 51 64449092 30720393 41 26195827 30883722 62107446 68 65742290 56866285 54 21 76 73203959 70630120 70 54 33 22841979 40...
output:
487472861809 3871865111 7560798679 584853762636 670310334583
result:
ok 5 lines
Test #17:
score: 5
Accepted
time: 306ms
memory: 10796kb
input:
5 100000 100000 63 6872184 73048870 80080294 63 67363090 71 92 72 77924665 49 76 33 43653093 53 42 42505538 39442903 11214653 81 62242278 84 14308712 76804923 70 50523588 57 36 12632269 82 86 64 72 22203825 76 37233555 28443111 68983684 1268788 57 71 35 59398333 69173709 63 4672396 6848195 76 19062001 35717853 58626994 5638634 81 46276664 62109583 40 64078377 59070511 59 53 55086436 1814215 92 71 59983040 50145673 90 31594282 95 79615958 27773890 81 45398323 84 61508520 72 16332062 1580244 80896...
output:
600797388119 566101514493 587540018 634174803650 552280363387
result:
ok 5 lines
Test #18:
score: 5
Accepted
time: 347ms
memory: 10828kb
input:
5 100000 100000 13267728397 6930065080 11822984059 5 13333680640 13 195 12259373581 1 70 140 42889654017 40756370655 20 10 10518012100 100 20 12 70 22829869610 17786404294 65 4667265343 25 123386330555 1 90 2 2357519480 10 30 848253425 1 1701531557 233151675015 104107358000 11609750778 17930936247 189686717810 1080879204 23735533060 163381223748 50 4941979237 410977608 12922127405 14 40 5 9805455695 52447994285 66154078115 3603988703 10 8 60 78 134 32 39362054135 6251616060 2 261185385920 100874...
output:
824449922225 751730822926 891096169450 963861894691 902706051916
result:
ok 5 lines
Test #19:
score: 5
Accepted
time: 327ms
memory: 10880kb
input:
5 100000 100000 76 16523038041 38270908511 3277440779 55 68159829433 2 4 306648451 5166718818 3 4 2 35 5 81 31372053306 21 76123260264 9 11 145816805177 14 17 5 4 44840038075 4175916625 3 24 1903150201 28935559998 12274698105 32 10261508810 173638357 60544742197 259671060305 64 20757163417 14 2 2 1410519867 36 93623267276 3 156695203858 5579484972 90209617643 592 1114241002 16 7 1686241389 100 25 49794096073 58 24942060955 188 2 17 56 161 142461244 91299918861 6821994338 10 36650054045 253485420...
output:
795995657507 748640976198 920397318025 822349094004 799930587126
result:
ok 5 lines
Test #20:
score: 5
Accepted
time: 332ms
memory: 10800kb
input:
5 100000 100000 275 90 36 8372954616 5731965129 15 144806129205 8571465015 8588056782 45 9164768770 5 25 2609058267 3276662820 270 20 86137617585 9 14484074790 3 55 345 9746540895 50421333448 3 1226440407 360 5 6 10 15527522832 4363886307 1201478170 212159120 1504099884 45 90 15 360 420 63832205850 1963350950 2482452000 15 9 2 66 2440864265 42974178924 8685112113 30 180469005955 25 4392380148 13169492290 15 3 8627595400 18 5 6 4742839620 26336895219 1 24049361520 6 270 5317846428 257270259310 32...
output:
827477774355 809494382833 785779359157 798956553961 880255400578
result:
ok 5 lines
Extra Test:
score: 0
Extra Test Passed