QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#237045 | #7520. Monster Generator | zhaohaikun | RE | 0ms | 3704kb | C++14 | 4.0kb | 2023-11-04 12:47:38 | 2023-11-04 12:47:38 |
Judging History
你现在查看的是测评时间为 2023-11-04 12:47:38 的历史记录
- [2023-11-04 16:34:13]
- hack成功,自动添加数据
- (//qoj.ac/hack/422)
- [2023-11-04 16:28:16]
- hack成功,自动添加数据
- (//qoj.ac/hack/420)
- [2023-11-04 12:47:38]
- 提交
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) {
// 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 - 1) / (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) {
return x.b - x.a > y.b - y.a;
});
F(i, 1, n)
F(j, i + 1, n) {
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) {
t[++tot] = (A - B - 1) / (BB - AA) + 1;
}
// }
}
F(i, 1, m) t[++tot] = i;
t[++tot] = 1;
t[++tot] = 2;
// F(i, 1, tot) cout << t[i] << endl;
t[++tot] = 0;
t[++tot] = m + 1;
sort(t + 1, t + tot + 1);
F(i, 1, tot) {
if (t[i] > m) break;
if (t[i] == t[i + 1]) continue;
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;
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;
});
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;
// 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 << t[i] << " " << t[i + 1] - 1 << " " << ans << endl;
// return 0;
}
cout << ans;
return 0;
}
/* why?
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3704kb
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: -100
Runtime Error
input:
3 100000000 3 1 5 2 4 2 1 3 1 9 100 1