QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#390867 | #4636. Optimal Assortment | james1BadCreeper | WA | 545ms | 40872kb | C++14 | 1.7kb | 2024-04-16 00:17:08 | 2024-04-16 00:17:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 2e5 + 5, W = 1e6;
int n, m;
int V[N], L[N], R[N];
i64 Tw[W * 4 + 50], Twv[W * 4 + 50];
void update(int o, int l, int r, int p, int x, i64 y) {
if (l == r) return Tw[o] += x, Twv[o] += y, void();
int mid = l + r >> 1;
if (p <= mid) update(o << 1, l, mid, p, x, y);
else update(o << 1 | 1, mid + 1, r, p, x, y);
Tw[o] = Tw[o << 1] + Tw[o << 1 | 1];
Twv[o] = Twv[o << 1] + Twv[o << 1 | 1];
}
i64 Aw, Awv, pos;
void query(int o, int l, int r, i64 sw, i64 swv) {
if (l == r) return pos = l, Aw = sw, Awv = swv, void();
int mid = l + r >> 1;
i64 nsw = sw + Tw[o << 1 | 1], nswv = swv + Twv[o << 1 | 1];
if (Tw[o << 1 | 1] && nswv - (mid + 1) * nsw >= (mid + 1ll) * R[0]) query(o << 1 | 1, mid + 1, r, sw, swv);
else query(o << 1, l, mid, nsw, nswv);
}
void solve(void) {
query(1, 0, W, 0, 0);
Aw += R[0];
if (Aw == 0) return cout << pos << "/1\n", void();
i64 g = __gcd(Aw, Awv);
Aw /= g, Awv /= g;
cout << Awv << "/" << Aw << "\n";
}
int main(void) {
// ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> V[i];
for (int i = 0; i <= n; ++i) cin >> L[i];
for (int i = 0; i <= n; ++i) cin >> R[i];
for (int i = 1; i <= n; ++i) update(1, 0, W, V[i], L[i], 1ll * L[i] * V[i]);
solve();
while (m--) {
int op, x, y, z; cin >> op >> x >> y;
update(1, 0, W, V[x], -L[x], -L[x] * V[x]);
if (op == 1) cin >> z, L[x] = y, R[x] = z;
else V[x] = y;
update(1, 0, W, V[x], L[x], 1ll * L[x] * V[x]);
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 17956kb
input:
2 5 4 2 4 3 2 4 3 2 2 1 2 1 1 2 3 1 0 0 0 1 1 0 0 1 2 0 0
output:
16/9 10/9 1/1 2/1 2/1 0/1
result:
ok 6 lines
Test #2:
score: -100
Wrong Answer
time: 545ms
memory: 40872kb
input:
200000 200000 959139 199252 470888 74578 802746 396295 386884 721198 628655 722503 207868 647942 87506 792718 761498 917727 843338 908043 952768 268783 375312 414369 319712 96230 277106 168102 263554 936674 246545 667941 198849 268921 191459 436316 134606 802932 515506 837311 465964 394766 17626 650...
output:
311567211361053/313072603 311567211361053/313072603 311567211361053/313072603 311567211361053/313072603 311567211361053/313072603 311567211361053/313072603 311567211361053/313072603 311567211361053/313072603 311567211361053/313072603 311567211361053/313072603 311567211361053/313072603 31156721136105...
result:
wrong answer 388th lines differ - expected: '44602984818794/44818453', found: '269475019090603/270621015'