QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#778697 | #7787. Maximum Rating | 4eyebird | WA | 32ms | 331444kb | C++17 | 3.8kb | 2024-11-24 15:51:06 | 2024-11-24 15:51:08 |
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
{
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;
}
详细
Test #1:
score: 100
Accepted
time: 24ms
memory: 331260kb
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: 24ms
memory: 331272kb
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: 11ms
memory: 331128kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 32ms
memory: 331444kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 19ms
memory: 331324kb
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 297 969 922 509 983 641 54 878 940 343 463 787 916 993 570 609 490 441 925 100 985 839 623 612 424 344 815 422 274 220 316 112 385 115 468 259 4...
result:
wrong answer 41st numbers differ - expected: '298', found: '297'