QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#680307 | #9529. Farm Management | ucup-team3691# | WA | 1ms | 3852kb | C++14 | 3.6kb | 2024-10-26 20:34:52 | 2024-10-26 20:34:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
using ll = long long;
using ull = unsigned long long;
string to_string(const string &s) {
return '"' + s + '"';
}
string to_string(bool b) {
return b ? "true" : "false";
}
template <typename A, typename B>
string to_string(const pair<A, B> &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(const T &v) {
string s = "{";
bool first = true;
for (const auto &it : v) {
if (!first)
s += ", ";
else
first = false;
s += to_string(it);
}
return s += "}";
}
void debug_out() {
cerr << endl;
}
template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
cerr << to_string(first) << " ";
debug_out(rest...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto startTime = high_resolution_clock::now();
int get_time() {
auto stopTime = chrono::high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stopTime - startTime);
return duration.count(); // in ms
}
struct interval {
int w, l, r;
bool operator < (const interval &aux) const {
return w < aux.w;
}
};
struct node {
ll s, p;
};
struct aint {
aint(int n_, vector<pair<ll, ll>> &s) : n(n_), arb(4 * n_ + 5), s(s) {
build(s, 1, n, 1);
}
void build(vector<pair<ll, ll>> &s, int st, int dr, int nod) {
if (st == dr) {
arb[nod].s = s[st].second;
arb[nod].p = 1LL * s[st].first * s[st].second;
return;
}
int mij = (st + dr) / 2;
build(s, st, mij, nod * 2);
build(s, mij + 1, dr, nod * 2 + 1);
arb[nod].s = arb[nod * 2].s + arb[nod * 2 + 1].s;
arb[nod].p = arb[nod * 2].p + arb[nod * 2 + 1].p;
}
pair<ll, ll> query(ll r, int x, int y, int st, int dr, int nod) {
if (r == 0)
return {0, 0};
if (x <= st && dr <= y) {
if (arb[nod].s <= r) {
return {arb[nod].p, r - arb[nod].s};
}
}
if (st == dr) {
return {1LL * s[st].first * r, 0};
}
int mij = (st + dr) / 2;
pair<ll, ll> ans = {0, r};
ll add = 0;
if (y > mij) {
ans = query(r, x, y, mij + 1, dr, nod * 2 + 1);
r = ans.second;
add = ans.first;
}
if (x <= mij) {
ans = query(r, x, y, st, mij, nod * 2);
ans.first += add;
}
return ans;
}
int n;
vector<pair<ll, ll>> s;
vector<node> arb;
};
void solve() {
int n;
ll m;
cin >> n >> m;
vector<interval> v(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> v[i].w >> v[i].l >> v[i].r;
}
sort(v.begin() + 1, v.end());
ll sp = m;
ll base = 0;
vector<pair<ll, ll>> s(1);
for (int i = 1; i <= n; ++i) {
base = base + 1LL * v[i].w * v[i].l;
sp -= v[i].l;
s.push_back({v[i].w, v[i].r - v[i].l});
}
aint arb(n, s);
ll best = base;
for (int i = 1; i <= n; ++i) {
if (i == n) {
best = max(best, 1LL * sp * v[i].w);
continue;
}
sp = sp + v[i].l;
base = base - 1LL * v[i].w * v[i].l;
auto ans = arb.query(sp, i + 1, n, 1, n, 1);
best = max(best, base + ans.first + 1LL * ans.second * v[i].w);
base = base + 1LL * v[i].w * v[i].l;
sp = sp - v[i].l;
}
cout << best << "\n";
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3640kb
input:
5 17 2 3 4 6 1 5 8 2 4 4 3 3 7 5 5
output:
109
result:
ok single line: '109'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
12 62 503792 9 10 607358 1 3 600501 10 10 33249 4 4 774438 6 6 197692 3 6 495807 8 8 790225 5 9 77272 3 8 494819 4 9 894779 3 9 306279 5 6
output:
35204500
result:
ok single line: '35204500'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3852kb
input:
15 32 835418 2 3 178262 1 3 527643 2 2 519710 1 1 774544 3 3 82312 1 1 808199 1 1 809396 1 3 255882 1 3 80467 1 3 874973 1 3 813965 1 2 198275 1 2 152356 1 3 802055 1 1
output:
21565150
result:
wrong answer 1st lines differ - expected: '22000255', found: '21565150'