QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578953#7787. Maximum RatingIron_gainerWA 1ms5640kbC++201.5kb2024-09-20 23:41:112024-09-20 23:41:11

Judging History

你现在查看的是最新测评结果

  • [2024-09-20 23:41:11]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5640kb
  • [2024-09-20 23:41:11]
  • 提交

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