QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#236909#7520. Monster GeneratorkyEEccccccWA 18ms3652kbC++143.8kb2023-11-04 11:30:452023-11-04 11:30:46

Judging History

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

  • [2023-11-04 18:37:30]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:23ms
  • 内存:3740kb
  • [2023-11-04 17:11:50]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:18ms
  • 内存:3836kb
  • [2023-11-04 11:30:46]
  • 评测
  • 测评结果:0
  • 用时:18ms
  • 内存:3652kb
  • [2023-11-04 11:30:45]
  • 提交

answer

// Author: kyEEcccccc

#include <bits/stdc++.h>

using namespace std;

using LL = long long;
using ULL = unsigned long long;

#define F(i, l, r) for (int i = (l); i <= (r); ++i)
#define FF(i, r, l) for (int i = (r); i >= (l); --i)
#define MAX(a, b) ((a) = max(a, b))
#define MIN(a, b) ((a) = min(a, b))
#define SZ(a) ((int)((a).size()) - 1)

constexpr int N = 105;

int n;
LL m, a[N], aa[N], b[N], bb[N];
int ord[N];
array<LL, 2> pts[N];

signed main(void)
{
	// freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(nullptr);

	cin >> n >> m;
	F(i, 1, n) cin >> a[i] >> aa[i] >> b[i] >> bb[i];
	vector<LL> ti{0, m + 1};
	F(i, 1, n)
	{
		if (a[i] <= b[i] && aa[i] > bb[i])
		{
			ti.push_back((b[i] - a[i]) / (aa[i] - bb[i]) + 1);
		}
		if (a[i] > b[i] && aa[i] < bb[i])
		{
			ti.push_back((a[i] - b[i] + bb[i] - aa[i] - 1) / (bb[i] - aa[i]));
		}
		F(j, 1, i - 1)
		{
			if (a[i] >= a[j] && aa[j] > aa[i])
			{
				ti.push_back((a[i] - a[j]) / (aa[j] - aa[i]) + 1);
			}
			if (a[i] < a[j] && aa[j] < aa[i])
			{
				ti.push_back((a[j] - a[i] + aa[i] - aa[j] - 1) / (aa[i] - aa[j]));
			}
			if (b[i] >= b[j] && bb[j] > bb[i])
			{
				ti.push_back((b[i] - b[j]) / (bb[j] - bb[i]) + 1);
			}
			if (b[i] < b[j] && bb[j] < bb[i])
			{
				ti.push_back((b[j] - b[i] + bb[i] - bb[j] - 1) / (bb[i] - bb[j]));
			}
		}
	}
	sort(ti.begin(), ti.end());
	ti.resize(unique(ti.begin(), ti.end()) - ti.begin());
	while (ti.back() > m + 1) ti.pop_back();
	ULL ans = 0;
	F(_, 0, SZ(ti) - 1)
	{
		LL bg = ti[_], ed = ti[_ + 1];
		iota(ord + 1, ord + n + 1, 1);
		sort(ord + 1, ord + n + 1, [bg] (int x, int y)
		{
			if (a[x] + (__int128)aa[x] * bg <= b[x] + (__int128)bb[x] * bg)
			{
				if (a[y] + (__int128)aa[y] * bg <= b[y] + (__int128)bb[y] * bg)
				{
					if (a[x] + (__int128)aa[x] * bg == a[y] + (__int128)aa[y] * bg)
					{
						return x < y;
					}
					return a[x] + (__int128)aa[x] * bg < a[y] + (__int128)aa[y] * bg;
				}
				else
				{
					return true;
				}
			}
			else
			{
				if (a[y] + (__int128)aa[y] * bg <= b[y] + (__int128)bb[y] * bg)
				{
					return false;
				}
				else
				{
					if (b[x] + (__int128)bb[x] * bg == b[y] + (__int128)bb[y] * bg)
					{
						return x > y;
					}
					return b[x] + (__int128)bb[x] * bg > b[y] + (__int128)bb[y] * bg;
				}
			}
		});

		ULL res = 0;
		LL cval = 0, ck = 0;
		F(ii, 1, n)
		{
			int i = ord[ii];
			pts[ii] = {-(ck - aa[i]), cval - a[i]};
			cval = cval - a[i] + b[i];
			ck = ck - aa[i] + bb[i];
		}
		sort(pts + 1, pts + n + 1);
		int jj = 0;
		F(i, 1, n)
		{
			if (jj > 0 && pts[i][0] == pts[jj][0]) continue;
			while (jj >= 2 && (__int128)(pts[i][1] - pts[jj][1]) * (pts[jj][0] - pts[jj - 1][0])
				<= (__int128)(pts[jj][1] - pts[jj - 1][1]) * (pts[i][0] - pts[jj][0])) --jj;
			pts[++jj] = pts[i];
		}

		// F(t, bg, ed - 1)
		// {
		// 	__int128 mn = 0;
		// 	F(i, 1, jj)
		// 	{
		// 		MIN(mn, pts[i][1] - pts[i][0] * t);
		// 	}
		// 	res += (-mn) & (((__int128)1 << 64) - 1);
		// }

		vector<LL> tt{bg, ed};
		F(i, 2, jj)
		{
			LL cur = (pts[i][1] - pts[i - 1][1] + pts[i][0] - pts[i - 1][0] - 1)
				/ (pts[i][0] - pts[i - 1][0]);
			if (cur >= bg && cur < ed) tt.push_back(cur);
		}
		sort(tt.begin(), tt.end());
		tt.resize(unique(tt.begin(), tt.end()) - tt.begin());
		int kk = 1;
		F(i, 0, SZ(tt) - 1)
		{
			LL bbg = tt[i], eed = tt[i + 1];
			while (kk < jj && pts[kk][1] - (__int128)pts[kk][0] * bbg
				> pts[kk + 1][1] - (__int128)pts[kk + 1][0] * bbg) ++kk;
			res -= (ULL)(((__int128)(eed - bbg) * (eed + bbg - 1) / 2) & (((__int128)1 << 64) - 1))
				* (ULL)(-pts[kk][0]);
			res -= (ULL)pts[kk][1] * (eed - bbg);
		}
		ans += res;
	}
	cout << ans << endl;
	
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3476kb

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

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: 1ms
memory: 3484kb

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: 1ms
memory: 3480kb

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

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: 0
Accepted
time: 0ms
memory: 3444kb

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:

18304932886689493500

result:

ok single line: '18304932886689493500'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3428kb

input:

100 1000000000000000000
839671173511709 107 620743247548148 134
338569457755976 9 455191878916920 157
56529874788057 33 993208347666256 99
553193266380324 120 589361808163439 126
866467572275902 19 13931460152331 210
630774124991101 56 253227140072409 133
970610042608501 106 332792633317838 252
8813...

output:

2159229278647499039

result:

ok single line: '2159229278647499039'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

100 1000000000000000000
926447257775795 188 535928580576730 524
773621914798781 805 607314524993852 999
433706296251306 467 260773017334982 276
627420175261216 730 936517336182015 391
944793592281860 143 916701567834795 374
985020926183290 391 155471328385744 343
158052135419112 152 37256868527793 4...

output:

845915142005167939

result:

ok single line: '845915142005167939'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3480kb

input:

5 10000000
82420 1 83004 12
90974 1 5052 16
74853 1 50459 3
40080 1 8547 14
73449 1 29852 11

output:

50401135100561

result:

ok single line: '50401135100561'

Test #10:

score: -100
Wrong Answer
time: 18ms
memory: 3540kb

input:

100 1000000000000000000
9993245793650 4 9241831921583 115
6604842581175 13 7477954917260 107
7956734211252 3 351959292590 21
8744829275263 11 1121812966924 88
4383873864556 10 7802901884633 87
2999374450961 5 7728117026444 119
2606040601922 2 9450726899416 95
463533606932 4 456141627827 113
51628088...

output:

1277876296223419748

result:

wrong answer 1st lines differ - expected: '1462626783113250968', found: '1277876296223419748'