0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:05:26 +00:00

P4774 [NOI2018] 屠龙勇士

https://www.luogu.com.cn/record/77141202
This commit is contained in:
Baoshuo Ren 2022-06-09 16:38:48 +08:00
parent a858672529
commit bcd385b829
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
41 changed files with 217 additions and 0 deletions

97
Luogu/P4774/P4774.cpp Normal file
View File

@ -0,0 +1,97 @@
#include <iostream>
#include <set>
#include <tuple>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e5 + 5;
int t, n, m;
long long max;
std::tuple<long long, long long, int, int> dragon[N];
std::multiset<long long> set;
long long exgcd(long long a, long long b, long long& x, long long& y) {
if (!b) {
x = 1, y = 0;
return a;
}
long long g = exgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
long long excrt() {
long long res = 0, lcm = 1;
for (int i = 1; i <= n; i++) {
long long a = (__int128)(std::get<3>(dragon[i])) * lcm % std::get<1>(dragon[i]),
b = std::get<1>(dragon[i]),
c = (__int128)(std::get<0>(dragon[i]) - std::get<3>(dragon[i]) * res % b + b) % b,
x, y;
long long g = exgcd(a, b, x, y);
x = (x % b + b) % b;
if (c % g) return -1;
res += (__int128)(c / g) * x % (b / g) * lcm % (lcm * (b / g));
lcm *= b / g;
res %= lcm;
}
if (res < max) res += ((max - res - 1) / lcm + 1) * lcm;
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> t;
while (t--) {
max = 0;
set.clear();
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> std::get<0>(dragon[i]);
}
for (int i = 1; i <= n; i++) {
cin >> std::get<1>(dragon[i]);
}
for (int i = 1; i <= n; i++) {
cin >> std::get<2>(dragon[i]);
}
for (int i = 1, x; i <= m; i++) {
cin >> x;
set.insert(x);
}
for (int i = 1; i <= n; i++) {
auto it = set.upper_bound(std::get<0>(dragon[i]));
if (it != set.begin()) it--;
std::get<3>(dragon[i]) = *it;
set.insert(std::get<2>(dragon[i]));
max = std::max(max, (std::get<0>(dragon[i]) - 1) / *it + 1);
set.erase(it);
}
cout << excrt() << endl;
}
return 0;
}

BIN
Luogu/P4774/data/P4774_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Luogu/P4774/data/P4774_9.out (Stored with Git LFS) Normal file

Binary file not shown.