QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#661524 | #7787. Maximum Rating | hbhz_zcy | WA | 1ms | 7964kb | C++14 | 2.5kb | 2024-10-20 16:39:04 | 2024-10-20 16:39:04 |
Judging History
answer
//g++ k.cpp -o k -g -std=c++14 -O0 -Wall -fsanitize=undefined
#include <iostream>
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
int qd()
{
int rt = 0, ng = 0;
char c = getchar();
while (c < '0' || c > '9')
ng ^= (c == '-'), c = getchar();
while ('0' <= c && c <= '9')
rt = (rt << 3) + (rt << 1) + c - 48, c = getchar();
return ng ? -rt : rt;
}
const int maxn = 4e5 + 10;
int N, Q, a[maxn], ls[maxn], lstop = 0, qt[maxn][2];
LL nsum;
struct node
{
int xv, cnt;
LL v;
} f[maxn << 4];
void pushup(int t) { f[t].v = f[t << 1].v + f[t << 1 | 1].v, f[t].cnt = f[t << 1].cnt + f[t << 1 | 1].cnt; }
void build(int t, int l, int r)
{
// printf("%d:%d %d\n",t,l,r);
if (l >= r)
{
f[t].xv = ls[l];
return;
}
int m = (l + r) >> 1;
build(t << 1, l, m), build(t << 1 | 1, m + 1, r);
f[t].xv = max(f[t << 1].xv, f[t << 1 | 1].xv);
}
void change(int t, int l, int r, int v, int num)
{
if (l >= r)
{
f[t].v += 1LL * ls[l] * num, f[t].cnt += num;
return;
}
int m = (l + r) >> 1;
f[t << 1].xv >= v ? change(t << 1, l, m, v, num) : change(t << 1 | 1, m + 1, r, v, num);
pushup(t);
}
int ask(int t, int l, int r, LL v)
{
if (v >= f[t].v)
return f[t].cnt;
if (l == r)
return ls[l] ? v / ls[l] : 0;
int m = (l + r) >> 1;
return v <= f[t].v ? ask(t << 1, l, m, v) : f[t << 1].cnt + ask(t << 1 | 1, m + 1, r, v - f[t << 1].v);
}
int main()
{
// freopen("test.in","r",stdin);
N = qd(), Q = qd();
for (int i = 1; i <= N; i++)
{
a[i] = qd();
if (a[i] <= 0)
nsum += a[i];
else
ls[++lstop] = a[i];
}
for (int i = 1; i <= Q; i++)
{
qt[i][0] = qd(), qt[i][1] = qd();
if (qt[i][1] > 0)
ls[++lstop] = qt[i][1];
}
sort(ls + 1, ls + lstop + 1);
lstop = unique(ls + 1, ls + lstop + 1) - ls - 1; //printf("%d %d\n\n",lstop,nsum);
build(1, 1, lstop);
for (int i = 1; i <= N; i++)
change(1, 1, lstop, a[i], 1);
for (int i = 1; i <= Q; i++)
{
int t = qt[i][0], x = qt[i][1];
if (a[t] <= 0)
nsum -= a[t];
else
change(1, 1, lstop, a[t], -1);
if (x <= 0)
nsum += x;
else
change(1, 1, lstop, x, 1);
a[t] = x;
printf("%d\n", ask(1, 1, lstop, -nsum) + 1);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7952kb
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: 7952kb
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: 7964kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 7888kb
input:
1 1 -1000000000 1 -1000000000
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'