QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#778383 | #7787. Maximum Rating | 4eyebird | WA | 1ms | 5684kb | C++17 | 4.6kb | 2024-11-24 14:21:59 | 2024-11-24 14:22:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Buff ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
//#define int long long
int idx;
struct node
{
int l, r;
int ct, lzc;
ll sm, lz;
} tr[7000000];
map<int, int> Ct;
constexpr int MX = 5;
void update(int l, int r, ll x, int L = 0, int R = MX, int p = 1)
{
if (x > 0)
tr[p].ct += (r - l + 1);
else if (x < 0)
tr[p].ct -= (r - l + 1);
tr[p].sm += x * (r - l + 1);
if (l <= L && R <= r)
{
if (x > 0)
tr[p].lzc++;
else if (x < 0)
tr[p].lzc--;
tr[p].lz += x;
return;
}
int mid = (L + R) >> 1;
if (l <= mid)
{
if (tr[p].l == 0)
tr[p].l = idx++;
update(l, min(mid, r), x, L, mid, tr[p].l);
}
if (r > mid)
{
if (tr[p].r == 0)
tr[p].r = idx++;
update(max(l, mid + 1), r, x, mid + 1, R, tr[p].r);
}
}
int query(int px, int L = 0, int R = MX, int p = 1)
{
if (L == px && R == px)
return p;
int mid = (L + R) >> 1;
if (tr[p].lz > 0 || tr[p].lzc != 0)
{
if (tr[p].l == 0)
tr[p].l = idx++;
if (tr[p].r == 0)
tr[p].r = idx++;
tr[tr[p].l].sm += tr[p].lz * (mid - L + 1);
tr[tr[p].r].sm += tr[p].lz * (R - mid);
tr[tr[p].l].lz += tr[p].lz;
tr[tr[p].r].lz += tr[p].lz;
tr[p].lz = 0;
tr[tr[p].l].ct += tr[p].lzc * (mid - L + 1);
tr[tr[p].r].ct += tr[p].lzc * (R - mid);
tr[tr[p].l].lzc += tr[p].lzc;
tr[tr[p].r].lzc += tr[p].lzc;
tr[p].lzc = 0;
}
if (px <= mid)
{
if (tr[p].l == 0)
{
return -1;
}
return query(px, L, mid, tr[p].l);
}
else if (px > mid)
{
if (tr[p].r == 0)
{
return -1;
}
return query(px, mid + 1, R, tr[p].r);
}
}
ll a[200010];
void solve()
{
idx = 2;
int n, q;
cin >> n >> q;
ll Sf = 0, Sz = 0, Cz = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] < 0)
Sf += a[i];
else if (a[i] > 0)
{
Cz++;
Sz += a[i];
Ct[a[i]]++;
update(a[i], MX, a[i]);
}
}
while (q--)
{
int p;
ll x;
cin >> p >> x;
if (a[p] < 0)
{
if (x <= 0)
{
Sf -= a[p];
Sf += x;
a[p] = x;
}
else
{
Sf -= a[p];
a[p] = x;
Ct[x]++;
Cz++;
Sz += x;
update(x, MX, x);
}
}
else
{
Cz--;
Sz -= a[p];
Ct[a[p]]--;
update(a[p], MX, -a[p]);
if (x <= 0)
{
Sf += x;
a[p] = x;
}
else
{
a[p] = x;
Ct[x]++;
Cz++;
Sz += x;
update(x, MX, x);
}
}
if (Sf == 0)
{
cout << "1\n";
continue;
}
if (Sz + Sf <= 0)
{
cout << Cz + 1 << '\n';
continue;
}
auto check = [&](int px) -> bool
{
int qy = query(px);
if (qy == -1)
{
if (Sf >= 0)
return true;
else
return false;
}
if (Sf + tr[qy].sm < 0)
return true;
else
return false;
};
int l = 0, r = MX;
while (l < r)
{
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
int qy = query(l);
int mxc = tr[qy].ct;
ll ca = tr[qy].sm + Sf;
int cty = Ct[l];
while (cty--)
{
if (ca - l < 0)
break;
ca -= l;
mxc--;
}
int ans = Cz - (Cz - mxc) + 1;
cout << ans << '\n';
}
}
signed main()
{
#ifdef YGYYYGJ
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
Buff;
int _T_ = 1;
while (_T_--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3716kb
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: 5612kb
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: 3624kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5608kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 5684kb
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:
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 100...
result:
wrong answer 1st numbers differ - expected: '946', found: '1000'