QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#237047#7520. Monster GeneratorzhaohaikunWA 0ms3700kbC++144.0kb2023-11-04 12:51:212023-11-04 17:11:54

Judging History

你现在查看的是测评时间为 2023-11-04 17:11:54 的历史记录

  • [2023-11-04 18:37:34]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:0ms
  • 内存:3708kb
  • [2023-11-04 17:11:54]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:0ms
  • 内存:3700kb
  • [2023-11-04 12:51:22]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3700kb
  • [2023-11-04 12:51:21]
  • 提交

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 > 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) {
				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?
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3700kb

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: 3616kb

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: 3556kb

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: -100
Wrong Answer
time: 0ms
memory: 3692kb

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:

1542003553990731211

result:

wrong answer 1st lines differ - expected: '1542003553318518337', found: '1542003553990731211'