QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578953 | #7787. Maximum Rating | Iron_gainer | WA | 1ms | 5640kb | C++20 | 1.5kb | 2024-09-20 23:41:11 | 2024-09-20 23:41:11 |
Judging History
answer
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 200005;
const ll L = 1;
const ll R = 1e9;
ll a[N];
ll sum = 0;
ll cnt = 0;
ll pcnt = 0;
struct node
{
ll cnt;
ll sum;
int left;
int right;
}t[40*N];
void update(int &idx,int l, int r,ll p,ll num,ll sign)
{
if (idx == 0)
idx = ++cnt;
t[idx].cnt += sign;
t[idx].sum += sign * num;
if (l == r) return;
int mid = (l + r) >> 1;
if (num <= mid)
update(t[idx].left, l, mid, 2 * p, num, sign);
else
update(t[idx].right, mid + 1, r, 2 * p + 1, num, sign);
}
int query(int idx, int l, int r, ll tsum)
{
if (l == r)
{
return (tsum <= 0 ? 0 : ((tsum + l - 1) / l));
}
int mid = (l + r) >> 1;
if (t[t[idx].right].sum >= tsum)
return query(t[idx].right, mid + 1, r, tsum);
else
return query(t[idx].left, l, mid, tsum - t[t[idx].right].sum) + t[t[idx].right].cnt;
}
int main()
{
int n, q;
cin >> n >> q;
int root = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] > 0)
{
update(root, L, R, 0, a[i], 1);
pcnt++;
}
sum += a[i];
}
for (int i = 1; i <= q; i++)
{
int pos, num;
cin >> pos >> num;
if (a[pos] > 0)
{
update(root, L, R, 0, a[pos], -1);
pcnt--;
}
if (num > 0)
{
update(root, L, R, 0, num, 1);
pcnt++;
}
sum -= a[pos];
sum += num;
a[pos] = num;
int temp = query(1, L, R, sum);
//cout << pcnt + 1 - temp << endl;
}
if (n == 200000 && q == 200000)
{
cout << cnt << endl;
}
/*cerr << cnt << endl;*/
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5640kb
input:
3 5 1 2 3 3 4 2 -2 1 -3 3 1 2 1
output:
result:
wrong answer Answer contains longer sequence [length = 5], but output contains 0 elements