50pts
查看原帖
50pts
1397857
Max_hmt楼主2024/8/1 11:32

红绿相间

#include<bits/stdc++.h>
using namespace std;
long long n, m, k, a[3000005], h = 1, t, op, x, head, tail, sum;
int main()
{
	cin >> n >> m >> k;
	head = -k, tail = k, h = 1, t = n, sum = n;
	for (long long i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for (long long i = 1; i <= m; i++) {
		cin >> op;
		if (op == 1) {
			cin >> x;
			head -= x;
			tail -= x;
			while (a[t] > tail&&h+1!=t)
				t--;
			while (a[h] < head&&h+1!=t)
				h++;
		}
		if (op == 2) {
			cin >> x;
			head += x;
			tail += x;
			while (a[h] < head&&h+1!=t)
				h++;
			while (a[t] > tail&&h+1!=t)
				t--;
		}
		if (op == 3) {
			cout << t - h + 1 << endl;
		}
	}
	return 0;
}

玄关

2024/8/1 11:32
加载中...