QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#365050 | #8112. Pastry shop | ckiseki# | WA | 0ms | 3884kb | C++20 | 2.9kb | 2024-03-24 18:41:29 | 2024-03-24 18:41:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
using lld = int64_t;
// struct Dsu {
// vector<int> pa, sz;
// Dsu(int n) : pa(n), sz(n, 1) {
// iota(all(pa), 0);
// }
// int anc(int x) {
// return x==pa[x] ? x : pa[x]=anc(pa[x]);
// }
// bool join(int x, int y) {
// x = anc(x);
// y = anc(y);
// if (x == y) return false;
// if (sz[x] < sz[y]) swap(x, y);
// pa[y] = x;
// sz[x] += sz[y];
// return true;
// }
// };
struct Event {
lld a, b;
int p;
};
bool operator<(const Event &lhs, const Event &rhs) {
return lhs.a * rhs.b > lhs.b * rhs.a;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
++n;
vector<lld> t(n);
for (int i = 1; i < n; i++) {
cin >> t[i];
}
vector<pair<int,int>> qs;
for (int i = 0; i < m; i++) {
int d;
cin >> d;
qs.emplace_back(d, i);
}
sort(all(qs));
vector<int> L(n, 1);
priority_queue<Event> evt;
for (int i = 0; i + 1 < n; i++) {
evt.emplace(t[i + 1] - t[i], 1, i);
}
lld ansA = 0, ansB = 0;
auto add_contrib = [&](lld i, int coef) {
for (int j = 0; j < L[i]; j++) {
ansB += t[i] * coef;
ansA += j * coef;
}
};
for (int i = 0; i < n; i++)
add_contrib(i, 1);
set<int> st;
for (int i = 0; i < n; i++)
st.insert(i);
vector<lld> ans(m);
lld sumT = 0;
for (int i = 0; i < n; i++)
sumT += t[i];
debug(sumT);
size_t idx = 0;
while (!evt.empty()) {
auto [dt, len, pos] = evt.top(); evt.pop();
debug(dt / double(len));
while (idx < qs.size() && qs[idx].first * len <= dt) {
int j = qs[idx].second;
ans[j] = ansA * qs[idx].first + ansB - sumT;
debug(idx, j, qs[idx].first);
++idx;
}
if (!st.count(pos) || !st.count(pos + len))
continue;
// if (dsu.anc(pos) == dsu.anc(pos + len))
// continue;
// dsu.join(pos, pos + len);
add_contrib(pos, -1);
add_contrib(pos + len, -1);
st.erase(pos + len);
L[pos] += L[pos + len];
L[pos + len] = 0;
add_contrib(pos, 1);
auto it = st.upper_bound(pos);
if (it != st.end()) {
evt.emplace(t[*it] - t[pos], *it - pos, pos);
}
orange(all(st));
orange(all(L));
}
for (int i = 0; i < m; i++)
cout << ans[i] << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
input:
4 3 3 10 11 23 4 2 5
output:
4 1 6
result:
ok 3 number(s): "4 1 6"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3540kb
input:
100 100 1 3 5 5 6 10 10 12 13 14 14 14 14 15 16 17 18 19 19 19 20 22 24 26 26 29 29 30 30 30 31 31 32 32 33 36 37 38 40 40 42 43 43 46 47 47 48 49 55 56 59 60 61 61 63 64 64 65 65 66 67 68 72 74 76 76 77 79 80 80 81 81 81 81 82 82 82 84 84 84 85 87 87 88 89 89 89 90 90 91 91 91 92 93 94 95 99 100 10...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9775 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 24925 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4725 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
wrong answer 1st numbers differ - expected: '439025', found: '0'