QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#195631 | #7520. Monster Generator | ucup-team180# | WA | 1ms | 3456kb | C++17 | 4.1kb | 2023-10-01 05:45:00 | 2023-11-04 18:36:48 |
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-10-01 05:45:00]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
long long m;
cin >> n >> m;
vector<long long> a(n), da(n), b(n), db(n);
for (int i = 0; i < n; i++){
cin >> a[i] >> da[i] >> b[i] >> db[i];
}
vector<long long> T;
T.push_back(0);
T.push_back(m + 1);
for (int i = 0; i < n; i++){
if (b[i] >= a[i] && db[i] < da[i]){
long long t = (b[i] - a[i] + da[i] - db[i]) / (da[i] - db[i]);
if (0 <= t && t <= m){
T.push_back(t);
}
}
if (b[i] < a[i] && da[i] < db[i]){
long long t = (a[i] - b[i] + db[i] - da[i] - 1) / (db[i] - da[i]);
if (0 <= t && t <= m){
T.push_back(t);
}
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (a[i] > a[j] && da[i] < da[j]){
long long t = (a[i] - a[j] + da[j] - da[i]) / (da[j] - da[i]);
if (0 <= t && t <= m){
T.push_back(t);
}
}
if (b[i] > b[j] && db[i] < db[j]){
long long t = (b[i] - b[j] + db[j] - db[i]) / (db[j] - db[i]);
if (0 <= t && t <= m){
T.push_back(t);
}
}
}
}
sort(T.begin(), T.end());
T.erase(unique(T.begin(), T.end()), T.end());
int cnt = T.size() - 1;
unsigned long long ans = 0;
for (int i = 0; i < cnt; i++){
vector<__int128_t> A(n), B(n);
for (int j = 0; j < n; j++){
A[j] = a[j] + (__int128_t) da[j] * T[i];
B[j] = b[j] + (__int128_t) db[j] * T[i];
}
vector<int> c1, c2;
for (int j = 0; j < n; j++){
if (B[j] >= A[j]){
c1.push_back(j);
} else {
c2.push_back(j);
}
}
sort(c1.begin(), c1.end(), [&](int x, int y){
return A[x] < A[y];
});
sort(c2.begin(), c2.end(), [&](int x, int y){
return B[x] > B[y];
});
vector<int> c;
for (int j : c1){
c.push_back(j);
}
for (int j : c2){
c.push_back(j);
}
vector<__int128_t> LA(n), LB(n);
__int128_t ca = 0, cb = 0;
for (int j = 0; j < n; j++){
LA[j] = ca - da[c[j]];
LB[j] = cb - a[c[j]];
ca = LA[j] + db[c[j]];
cb = LB[j] + b[c[j]];
}
vector<pair<__int128_t, __int128_t>> L(n);
for (int j = 0; j < n; j++){
L[j] = make_pair(LA[j], -LB[j]);
}
sort(L.begin(), L.end(), greater<pair<__int128_t, __int128_t>>());
for (int j = 0; j < n; j++){
L[j].second *= -1;
}
auto cross = [&](pair<__int128_t, __int128_t> P1, pair<__int128_t, __int128_t> P2){
__int128_t a1 = P1.first;
__int128_t b1 = P1.second;
__int128_t a2 = P2.first;
__int128_t b2 = P2.second;
return (b1 - b2 + a2 - a1) / (a2 - a1);
};
vector<pair<__int128_t, __int128_t>> LH;
LH.push_back(L[0]);
for (int j = 1; j < n; j++){
if (L[j].first != L[j - 1].first){
while (LH.size() >= 3){
pair<__int128_t, __int128_t> L1 = LH[LH.size() - 2];
pair<__int128_t, __int128_t> L2 = LH[LH.size() - 1];
pair<__int128_t, __int128_t> L3 = L[j];
if (cross(L1, L2) > cross(L2, L3)){
LH.pop_back();
} else {
break;
}
}
LH.push_back(L[j]);
}
}
int cnt2 = LH.size();
vector<long long> C(cnt2 - 1);
for (int j = 0; j < cnt2 - 1; j++){
C[j] = cross(LH[j], LH[j + 1]);
}
for (int j = 0; j < cnt2; j++){
long long mn = T[i], mx = T[i + 1] - 1;
if (j > 0){
mn = max(mn, C[j - 1]);
}
if (j < cnt2 - 1){
mx = min(mx, C[j] - 1);
}
if (mn <= mx){
unsigned long long as;
if (mn % 2 == mx % 2){
as = (unsigned long long) ((mn + mx) / 2) * (unsigned long long) (mx - mn + 1);
} else {
as = (unsigned long long) ((mx - mn + 1) / 2) * (unsigned long long) (mn + mx);
}
ans += (unsigned long long) (-LH[j].first) * as;
ans += (unsigned long long) (-LH[j].second) * (unsigned long long) (mx - mn + 1);
}
}
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3404kb
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: 1ms
memory: 3420kb
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
Wrong Answer
time: 0ms
memory: 3456kb
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:
13887535875942667282
result:
wrong answer 1st lines differ - expected: '17883317185357051350', found: '13887535875942667282'