QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#853784 | #3299. Advertisement Matching | rlc202204 | TL | 4ms | 14100kb | C++23 | 3.2kb | 2025-01-11 19:14:41 | 2025-01-11 19:14:43 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2.5e5 + 5;
typedef long long ll;
#define debug(x) cout << #x << "=" << x << endl
ll val[N << 2] = {0};
ll tag[N << 2] = {0};
#define ls (x << 1)
#define rs (x << 1 | 1)
#define mid ((lx + rx) >> 1)
void pushup(int x) {
val[x] = max(val[ls], val[rs]);
}
void pushdown(int x) {
if (tag[x] == 0ll)
return;
val[ls] += tag[x], tag[ls] += tag[x];
val[rs] += tag[x], tag[rs] += tag[x];
tag[x] = 0ll;
}
void build(int x, int lx, int rx, ll *a) {
if (lx + 1 == rx) {
val[x] = a[lx];
return;
}
build(ls, lx, mid, a), build(rs, mid, rx, a);
pushup(x);
}
void upd(int x, int lx, int rx, int l, int r, ll v) {
if (rx <= l || r <= lx)
return;
if (l <= lx && rx <= r) {
val[x] += v;
tag[x] += v;
return;
}
pushdown(x);
upd(ls, lx, mid, l, r, v), upd(rs, mid, rx, l, r, v);
pushup(x);
}
#undef ls
#undef rs
#undef mid
int n, m;
int a[N] = {0};
int b[N] = {0};
int ca[N] = {0}, cb[N] = {0};
ll res[N] = {0};
ll ta, tb;
bool cmp(int x, int y) {
return x > y;
}
void calc() {
/*
for (int i = 1; i <= n; i++)
cout << ca[i] << " ";
cout << endl;
for (int j = 1; j <= m; j++)
cout << cb[j] << " ";
cout << endl;
*/
ll sum = tb, ans = 0;
for (int i = 1, j = m; i <= n; i++) {
while (j >= 1 && cb[j] < i)
sum -= cb[j], j--;
sum += ca[i];
res[i] = sum - 1ll * j * i;
ans = max(ans, res[i]);
// debug(i), debug(res[i]);
}
ll mn = min({ta, tb, ta + tb - ans});
if (mn == ta)
printf("1\n");
else
printf("0\n");
}
int main() {
scanf("%d%d", &n, &m);
ta = tb = 0ll;
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]), ca[i] = a[i], ta += a[i];
for (int j = 1; j <= m; j++)
scanf("%d", &b[j]), cb[j] = b[j], tb += b[j];
sort(ca + 1, ca + n + 1, cmp);
sort(cb + 1, cb + m + 1, cmp);
ll sum = tb;
for (int i = 1, j = m; i <= n; i++) {
while (j >= 1 && cb[j] < i)
sum -= cb[j], j--;
sum += ca[i];
res[i] = sum - 1ll * j * i;
// debug(i), debug(res[i]);
}
build(1, 1, n + 1, res);
int q;
scanf("%d", &q);
for (int i = 1, op, j; i <= q; i++) {
scanf("%d%d", &op, &j);
if (op == 1) {
int pos = lower_bound(ca + 1, ca + n + 1, a[j], greater<int>()) - ca;
a[j]++, ca[pos]++;
ta++;
// debug(pos);
upd(1, 1, n + 1, pos, n + 1, 1);
}
else if (op == 2) {
int pos = (ca[n] == a[j] ? n : upper_bound(ca + 1, ca + n + 1, a[j], greater<int>()) - ca - 1);
a[j]--, ca[pos]--;
ta--;
upd(1, 1, n + 1, pos, n + 1, -1);
}
else if (op == 3) {
// debug(b[j]);
int pos = lower_bound(cb + 1, cb + m + 1, b[j], greater<int>()) - cb;
b[j]++, cb[pos]++;
tb++;
// debug(pos);
upd(1, 1, n + 1, 1, min(n + 1, cb[pos]), 1);
}
else {
int pos = (cb[m] == b[j] ? m : upper_bound(cb + 1, cb + m + 1, b[j], greater<int>()) - cb - 1);
b[j]--, cb[pos]--;
tb--;
upd(1, 1, n + 1, 1, min(n + 1, cb[pos]), -1);
}
calc();
/* ll ans = min({ta, tb, ta + tb - val[1]});
// cout << val[1] << endl;
// cout << ans << " " << ta << " " << tb << endl;
if (ans == ta)
printf("1\n");
else
printf("0\n");*/
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 12088kb
input:
5 5 1 5 2 4 3 3 3 3 3 3 5 4 2 3 5 2 2 1 1 1 4
output:
0 1 1 1 0
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 12024kb
input:
100 100 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 1...
output:
1 1 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 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 100 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 12048kb
input:
100 100 42 28 42 64 42 29 72 64 72 29 28 72 28 72 29 42 64 42 72 29 64 29 72 28 42 64 72 64 28 42 72 42 29 64 72 64 72 29 72 29 64 42 64 72 29 28 42 64 72 64 72 28 42 64 64 42 64 64 28 28 72 29 28 64 28 64 64 72 64 28 42 29 64 42 64 42 72 64 64 64 28 64 42 72 64 29 64 29 64 64 72 29 29 28 42 72 64 7...
output:
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 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 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:
ok 100 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 11992kb
input:
100 100 13 40 46 59 64 64 3 34 64 13 46 13 13 46 46 16 64 48 26 13 59 50 16 46 41 5 59 13 64 16 20 43 41 26 14 16 34 64 59 41 73 71 64 50 14 48 71 50 71 26 43 59 5 50 16 71 77 77 59 14 3 41 71 7 41 40 16 13 50 13 64 64 16 59 40 5 26 50 64 59 3 5 40 41 16 5 13 46 40 14 40 34 40 59 46 14 26 41 43 64 2...
output:
1 0 1 1 0 1 1 1 0 0 0 1 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 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 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 100 lines
Test #5:
score: 0
Accepted
time: 2ms
memory: 12084kb
input:
100 100 69 81 86 84 48 31 42 27 14 18 7 8 61 41 97 9 38 88 24 48 52 92 60 28 18 61 51 64 98 9 72 13 35 97 32 8 17 79 54 5 100 1 76 21 11 12 52 5 98 25 61 37 82 4 18 22 96 10 23 68 92 63 40 25 27 67 39 36 44 82 6 31 17 3 7 90 21 80 62 9 73 26 75 57 20 20 86 35 46 45 89 40 18 43 16 68 4 6 89 75 37 1 7...
output:
0 1 0 1 1 1 1 1 0 0 0 0 0 1 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 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok 100 lines
Test #6:
score: 0
Accepted
time: 3ms
memory: 11976kb
input:
1000 1000 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 88...
output:
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 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 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 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:
ok 1000 lines
Test #7:
score: 0
Accepted
time: 4ms
memory: 14100kb
input:
1000 1000 499 499 499 499 917 670 499 499 947 670 917 670 917 917 917 670 556 556 947 499 670 947 556 670 499 947 556 917 947 499 556 947 556 499 670 947 947 670 947 556 499 917 670 556 556 917 947 499 947 670 947 917 670 917 556 499 670 947 556 947 499 670 947 947 947 917 556 556 670 499 499 917 55...
output:
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 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 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 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:
ok 1000 lines
Test #8:
score: 0
Accepted
time: 4ms
memory: 12032kb
input:
1000 1000 16 517 918 174 148 253 293 596 438 217 566 362 984 507 690 320 253 144 971 74 157 981 547 802 39 765 264 771 846 745 539 906 743 39 242 266 568 660 118 352 509 278 500 481 929 502 375 315 599 756 217 159 606 39 967 50 145 863 412 7 780 320 745 942 99 52 510 560 184 669 596 50 477 236 7 507...
output:
1 0 1 0 0 0 0 0 0 0 0 0 0 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 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 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 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 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000 lines
Test #9:
score: 0
Accepted
time: 4ms
memory: 11976kb
input:
1000 1000 397 930 346 818 646 400 677 961 999 158 382 242 136 712 460 432 622 282 297 428 708 432 100 768 51 140 776 934 479 531 307 542 498 520 961 155 984 664 45 398 831 581 638 130 248 476 88 238 584 959 838 270 574 402 248 267 562 281 839 422 528 729 299 809 562 723 93 102 371 46 173 13 500 313 ...
output:
1 1 1 1 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 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 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 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:
ok 1000 lines
Test #10:
score: -100
Time Limit Exceeded
input:
250000 250000 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 50...
output:
0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 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 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 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 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 0 0 0 0 0 0 0 0 0 0 0 ...