QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#768870 | #7787. Maximum Rating | mobbb | WA | 1ms | 3836kb | C++20 | 3.0kb | 2024-11-21 14:58:25 | 2024-11-21 14:58:26 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
const int N = 4e5 + 7;
int val[N], m;
struct info{
ll val, t;
};
info operator + (const info &l,const info &r){
info b = {0, 0};
if (l.t && r.t){
b.val = l.val + r.val;
b.t = l.t + r.t;
}else if (l.t){
b = l;
}else if (r.t){
b = r;
}
return b;
}
struct node{
info s;
}seg[N * 4];
void update(int id){
seg[id].s = seg[2 * id].s + seg[2 * id + 1].s;
}
void build(int id,int l,int r){
if (l > r) {
return;
}
if (l == r){
seg[id].s = {val[l], 0};
}else{
int mid = (l + r) / 2;
build(id * 2,l,mid);
build(id * 2 + 1,mid + 1,r);
update(id);
}
}
void change(int id,int l,int r,int pos,int t){
if (l > r) {
return;
}
if (l == r){
seg[id].s.t = t;
}else{
int mid = (l + r) / 2;
if (pos <= mid) {
change(2 * id,l,mid,pos,t);
}
else{
change(2 * id + 1,mid + 1,r,pos,t);
}
update(id);
}
}
ll query(int id,int l,int r,ll sum){
if (l > r) {
return 0;
}
if (l == r){
if (sum >= seg[id].s.val){
return seg[id].s.t;
}else{
return 0;
}
}
int mid = (l + r) / 2;
ll cur = 0;
if (seg[id * 2].s.val >= sum){
cur += query(id * 2, l, mid, sum);
}else{
cur += seg[id * 2].s.t;
sum -= cur;
cur += query(id * 2 + 1, mid + 1, r, sum);
}
return cur;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, q;
std::cin >> n >> q;
std::vector<int> a(n + 1);
ll sum = 0;
std::map<int, std::pair<std::vector<int>, int>> pos;
for (int i = 1; i <= n; i++){
std::cin >> a[i];
if (a[i] > 0){
val[++m] = a[i];
}else{
sum += (-a[i]);
}
}
std::vector<std::pair<int, int>> evt(q);
for (int i = 0; i < q; i++){
int x, v;
std::cin >> x >> v;
evt[i] = {x, v};
if (v > 0){
val[++m] = v;
}
}
std::sort(val + 1, val + m + 1);
for (int i = 1; i <= m; i++){
pos[val[i]].first.push_back(i);
pos[val[i]].second = -1;
}
build(1, 1, m);
for (int i = 1; i <= n; i++){
if (a[i] <= 0) continue;
int idx = pos[a[i]].first[++pos[a[i]].second];
change(1, 1, m, idx, 1);
}
for (auto [x, v] : evt){
if (a[x] > 0 && v > 0){
int curpos = pos[a[x]].first[pos[a[x]].second--];
change(1, 1, m, curpos, 0);
// std::cout << seg[1].s.val << ' ';
int nextpos = pos[v].first[++pos[v].second];
change(1, 1, m, nextpos, 1);
a[x] = v;
}else if (a[x] > 0 && v <= 0){
int curpos = pos[a[x]].first[pos[a[x]].second--];
change(1, 1, m, curpos, 0);
sum += -v;
a[x] = v;
}else if (a[x] <= 0 && v > 0){
sum -= (-a[x]);
int nextpos = pos[v].first[++pos[v].second];
change(1, 1, m, nextpos, 1);
a[x] = v;
}else if (a[x] <= 0 && v <= 0){
sum -= (-a[x]);
sum += (-v);
a[x] = v;
}
std::cout << query(1, 1, m, sum) + 1 << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3836kb
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: 0ms
memory: 3620kb
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: 3620kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3596kb
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: 1ms
memory: 3512kb
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: 1ms
memory: 3756kb
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'