QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#643228 | #8548. China Convex Polygon Contest | orz_z | WA | 9ms | 9952kb | C++14 | 4.6kb | 2024-10-15 19:58:26 | 2024-10-15 19:58:35 |
Judging History
answer
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("Ofast,fast-math")
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {
cerr << "[" << s << "] = [" << x << "]\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {
for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;
else if (s[i] == ')' || s[i] == '}') b--;
else if (s[i] == ',' && b == 0) {
cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";
debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);
break;
}
}
#ifdef ONLINE_JUDGE
#define Debug(...)
#else
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
int x = 0;
bool t = 0;
char c = getchar();
while (c < '0' || c > '9') t |= c == '-', c = getchar();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return t ? -x : x;
}
inline void wi(int x) {
if (x < 0) {
putchar('-'), x = -x;
}
if (x > 9) wi(x / 10);
putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
wi(x), putchar(s);
}
bool Mbe;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3f;
const int _ = 2e5 + 5;
int n, m, a[_], b[_];
bool vis[_];
map<pii, int> mp;
//int val[_];
struct sgt {
struct node {
int s, tg, lc, rc;
} tr[_ * 30];
int cnt;
int rt;
void init() {
F(i, 0, cnt + 1) tr[i].s = tr[i].tg = tr[i].lc = tr[i].rc = 0;
cnt = 0;
rt = 0;
}
void upd(int &o, int l, int r, int L, int R, int v) {
if (L > R) return;
if (!o) o = ++cnt;
if (L <= l && r <= R) {
tr[o].s += v;
tr[o].tg += v;
return;
}
int mid = (l + r) >> 1;
if (L <= mid) upd(tr[o].lc, l, mid, L, R, v);
if (R > mid) upd(tr[o].rc, mid + 1, r, L, R, v);
tr[o].s = max(tr[tr[o].lc].s, tr[tr[o].rc].s);
}
int qry(int o, int l, int r, int p, int tg = 0) {
if (l == r) {
return tr[o].s + tg;
}
int mid = (l + r) >> 1;
return p <= mid ? qry(tr[o].lc, l, mid, p, tg + tr[o].tg) : qry(tr[o].rc, mid + 1, r, p, tg + tr[o].tg);
}
} tr;
int s[_], val[_], cnt[_];
void solve() {
n = ri(), m = ri();
F(i, 1, n) a[i] = ri();
// int n2 = n;
// tr.init();
F(i, 1, n) b[i] = ri();
sort(b + 1, b + n + 1);
F(i, 1, n) s[i] = s[i - 1] + b[i];
a[n + 1] = m;
F(i, 1, n + 1) val[i] = cnt[i] = 0;
int j = 0;
F(i, 1, n) {
while(j <= n + 1 && a[j] < s[i]) j++;
if(j <= n + 1) val[j] = max(val[j], a[j] - s[i]), cnt[j]++;
}
int ans = 0;
priority_queue<int> q;
F(i, 1, n + 1) {
if(cnt[i]) {
int W1 = val[i], W2 = (!q.empty()) ? a[i] - a[i - 1] + q.top() : 0;
if(W1 >= W2) {
ans += W1;
q.push(-W1);
} else {
ans += a[i] - a[i - 1] + q.top();
q.pop();
q.push(-(a[i] - a[i - 1]));
q.push(0);
}
F(j, 1, cnt[i] - 1) q.push(0);
} else {
if(!q.empty() && a[i] - a[i - 1] + q.top() > 0) {
ans += a[i] - a[i - 1] + q.top();
q.pop();
q.push(-(a[i] - a[i - 1]));
}
}
}
cout << ans << '\n';
}
bool Med;
signed main() {
// Mry;
int T = ri();
while (T--) {
solve();
}
// Try;
return 0;
}
/*
9 879847766
125098132 150509852 181700303 196375322 519766842 560891576 609151480 721527163 805167083
99031467 66330518 6283986 21388462 41109537 83628243 116141243 144052767 192448599
*/
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9952kb
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: 9ms
memory: 5704kb
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:
858888761 28 26 526984260 28 875933380 27 803763192 942603170 720683076 536166430 759475944 28 27 27 886112586 27 28 28 727698126 28 27 29 27 28 28 28 27 25 819730903 755064144 27 26 27 792662140 891539003 583799124 817190966 934413263 28 27 865467960 25 27 29 450970031 27 26 618111955 28 27 8328741...
result:
wrong answer 3rd numbers differ - expected: '27', found: '26'