QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771357 | #7787. Maximum Rating | acb437 | WA | 2ms | 8056kb | C++14 | 2.5kb | 2024-11-22 12:06:44 | 2024-11-22 12:06:44 |
Judging History
answer
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
typedef pair <int, int> PII;
int n, q, a[N];ll neg;
int len, b[N << 1];
PII qs[N];
struct SegTree
{
#define lc(u) u << 1
#define rc(u) u << 1 | 1
struct node
{
int l, r;
int val;ll sum;
}tr[N << 3];
void pushup(int u){tr[u].val = tr[lc(u)].val + tr[rc(u)].val, tr[u].sum = tr[lc(u)].sum + tr[rc(u)].sum;}
void build(int u, int l, int r)
{
tr[u].l = l, tr[u].r = r;
if(l == r)return;
int m = (l + r) >> 1;
build(lc(u), l, m), build(rc(u), m + 1, r);
}
void modify(int u, int l, int r, int pos, int val)
{
if(tr[u].l == tr[u].r)return (void)(tr[u].val += val, tr[u].sum += b[pos] * val);
int m = (tr[u].l + tr[u].r) >> 1;
if(pos <= m)modify(lc(u), l, r, pos, val);
else modify(rc(u), l, r, pos, val);
pushup(u);
}
int query(int u, ll val)
{
if(tr[u].l == tr[u].r)return val >= tr[u].sum ? tr[u].val : 0;
if(tr[lc(u)].sum < val)return tr[lc(u)].val + query(rc(u), val - tr[lc(u)].sum);
else return query(lc(u), val);
}
#undef lc
#undef rc
}tr;
int main()
{
scanf("%d%d", &n, &q);
for(int i = 1;i <= n;i++)
{
scanf("%d", &a[i]);
if(a[i] >= 0)b[++len] = a[i];
else neg += a[i];
}
for(int i = 1;i <= q;i++)
{
scanf("%d%d", &qs[i].first, &qs[i].second);
if(qs[i].second >= 0)
b[++len] = qs[i].second;
}
sort(b + 1, b + len + 1);
for(int i = 1;i <= n;i++)
{
if(a[i] < 0)continue;
int pos = lower_bound(b + 1, b + len + 1, a[i]) - b;
a[i] = pos, b[pos]--;
}
for(int i = 1;i <= q;i++)
{
if(qs[i].second < 0)continue;
int pos = lower_bound(b + 1, b + len + 1, qs[i].second) - b;
qs[i].second = pos, b[pos]--;
}
for(int i = 1;i <= len;i++)b[i]++;
if(len)
{
tr.build(1, 1, len);
for(int i = 1;i <= n;i++)
if(a[i] > 0)
tr.modify(1, 1, len, a[i], 1);
}
for(int i = 1;i <= q;i++)
{
if(a[qs[i].first] < 0)neg -= a[qs[i].first];
else tr.modify(1, 1, len, a[qs[i].first], -1);
if(qs[i].second < 0)neg += qs[i].second;
else tr.modify(1, 1, len, qs[i].second, 1);
printf("%d\n", tr.query(1, -neg) + 1);
a[qs[i].first] = qs[i].second;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8032kb
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: 8052kb
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: 1ms
memory: 8012kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5952kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 8056kb
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 2 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:
wrong answer 40th numbers differ - expected: '1', found: '2'