CF896E Welcome home, Chtholly(暴力卡常)

AC = O ( n m ) + 快读 + 循环展开 + 指针 + 优化开关 \operatorname{AC} = O(nm) + \text{快读} + \text{循环展开} + \text{指针} + \text{优化开关}

时间复杂度 O ( ) O(\text{松})

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;
inline int read() {
	int x = 0, f = 0; char ch = 0;
	while (!isdigit(ch)) f |= ch == '-', ch = getchar();
	while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}
int a[N];
int main() {
	int n = read(), m = read();
	for (int i = 1; i <= n; ++i) a[i] = read();
	while (m--) {
		int opt = read(), l = read(), r = read(), x = read();
		auto ap = a + l;
		int len = r - l + 1;
		if (opt == 1) {
			while (len % 4) {
				--len;
				ap[len] -= ap[len] > x ? x : 0;
			}
			len /= 4;
			while (len--) {
				ap[0] -= ap[0] > x ? x : 0;
				ap[1] -= ap[1] > x ? x : 0;
				ap[2] -= ap[2] > x ? x : 0;
				ap[3] -= ap[3] > x ? x : 0;
				ap += 4;
			}
		} else {
			int ans = 0;
			while (len % 4) {
				--len;
				ans += ap[len] == x;
			}
			len /= 4;
			while (len--) {
				ans += (ap[0] == x) + (ap[1] == x) + (ap[2] == x) + (ap[3] == x);
				ap += 4;
			}
			printf("%d\n", ans);
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39984146/article/details/107690716