QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#603374 | #7787. Maximum Rating | wsxcb# | WA | 2ms | 11812kb | C++17 | 2.2kb | 2024-10-01 16:14:37 | 2024-10-01 16:14:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
const int N = 4e5 + 10;
int lowbit(int x) {
return x & (-x);
}
struct BIT {
ll a[N];
void add(int x, int k) {
for (int i = x; i < N; i += lowbit(i))
a[i] += k;
}
int get(int x) {
ll ans = 0;
for (int i = x; i; i -= lowbit(i)) {
ans += a[i];
}
return ans;
}
} t1, t2;
int n, q, cnt = 0;
int a[N], b[N];
ll s1 = 0, c2 = 0, c1 = 0;
void solve() {
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] > 0) {
b[++cnt] = a[i];
c2++;
} else if (a[i] < 0) {
s1 += abs(a[i]);
c1++;
}
}
vector<pair<int, int>>ask(q + 1);
for (int i = 1; i <= q; i++) {
cin >> ask[i].first >> ask[i].second;
if (ask[i].second > 0)
b[++cnt] = ask[i].second;
}
sort(b + 1, b + 1 + cnt);
int len = unique(b + 1, b + 1 + cnt) - b - 1;
for (int i = 1; i <= n; i++) {
int pos = lower_bound(b + 1, b + 1 + len, a[i]) - b;
//cout << pos << ' ' << a[i] << '\n';
t1.add(pos, 1);
t2.add(pos, a[i]);
}
//cout << t2.get(1) << '\n';
for (int _ = 1; _ <= q; _++) {
auto [p1, x] = ask[_];
int pos = lower_bound(b + 1, b + 1 + len, x) - b;
if (x > 0) {
t1.add(pos, 1);
t2.add(pos, x);
c2++;
} else
s1 += abs(x);
if (a[p1] > 0) {
int pos = lower_bound(b + 1, b + 1 + len, a[p1]) - b;
//cout << pos << ' ';
t1.add(pos, -1);
t2.add(pos, -a[p1]);
c2--;
} else
s1 -= abs(a[p1]);
a[p1] = x;
//cout << s1 << ' ';
int l = 1, r = len, p2 = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (t2.get(mid) >= s1) {
p2 = mid;
r = mid - 1;
} else
l = mid + 1;
}
if (p2 == -1) {
cout << c2 + 1 << '\n';
continue;
}
//cout << p2 << ' ';
int cnt2 = t1.get(p2);
ll sum = t2.get(p2);
//cout << sum << ' ' << cnt2 << ' ';
sum -= s1;
cnt2 -= (sum + b[p2] - 1) / b[p2];
r = c2, l = c2 - cnt2;
//cout << l << ' ' << r << ' ';
cout << r - l + 1 << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin>>t;
while (t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9700kb
input:
3 5 1 2 3 3 4 2 -2 1 -3 3 1 2 1
output:
1 2 2 2 3
result:
ok 5 number(s): "1 2 2 2 3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 11792kb
input:
3 5 1 2 3 3 4 2 -2 1 3 3 1 2 1
output:
1 2 1 2 1
result:
ok 5 number(s): "1 2 1 2 1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9684kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 11796kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 9696kb
input:
1000 1000 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 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 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 1 1 1 1 ...
output:
946 65 252 410 915 592 983 487 343 899 809 432 586 587 139 464 804 84 476 699 504 149 579 352 375 856 545 166 140 657 568 509 275 710 873 430 537 879 301 1 298 970 923 510 984 642 55 879 941 344 464 788 917 994 571 610 491 442 926 101 986 840 624 613 425 345 816 423 275 221 317 113 386 116 469 260 4...
result:
ok 1000 numbers
Test #6:
score: 0
Accepted
time: 2ms
memory: 11812kb
input:
1000 1000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000...
output:
500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 ...
result:
ok 1000 numbers
Test #7:
score: -100
Wrong Answer
time: 2ms
memory: 9644kb
input:
1000 1000 -485078954 -474724347 -284958745 -99994191 -853392841 -796786314 -87134718 -861459498 -982809180 -184620712 -618476092 -244916830 -349486182 -751407510 -874417202 -419521829 -888338757 -735353446 -426330733 -715383449 -48093437 -359419189 -474876639 -887614191 -157085227 -51186523 -4851821...
output:
2 3 4 5 6 7 8 9 10 11 12 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 51 52 53 54 55 56 57 58 59 60 60 61 62 63 64 65 65 66 67 68 69 70 71 72 73 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 88 89 90 91 92 92 93 94 95 96...
result:
wrong answer 746th numbers differ - expected: '505', found: '506'