ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#266 | #5. 「WyOJ Round 1」炽 · 踏浪而歌 | Dtw | 10 | 2210ms | 22508kb | C++23 | 2.0kb | 2025-04-18 15:02:52 | 2025-04-18 18:03:08 |
answer
#include <bits/stdc++.h>
using namespace std;
#define fst ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int N = 1e5 + 10, inf = 0x3f3f3f3f;
int n, a[N], cnt, b[N], nxt[N];
struct node { int mx, id; } tr[N << 2];
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define mid (l + r) / 2
void push_up(node &a, node b, node c)
{
if (b.mx > c.mx) a = b;
else a = c;
}
void build(int rt, int l, int r, int a[])
{
if (l == r) return tr[rt] = { a[l], l }, void();
build(lson, l, mid, a);
build(rson, mid + 1, r, a);
push_up(tr[rt], tr[lson], tr[rson]);
}
void update(int rt, int l, int r, int p, int v)
{
if (l == r) return tr[rt].mx += v, void();
if (p <= mid) update(lson, l, mid, p, v);
else update(rson, mid + 1, r, p, v);
push_up(tr[rt], tr[lson], tr[rson]);
}
node query(int rt, int l, int r, int sp, int ep)
{
if (sp <= l && r <= ep) return tr[rt];
node res; bool f = 0;
if (sp <= mid) res = query(lson, l, mid, sp, ep), f = 1;
if (ep > mid) {
if (f) push_up(res, res, query(rson, mid + 1, r, sp, ep));
res = query(rson, mid + 1, r, sp, ep);
}
return res;
}
multiset<pair<int, int>> q;
int main()
{
fst
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
build(1, 1, n, a);
int res = 0, cnt = 0;
while (1) {
auto t = tr[1];
if (!t.mx) break;
update(1, 1, n, t.id, -t.mx);
auto k = tr[1];
int c = 0;
if (!k.mx) { // 只剩我自己了
cnt = t.mx;
c = t.mx;
for (int i = 1; i <= c; i++) q.insert({t.id, t.id});
} else {
c = min(t.mx, k.mx);
update(1, 1, n, k.id, -c);
res += c;
for (int i = 1; i <= c; i++) q.insert({min(t.id, k.id), max(t.id, k.id)});
}
update(1, 1, n, t.id, t.mx - c);
}
cout << res + cnt << "\n";
for (auto u : q) cout << u.first << " " << u.second << "\n";
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 3ms
memory: 3368kb
input:
6 3 4 1 2 4 6
output:
10 1 2 1 2 1 2 2 3 4 6 4 6 5 6 5 6 5 6 5 6
result:
ok 21 numbers
Test #2:
score: 0
Wrong Answer
time: 131ms
memory: 11420kb
input:
1000 1000 1000 1000 999 996 993 991 991 991 991 991 991 988 988 988 988 987 984 980 980 978 978 977 ...
output:
259517 1 1 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1...
result:
wrong answer 5th numbers differ - expected: '2', found: '4'
Test #3:
score: 0
Wrong Answer
time: 255ms
memory: 20288kb
input:
5 93761 154479 466694 134030 151036
output:
533306 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
result:
wrong answer 1st numbers differ - expected: '500000', found: '533306'
Test #4:
score: 0
Wrong Answer
time: 276ms
memory: 20444kb
input:
56700 20 9 3 26 6 14 11 26 15 4 7 7 18 3 55 16 0 2 71 8 21 3 15 21 2 25 38 10 2 15 3 1 3 15 6 2 26 5...
output:
500000 1 5 1 56678 1 56678 1 56678 1 56678 1 56678 1 56678 1 56678 1 56678 1 56678 1 56678 1 56678 1...
result:
wrong answer 3rd numbers differ - expected: '2', found: '5'
Test #5:
score: 0
Wrong Answer
time: 243ms
memory: 19860kb
input:
18574 19 245 80 2 53 157 18 27 35 19 109 14 30 97 26 10 5 22 142 102 13 114 67 70 142 131 10 177 18 ...
output:
500000 1 5 1 18443 1 18443 1 18443 1 18443 1 18443 1 18443 1 18443 1 18443 1 18443 1 18443 1 18443 1...
result:
wrong answer 3rd numbers differ - expected: '2', found: '5'
Test #6:
score: 0
Wrong Answer
time: 266ms
memory: 20104kb
input:
36045 6 62 19 5 21 38 42 13 52 3 10 4 14 65 24 15 9 21 19 24 1 3 2 59 2 19 80 28 9 39 49 26 20 20 14...
output:
500000 1 47 1 47 1 47 1 47 1 47 1 47 2 3 2 35706 2 35706 2 35706 2 35706 2 35706 2 35706 2 35706 2 3...
result:
wrong answer 3rd numbers differ - expected: '2', found: '47'
Test #7:
score: 0
Wrong Answer
time: 235ms
memory: 19060kb
input:
100 442 37503 827 703 10394 1215 23599 313 1705 10819 6152 89 341 3448 778 7153 20397 5166 2735 2100...
output:
500000 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 88 1 8...
result:
wrong answer 3rd numbers differ - expected: '2', found: '88'
Test #8:
score: 0
Wrong Answer
time: 230ms
memory: 18944kb
input:
1000 6 436 820 182 327 3272 993 1042 321 2717 69 4321 706 4565 1280 528 1632 1317 916 125 262 1712 6...
output:
500000 1 2 1 999 1 999 1 999 1 999 1 999 2 299 2 299 2 299 2 299 2 299 2 299 2 299 2 299 2 299 2 299...
result:
wrong answer 5th numbers differ - expected: '2', found: '999'
Test #9:
score: 0
Wrong Answer
time: 251ms
memory: 19568kb
input:
10000 6 107 38 107 3 28 89 15 30 19 89 2 435 75 45 55 119 125 15 42 101 83 9 134 3 278 292 55 255 2 ...
output:
500000 1 167 1 167 1 167 1 167 1 167 1 167 2 3 2 9711 2 9711 2 9711 2 9711 2 9711 2 9711 2 9711 2 97...
result:
wrong answer 3rd numbers differ - expected: '2', found: '167'
Test #10:
score: 0
Wrong Answer
time: 320ms
memory: 22508kb
input:
100000 3 3 62 19 5 21 0 17 21 2 1 36 3 11 2 3 10 22 17 3 10 0 4 3 11 20 11 22 12 12 12 1 10 4 9 6 4 ...
output:
500000 1 2 1 2 1 2 3 5 3 99541 3 99541 3 99541 3 99541 3 99541 3 99541 3 99541 3 99541 3 99541 3 995...
result:
wrong answer 9th numbers differ - expected: '4', found: '5'