QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#778695 | #7787. Maximum Rating | 4eyebird | RE | 23ms | 331224kb | C++17 | 3.8kb | 2024-11-24 15:50:31 | 2024-11-24 15:50:31 |
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
constexpr int MX = 5;
class DST
{
public:
DST()
{
idx = 1;
Mxn = MX;
lc.assign(7e6, 0);
rc.assign(7e6, 0);
sg.assign(7e6, 0);
stm.assign(7e6, 0);
}
void update(int p, ll x)
{
int rt = 1;
_update(p, p, x, 0, Mxn, rt);
}
void update(int l, int r, ll x)
{
int rt = 1;
_update(l, r, x, 0, Mxn, rt);
}
ll query(int p)
{
return _query(p, 0, Mxn, 1);
}
private:
int idx, Mxn;
vector<ll> stm, sg;
vector<int> lc, rc;
void _update(ll L, ll R, ll x, ll l, ll r, int &pt)
{
if (!pt)
pt = ++idx;
int p = pt;
stm[p] += x * (R - L + 1);
if (L <= l && r <= R)
{
sg[p] += x;
return;
}
ll mid = (l + r) >> 1;
if (R <= mid)
_update(L, R, x, l, mid, lc[p]);
else if (L > mid)
_update(L, R, x, mid + 1, r, rc[p]);
else
{
_update(L, mid, x, l, mid, lc[p]);
_update(mid + 1, R, x, mid + 1, r, rc[p]);
}
}
ll _query(ll px, ll l, ll r, int p)
{
if (!p) return 0;
if (l == px && r == px)
return stm[p];
ll mid = (l + r) >> 1;
ll ret = sg[p];
if (px <= mid)
ret += _query(px, l, mid, lc[p]);
else if (px > mid)
ret += _query(px, mid + 1, r, rc[p]);
return ret;
}
};
map<int, int> Ct;
ll a[200010];
void solve()
{
int n, q;
cin >> n >> q;
DST T1, T2;
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]]++;
T1.update(a[i], MX, a[i]);
T2.update(a[i], MX, 1);
}
}
while (q--)
{
int p;
ll x;
cin >> p >> x;
if (a[p] < 0)
{
Sf -= a[p];
a[p] = x;
}
else
{
Cz--;
Sz -= a[p];
Ct[a[p]]--;
T1.update(a[p], MX, -a[p]);
T2.update(a[p], MX, -1);
a[p] = x;
}
if (x <= 0)
Sf += x;
else
{
Cz++;
Sz += x;
Ct[x]++;
T1.update(x, MX, x);
T2.update(x, MX, 1);
}
if (Sf == 0)
{
cout << "1\n";
continue;
}
if (Sz + Sf <= 0)
{
cout << Cz + 1 << '\n';
continue;
}
auto check = [&](int px) -> bool
{
ll qy = T1.query(px);
if (Sf + qy >= 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 mxc = T2.query(l);
ll ca = T1.query(l) + Sf;
int cty = Ct[l];
while (cty-- && ca > 0)
{
ca -= l;
mxc--;
}
int ans = 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: 23ms
memory: 331156kb
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: 12ms
memory: 331224kb
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: -100
Runtime Error
input:
1 1 1000000000 1 1000000000