QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#236917 | #7520. Monster Generator | kyEEcccccc | TL | 530ms | 3636kb | C++14 | 3.8kb | 2023-11-04 11:35:18 | 2023-11-04 18:37:32 |
Judging History
你现在查看的是最新测评结果
- [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 11:35:18]
- 提交
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] - (__int128)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: 0ms
memory: 3636kb
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: 530ms
memory: 3612kb
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: -100
Time Limit Exceeded
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...