mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 20:48:48 +00:00
parent
8b0fc1f975
commit
a858672529
94
LibreOJ/2721/2721.cpp
Normal file
94
LibreOJ/2721/2721.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#include <fstream>
|
||||||
|
#include <set>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
|
std::ifstream cin("dragon.in");
|
||||||
|
std::ofstream cout("dragon.out");
|
||||||
|
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 = std::get<3>(dragon[i]) * lcm % std::get<1>(dragon[i]),
|
||||||
|
b = std::get<1>(dragon[i]),
|
||||||
|
c = (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() {
|
||||||
|
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
LibreOJ/2721/data/dragon1.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon1.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon10.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon10.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon11.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon11.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon11.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon12.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon12.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon12.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon13.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon13.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon13.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon14.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon14.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon14.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon15.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon15.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon15.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon16.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon16.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon16.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon17.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon17.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon17.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon18.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon18.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon18.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon19.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon19.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon19.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon2.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon2.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon20.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon20.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon20.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon3.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon3.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon4.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon4.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon5.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon5.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon6.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon6.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon6.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon7.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon7.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon7.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon8.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon8.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon8.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon9.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon9.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2721/data/dragon9.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2721/data/dragon9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user