QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#46204 | #4488. Buy Figurines | miaomiaozi | AC ✓ | 570ms | 20224kb | C++17 | 3.9kb | 2022-08-26 16:32:18 | 2022-08-26 16:32:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// https://space.bilibili.com/672346917
#ifndef LOCAL
#define LOG(...) 42
#endif
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long LL;
typedef pair <int, int> PII;
constexpr int inf = 0x3f3f3f3f;
constexpr double EPS = 1e-8;
const double PI = acos(-1);
int multi_cases = 1;
template <typename T = long long>
struct SegTree {
struct node {
int l, r;
int mn = inf;
};
int n;
vector <node> tr;
vector <T> a;
SegTree(int _n = 1): n(_n), tr((_n + 5) << 2), a(_n + 5) {
build(1, 1, n);
}
SegTree(int _n, const vector <T> &_a) : n(_n), tr((_n + 5) << 2), a(_a) {
build(1, 1, n);
}
void init(int u, int r) {
assert(1 <= r && r <= n);
tr[u].mn = 0;
}
void pushup(node &u, node &l, node &r) {
u.mn = min(l.mn, r.mn);
}
void pushdown(node &u, node &l, node &r) {
}
void modify(int u, int l, int r, LL c) {
if(tr[u].l >= l && tr[u].r <= r) {
tr[u].mn += c;
return;
}
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
if(l <= mid) modify(u << 1, l, r, c);
if(r > mid) modify(u << 1 | 1, l, r, c);
pushup(u);
}
int query(int u) {
if (tr[u].l == tr[u].r) {
return tr[u].r;
}
int mid = tr[u].l + tr[u].r >> 1;
if (tr[u << 1].mn <= tr[u << 1 | 1].mn) {
return query(u << 1);
} else {
return query(u << 1 | 1);
}
}
int query() {
return query(1);
}
LL len(int &u) {
return 1LL * tr[u].r - tr[u].l + 1;
}
LL len(node &u) {
return 1LL * u.r - u.l + 1;
}
void pushup(int u) {
pushup(tr[u], tr[u << 1], tr[u << 1 | 1]);
}
void pushdown(int u) {
pushdown(tr[u], tr[u << 1], tr[u << 1 | 1]);
}
void build(int u, int l, int r) {
tr[u].l = l, tr[u].r = r;
if(l == r) {
init(u, r);
return;
}
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
pushup(u);
}
node query(int u, int l, int r) {
if(tr[u].l >= l && tr[u].r <= r) {
return tr[u];
}
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
if(r <= mid) return query(u << 1, l, r);
else if (l > mid) return query(u << 1 | 1, l, r);
else {
node res, left, right;
left = query(u << 1, l, r);
right = query(u << 1 | 1, l, r);
pushup(res, left, right);
return res;
}
}
};
struct Info {
LL t, used;
int finish, pos;
bool operator < (const Info &o) const {
return t > o.t;
}
};
void A_SOUL_AvA () {
int n, m;
cin >> n >> m;
priority_queue <Info> q;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
q.push({a, b, 0, -1});
}
SegTree <int> st(m);
LL ans = 0;
vector <LL> tot(m + 1);
while (q.size()) {
auto [sta, used, finish, pos] = q.top();
q.pop();
if (finish) {
st.modify(1, pos, pos, -1);
ans = max(ans, sta);
continue;
}
int which = st.query();
tot[which] = max(tot[which], sta) + used;
st.modify(1, which, which, 1);
q.push({tot[which], 0, 1, which});
}
cout << ans << endl;
}
int main () {
cin.tie(nullptr)->sync_with_stdio(false);
cout << fixed << setprecision(12);
int T = 1;
for (multi_cases && cin >> T; T; T--) {
A_SOUL_AvA ();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 570ms
memory: 20224kb
input:
8 5 3 2 4 1 3 5 1 3 4 4 2 200000 200000 26113860 1563 45251761 2156 63941612 4551 16962783 4576 18965664 5853 4091010 2401 10238760 7732 19457520 7279 7641592 4270 24241152 7862 51178555 8548 31253040 7967 2966632 5745 59550817 1824 4312590 7419 81579464 2401 20977992 8997 28997820 6485 3132935 9527...
output:
7 99184946 99609939 27024359944 26923428235 4992516018218 93791976 117811694
result:
ok 8 lines