QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#778900 | #7787. Maximum Rating | 4eyebird | WA | 28ms | 331316kb | C++17 | 3.7kb | 2024-11-24 16:43:06 | 2024-11-24 16:43:11 |
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 = 1e9 + 10;
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 if (a[p] > 0)
{
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
{
if (T1.query(px) + Sf >= 0)
return true;
else
return false;
};
int l = 1, r = MX;
while (l < r)
{
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
l--;
ll mxc = T2.query(l);
ll ca = -Sf - T1.query(l);
if (ca > 0)
mxc += ca / (l + 1);
cout << mxc + 1 << '\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: 28ms
memory: 331316kb
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: 19ms
memory: 331240kb
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: 12ms
memory: 331276kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 3ms
memory: 331128kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 11ms
memory: 331200kb
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 1 298 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 ...
result:
wrong answer 42nd numbers differ - expected: '970', found: '1000'