QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#239345 | #7520. Monster Generator | zhaohaikun | WA | 0ms | 3716kb | C++14 | 5.1kb | 2023-11-04 20:12:39 | 2023-11-04 20:12:40 |
Judging History
answer
// MagicDark
#include <bits/stdc++.h>
#define int long long
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> inline void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
const int N = 110;
int n, m;//, a[N], aa[N], b[N], bb[N];
struct Node {
int a, aa, b, bb;//, id;
} a[N];
int t[N * N * 10], tot;
struct T {
int k, b;
} e[N];
int q[N];
ull ans;
void calc(T x, int l, int r) {
// assert(l <= r);
// debug << x.k << " " << x.b << " " << l << " " << r << endl;
ans += (ull) x.b * (r - l + 1);
ans += (ull) x.k * (ull) ((__int128) (l + r) * (r - l + 1) / 2);
}
signed main() {
read(n), read(m);
F(i, 1, n) {
// read(a[i]), read(aa[i]), read(b[i]), read(bb[i]);
read(a[i].a), read(a[i].aa), read(a[i].b), read(a[i].bb);
// if (a[i].aa != a[i].bb) {
if (a[i].a <= a[i].b) {
if (a[i].aa > a[i].bb) {
t[++tot] = (a[i].b - a[i].a) / (a[i].aa - a[i].bb) + 1;
}
} else {
if (a[i].aa < a[i].bb) t[++tot] = (a[i].a - a[i].b - 1) / (a[i].bb - a[i].aa) + 1;
}
// }
// int w = a[i].bb - a[i].aa;
}
sort(a + 1, a + n + 1, [&] (Node x, Node y) {
if (x.b == y.b) return x.bb < y.bb;
return x.b > y.b;
});
F(i, 1, n)
F(j, i + 1, n) {
int A = a[i].b, B = a[j].b;
int AA = a[i].bb, BB = a[j].bb;
// int A = a[i].b - a[i].a, B = a[j].b - a[j].a;
// int AA = a[i].bb - a[i].aa, BB = a[j].bb - a[j].aa;
// if (A > B) {
if (AA < BB) {
F(tmp, -2, 2) t[++tot] = (A - B - 1) / (BB - AA) + tmp;
}
// }
}
sort(a + 1, a + n + 1, [&] (Node x, Node y) {
if (x.a == y.a) return x.aa < y.aa;
return x.a < y.a;
});
// F(i, 1, tot) cout << t[i] << endl;
F(i, 1, n)
F(j, i + 1, n) {
int A = a[i].a, B = a[j].a;
int AA = a[i].aa, BB = a[j].aa;
// int A = a[i].b - a[i].a, B = a[j].b - a[j].a;
// int AA = a[i].bb - a[i].aa, BB = a[j].bb - a[j].aa;
// if (A > B) {
if (AA > BB) {
// debug << B - A << " " << endl;
F(tmp, -2, 2) t[++tot] = (B - A - 1) / (AA - BB) + tmp;
}
// }
}
// F(i, 0, 10) t[++tot] = i;
t[++tot] = m;
// F(i, 1, m) t[++tot] = i;
// t[++tot] = m;
// t[++tot] = 1;
// t[++tot] = 2;
// t[++tot] = 3;
// F(i, 1, tot) cout << t[i] << endl;
t[++tot] = 0;
t[++tot] = m + 1;
// t[++tot] = m;
sort(t + 1, t + tot + 1);
F(i, 1, tot) {
if (t[i] > m) break;
if (t[i] == t[i + 1]) continue;
// assert(t[i] >= 0);
if (t[i] < 0) continue;
// debug << t[i] << " " << t[i + 1] << endl;
sort(a + 1, a + n + 1, [&] (Node x, Node y) {
int A1 = x.aa * t[i] + x.a;
int B1 = x.bb * t[i] + x.b;
int A2 = y.aa * t[i] + y.a;
int B2 = y.bb * t[i] + y.b;
// debug << A1 << " " << B1 << " " << A2 << " " << B2 << endl;
if ((B1 - A1 >= 0) != (B2 - A2 >= 0)) return (B1 - A1 >= 0) > (B2 - A2 >= 0);
if (B1 - A1 >= 0) return A1 < A2;
return B1 > B2;
// return x.b - x.a > y.b - y.a;
});
// F(j, 1, n) cout << a[j].a << " " << a[j].aa << " " << a[j].b << " " << a[j].bb << " " << a[j].aa * t[i] + a[j].a << " " << a[j].bb * t[i] + a[j].b << endl; cout << endl;
int k = 0, b = 0;
e[0] = {0, 0};
F(j, 1, n) {
k += a[j].aa;
b += a[j].a;
// debug << k << " " << b << endl;
e[j] = {k, b};
k -= a[j].bb;
b -= a[j].b;
}
sort(e, e + n + 1, [&] (T x, T y) {
if (x.k == y.k) return x.b > y.b;
return x.k < y.k;
});
q[0] = 0;
F(j, 0, n) {
if (j && e[j].k == e[j - 1].k) continue;
// while (q[0] >= 1 && e[j].b >= e[q[q[0]]].b) q[0]--;
// if (j) debug << e[j].k << " " << e[j - 1].k << endl;
while (q[0] >= 2 && (__int128) (e[j].b - e[q[q[0]]].b) * (e[q[q[0]]].k - e[q[q[0] - 1]].k) > (__int128) (e[q[q[0]]].b - e[q[q[0] - 1]].b) * (e[j].k - e[q[q[0]]].k)) q[0]--;
q[++q[0]] = j;
}
// F(j, 1, q[0]) debug << q[j] << " " << e[q[j]].k << " " << e[q[j]].b << endl;
int pos = t[i];
F(j, 1, q[0]) {
// debug << pos << endl;
if (j != q[0]) {
int w = min(t[i + 1] - 1, (e[q[j]].b - e[q[j + 1]].b + e[q[j + 1]].k - e[q[j]].k) / (e[q[j + 1]].k - e[q[j]].k) - 1);
// debug << w << endl;
if (w < pos) continue;
calc(e[q[j]], pos, w);
if (w == t[i + 1] - 1) break;
pos = w + 1;
// int l = pos - 1, r = t[i] + 1;
// while (l + 1 < r) {
// int mid = (l + r) >> 1;
// if ((__int128) (e[q[j + 1]].k * ))
// }
} else {
calc(e[q[j]], pos, t[i + 1] - 1);
}
}
// debug << ans << endl;
// debug << t[i] << " " << t[i + 1] - 1 << " " << ans << endl;
// return 0;
}
cout << ans;
return 0;
}
/* why?
3 5
1 1 5 4
5 0 4 3
1 4 3 4
2 1
5 1 7 1
10 1 9 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
3 5 3 1 5 2 4 2 1 3 1 9 100 1
output:
113
result:
ok single line: '113'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
3 100000000 3 1 5 2 4 2 1 3 1 9 100 1
output:
35000000549999998
result:
ok single line: '35000000549999998'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
10 1000000000000000000 776874380544333 197 471391764744275 33 159838820333814 107 677112662750393 41 962335658276824 48 255593531071176 11 127404116579775 209 268525254990127 34 647620110614714 76 897947476313307 13 146196843402516 221 772928712898807 39 637929916804442 2 716937021892338 15 64200226...
output:
17883317185357051350
result:
ok single line: '17883317185357051350'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
10 1000000000000 519946 5 967590 4 367668 9 772494 6 635694 5 932710 1 260259 2 627580 1 84994 3 52124 6 447095 4 705749 6 427312 2 977458 7 540121 1 292993 5 556831 6 321679 4 567919 4 609512 4
output:
1542003553318518337
result:
ok single line: '1542003553318518337'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
10 1000000000000000000 972703917532605 2 524956306619424 679 644953227221677 4 562488807303931 696 726248880302017 2 678581164692315 811 63290732871341 4 2359762326353 451 355584232678496 3 295959529542702 895 982076563374348 4 315626935294595 161 202583559712801 1 987516708328993 170 26590404960673...
output:
4582284981606185217
result:
ok single line: '4582284981606185217'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3712kb
input:
10 1000000000000000000 915236950983 25 924829121702 314 142125786492 33 125091250839 71 702305171043 11 468800042449 438 449646370235 9 56198959092 472 246955215365 12 950417123809 62 646952653060 4 858914642874 441 693754630072 34 490226765023 91 273330383457 25 749838451697 371 635897703553 24 847...
output:
6858188868332459867
result:
wrong answer 1st lines differ - expected: '18304932886689493500', found: '6858188868332459867'