QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#193378 | #7520. Monster Generator | ucup-team1198# | WA | 47ms | 3620kb | C++20 | 6.2kb | 2023-09-30 17:00:33 | 2023-09-30 17:00:33 |
Judging History
你现在查看的是测评时间为 2023-09-30 17:00:33 的历史记录
- [2023-11-04 16:34:13]
- hack成功,自动添加数据
- (//qoj.ac/hack/422)
- [2023-11-04 16:28:16]
- hack成功,自动添加数据
- (//qoj.ac/hack/420)
- [2023-09-30 17:00:33]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()
long long div_up(long long a, long long b) {
if (a >= 0)
return (a + b - 1) / b;
return a / b;
}
// line: (a,b) - ax+b, a.first < b.first
long long inter(const pair<long long, long long>& a, const pair<long long, long long>& b) {
return div_up(a.second - b.second, b.first - a.first);
}
long long at(const pair<long long, long long>& line, long long x) {
return line.first * x + line.second;
}
const long long INF = 1e18 + 1000;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
long long m;
cin >> n >> m;
vector<pair<long long, long long>> as(n);
vector<pair<long long, long long>> bs(n);
for (int i = 0; i < n; ++i) {
cin >> as[i].first >> as[i].second >> bs[i].first >> bs[i].second;
}
vector<long long> events;
events.emplace_back(0);
for (int i = 0; i < n; ++i) {
if (as[i].second == bs[i].second)
continue;
if (as[i].second > bs[i].second) {
if (bs[i].first >= as[i].first)
events.emplace_back(div_up(bs[i].first - as[i].first, as[i].second - bs[i].second));
} else {
if (as[i].first >= bs[i].first) {
events.emplace_back(div_up(as[i].first - bs[i].first, bs[i].second - as[i].second));
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (as[i].second < as[j].second) {
events.emplace_back(inter(make_pair(as[i].second, as[i].first), make_pair(as[j].second, as[j].first)));
} else if (as[i].second > as[j].second) {
events.emplace_back(inter(make_pair(as[j].second, as[j].first), make_pair(as[i].second, as[i].first)));
}
if (bs[i].second < bs[j].second) {
events.emplace_back(inter(make_pair(bs[i].second, bs[i].first), make_pair(bs[j].second, bs[j].first)));
} else if (bs[i].second > bs[j].second) {
events.emplace_back(inter(make_pair(bs[j].second, bs[j].first), make_pair(bs[i].second, bs[i].first)));
}
}
}
for (int i = 0; i < events.size(); ++i) {
if (events[i] < 0) {
swap(events[i], events.back());
events.pop_back();
--i;
}
}
sort(events.begin(), events.end());
events.resize(unique(events.begin(), events.end()) - events.begin());
while (events.back() > m)
events.pop_back();
events.emplace_back(m + 1);
unsigned long long ans = 0;
for (int i = 0; i + 1 < events.size(); ++i) {
long long cur_time = events[i];
long long to_time = events[i + 1];
vector<int> order(n);
iota(order.begin(), order.end(), 0);
auto is_positive = [&](int i) {
if (as[i].second == bs[i].second)
return as[i].first < bs[i].first;
if (as[i].second > bs[i].second) {
return cur_time < div_up(bs[i].first - as[i].first, as[i].second - bs[i].second);
}
return cur_time >= div_up(as[i].first - bs[i].first, bs[i].second - as[i].second);
};
sort(order.begin(), order.end(), [&](int a, int b) {
bool p1 = is_positive(a);
bool p2 = is_positive(b);
if (p1 && p2) {
if (as[a].second == as[b].second)
return as[a].first < as[b].first;
if (as[a].second > as[b].second)
return cur_time < div_up(as[b].first - as[a].first, as[a].second - as[b].second);
return cur_time >= div_up(as[a].first - as[b].first, as[b].second - as[a].second);
} else if (p1) {
return true;
} else if (p2) {
return false;
} else {
if (bs[a].second == bs[b].second)
return bs[b].first > bs[b].first;
if (bs[a].second > bs[b].second)
return cur_time >= div_up(bs[b].first - bs[a].first, bs[a].second - bs[b].second);
} return cur_time < div_up(bs[a].first - bs[b].first, bs[b].second - bs[a].second);
});
vector<pair<long long, long long>> lines;
lines.emplace_back(0ll, 0ll);
pair<long long, long long> cur(0ll, 0ll);
for (int i : order) {
lines.emplace_back(cur.first + as[i].second, cur.second + as[i].first);
cur = make_pair(cur.first - bs[i].second + as[i].second, cur.second - bs[i].first + as[i].first);
}
sort(lines.begin(), lines.end(), [](const pair<long long, long long>& l1, const pair<long long, long long>& l2) {
if (l1.first == l2.first)
return l1.second > l2.second;
return l1.first < l2.first;
});
vector<pair<long long, long long>> cht_lines;
vector<long long> points;
for (const pair<long long, long long>& line : lines) {
if (cht_lines.empty()) {
cht_lines.emplace_back(line);
continue;
}
if (cht_lines.back().first == line.first)
continue;
while (!points.empty() && points.back() >= inter(cht_lines.back(), line)) {
cht_lines.pop_back();
points.pop_back();
}
points.emplace_back(inter(cht_lines.back(), line));
cht_lines.emplace_back(line);
}
long long from = -INF;
for (int i = 0; i < cht_lines.size(); ++i) {
long long to = i + 1 == cht_lines.size() ? INF : points[i];
if (max(from, cur_time) < min(to, to_time)) {
long long a = max(from, cur_time);
long long b = min(to, to_time) - 1;
if ((a + b) % 2)
ans += uint64_t((b - a + 1) / 2) * (uint64_t(a + b) * uint64_t(cht_lines[i].first) + uint64_t(2 * cht_lines[i].second));
else
ans += uint64_t(b - a + 1) * (uint64_t((a + b) / 2) * uint64_t(cht_lines[i].first) + uint64_t(cht_lines[i].second));
}
from = to;
}
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3428kb
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: 3444kb
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: 3480kb
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: 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: 3444kb
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: 3484kb
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: 3468kb
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: 3580kb
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: 3432kb
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: 0
Accepted
time: 39ms
memory: 3588kb
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:
1462626783113250968
result:
ok single line: '1462626783113250968'
Test #11:
score: 0
Accepted
time: 46ms
memory: 3620kb
input:
100 1000000000000000000 5514922686365 63 3893026500867 7 9437390653117 2 2307883657774 37 2266370593545 180 282207773345 54 7413603305531 64 6590374339957 4 2003184336714 205 3334946120451 23 8047937523313 197 6016974069987 57 49327962408 210 95380662767 50 5796501143593 219 4738100059711 11 4403864...
output:
3008948596970395169
result:
ok single line: '3008948596970395169'
Test #12:
score: 0
Accepted
time: 46ms
memory: 3568kb
input:
100 1000000000000000000 9522256146511 22 7648033142717 124 4890738110302 13 5169707386838 200 1692873223867 14 4198546120569 164 5759367352857 61 5467937093692 19 5156572753262 64 2244161860595 92 5800903619823 60 9979656907955 2 9003875069201 21 6933129430226 204 9783187462793 49 5298708535013 190 ...
output:
5391002818765040268
result:
ok single line: '5391002818765040268'
Test #13:
score: 0
Accepted
time: 47ms
memory: 3620kb
input:
100 1000000000000000000 3121743641635 206 2774880557656 124 4341273709336 48 3868201748314 58 4898184402079 75 8962585631533 152 6469059809450 191 7785613783588 151 5901037828713 109 1086985069519 120 1872215875662 118 8935389074175 187 1080302564361 60 1962889993669 35 8218338957964 95 230441706635...
output:
4006532618546541597
result:
ok single line: '4006532618546541597'
Test #14:
score: -100
Wrong Answer
time: 1ms
memory: 3604kb
input:
100 1000000000000000000 121103125248530 208 233527234872397 54 842070374171965 178 514148681666092 126 93136745067938 256 36717885771563 224 120511269258919 654 299962020993680 15 426864331284465 625 581173275854814 257 618912001992036 511 767521635123932 235 937058562049830 716 650234846124942 322 ...
output:
10367758687843926311
result:
wrong answer 1st lines differ - expected: '7367765353666615058', found: '10367758687843926311'