QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#576785 | #8548. China Convex Polygon Contest | ucup-team4435# | WA | 13ms | 3660kb | C++20 | 3.6kb | 2024-09-19 22:22:51 | 2024-09-19 22:22:51 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define each(x, a) for (auto &x : a)
#define ar array
#define vec vector
#define range(i, n) rep(i, n)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;
int Bit(int mask, int b) { return (mask >> b) & 1; }
template<class T>
bool ckmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<class T>
bool ckmax(T &a, const T &b) {
if (b > a) {
a = b;
return true;
}
return false;
}
// [l, r)
template<typename T, typename F>
T FindFirstTrue(T l, T r, const F &predicat) {
--l;
while (r - l > 1) {
T mid = l + (r - l) / 2;
if (predicat(mid)) {
r = mid;
} else {
l = mid;
}
}
return r;
}
template<typename T, typename F>
T FindLastFalse(T l, T r, const F &predicat) {
return FindFirstTrue(l, r, predicat) - 1;
}
const ll INF = 2e18;
const int INFi = 1e9;
const int N = 2e5 + 5;
const int LG = 20;
void solve() {
int n, m;
cin >> n >> m;
vi a(n);
rep(i, n) cin >> a[i];
vi b(n);
rep(i, n) {
cin >> b[i];
}
int sz = n;
for (int i = 1; i < n; ++i) {
b[i] += b[i - 1];
if (b[i] > m) {
sz = i;
b.resize(sz);
break;
}
}
while (sz > 0 && b[sz - 1] >= m) {
sz--;
b.pop_back();
}
while (n > 0 && a[n - 1] >= m) {
n--;
a.pop_back();
}
reverse(all(b));
reverse(all(a));
rep(i, n) a[i] = m - a[i];
rep(i, sz) b[i] = m - b[i];
int lq = 0;
a.push_back(m);
n++;
ll pos = 0;
int ans = 0;
priority_queue<ll> have;
rep(i, n) {
int rq = lq;
while (rq < sz && b[rq] <= a[i]) {
rq++;
}
for (int j = lq; j + 1 < rq; ++j) {
if (!have.empty()) {
ll val = have.top();
have.pop();
ans += val;
}
}
if (lq == rq) {
have.push(a[i] - pos);
pos = a[i];
continue;
}
lq = rq;
int j = rq - 1;
ll val = b[j] - pos;
if (have.empty() || val > have.top()) {
ans += val;
ll t = a[i] - b[j];
if (!have.empty()) {
t += have.top();
have.pop();
}
if (t) {
have.push(t);
}
pos = a[i];
continue;
} else {
ll value = have.top();
have.pop();
ans += value;
have.push(a[i] - pos);
pos = a[i];
continue;
}
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(12) << fixed;
int t = 1;
cin >> t;
rep(i, t) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
3 3 10 1 5 9 1 2 3 3 10 1 5 9 1 1 4 3 10 1 5 9 1 5 10
output:
9 9 7
result:
ok 3 number(s): "9 9 7"
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 3660kb
input:
10000 9 879847766 125098132 150509852 181700303 196375322 519766842 560891576 609151480 721527163 805167083 99031467 66330518 6283986 21388462 41109537 83628243 116141243 144052767 192448599 8 30 5 12 16 19 20 23 25 27 3 1 1 4 2 8 2 3 8 30 4 10 13 16 17 20 23 27 6 3 1 2 3 4 7 2 7 586479012 37693706 ...
output:
740552446 26 23 508883916 28 820816836 25 769874714 942603170 631257931 492186961 454332137 24 27 26 703954964 18 25 26 646348792 25 23 26 26 25 28 27 27 24 680432876 686942822 26 26 24 710720807 751241131 526383075 727826477 909314391 26 28 813993374 25 23 29 429433659 23 22 504593826 21 22 7111523...
result:
wrong answer 1st numbers differ - expected: '858888761', found: '740552446'