QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771355 | #7787. Maximum Rating | acb437 | RE | 1ms | 7956kb | C++14 | 2.5kb | 2024-11-22 12:05:19 | 2024-11-22 12:05:20 |
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]++;
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: 7892kb
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: 7956kb
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: 7904kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Runtime Error
input:
1 1 -1000000000 1 -1000000000