100pts,WA#1求找bug
查看原帖
100pts,WA#1求找bug
743373
Vitamin_B楼主2024/6/30 16:20

rt,https://www.luogu.com.cn/record/163494230,die码:

// # pragma GCC optimize("Ofast,no-stack-protector")
//
// # pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

# include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair <int, int> pii;

struct node {

	int x, id;

	bool operator < (const node& a) const {

		return x < a.x;

	}

} a[1000005];

int n, m, l, r, t, col[1000005], st[1005], ed[1005], k, lazy[1005];

char op;

void init () {

	t = sqrt (n);

	for (int i = 1; i <= t; ++ i)
		st[i] = n / t * (i - 1) + 1, ed[i] = n / t * i;

	ed[t] = n;

	for (int i = 1; i <= t; ++ i) {

		for (int j = st[i]; j <= ed[i]; ++ j)
			col[j] = i;

		sort (a + st[i], a + ed[i] + 1);

	}

	return ;

}

void change (int l, int r) {

	int cl = col[l], cr = col[r];

	if (cl == cr) {

		for (int i = l; i <= r; ++ i)
			a[i].x += k;

		sort (a + st[cl], a + ed[cr] + 1);

		return ;

	}

	for (int i = l; i <= ed[cl]; ++ i)
		a[i].x += k;

	sort (a + st[cl], a + ed[cl] + 1);

	for (int i = cl + 1; i < cr; ++ i)
		lazy[i] += k;

	for (int i = st[cr]; i <= r; ++ i)
		a[i].x += k;

	sort (a + st[cr], a + ed[cr] + 1);

	return ;

}

int find (int l, int r) {

	int cl = col[l], cr = col[r], sum = 0;

	if (cl == cr) {

		for (int i = st[cl]; i <= ed[cr]; ++ i)
			if (a[i].id >= l && a[i].id <= r && a[i].x >= k - lazy[cl])
				++ sum;

		return sum;

	}

	for (int i = st[cl]; i <= ed[cl]; ++ i)
		if (a[i].id >= l && a[i].x >= k - lazy[cl])
			++ sum;

	for (int i = cl + 1; i < cr; ++ i)
		sum += a + ed[i] - lower_bound (a + st[i], a + ed[i] + 1, (node) {k - lazy[i], 0}) + 1;

	for (int i = st[cr]; i <= ed[cr]; ++ i)
		if (a[i].id <= r && a[i].x >= k - lazy[cr])
			++ sum;

	return sum;

}

int main () {

	ios::sync_with_stdio (0);

	cin.tie (0);

	cout.tie (0);

	cin >> n >> m;

	for (int i = 1; i <= n; ++ i)
		cin >> a[i].x, a[i].id = i;

	init ();

	while (m --) {

		cin >> op >> l >> r >> k;

		if (op == 'M')
			change (l, r);
		else
			cout << find (l, r) << '\n';

	}

	return 0;

}

顺便发放福利数据

输入:

100 5
40 7 47 44 52 81 87 60 82 49 40 30 44 90 62 68 81 44 46 17 44 71 89 79 44 95 57 4 6 36 26 61 62 64 14 93 46 35 20 98 55 6 71 9 85 31 1 70 93 100 82 33 57 14 83 56 40 67 27 53 43 39 44 4 59 32 49 72 91 60 67 84 16 64 9 21 59 30 100 34 47 62 10 9 56 88 19 20 16 92 22 11 68 56 62 16 77 94 20 10
M 66 67 1
M 82 97 13
M 14 90 20
M 47 76 7
A 58 86 80

答案:13

我:15

2024/6/30 16:20
加载中...