Skip to content

Instantly share code, notes, and snippets.

@zimpha
Created December 5, 2017 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zimpha/f07c0dd1caace394a7947e4a638788d7 to your computer and use it in GitHub Desktop.
Save zimpha/f07c0dd1caace394a7947e4a638788d7 to your computer and use it in GitHub Desktop.
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#include <cstdio>
#include <cctype>
#define fin stdin
//FILE *fin = fopen("a.in", "r");
#define BUF_SIZE 1 << 16
int pos = BUF_SIZE;
char buf[BUF_SIZE];
inline char nextch() {
if (pos == BUF_SIZE) fread(buf, BUF_SIZE, 1, fin), pos = 0;
return buf[pos++];
}
inline int read() {
char ch;
while (!isdigit(ch = nextch()));
int x = ch - '0';
while (isdigit(ch = nextch())) x = 10 * x + ch - '0';
return x;
}
#define MAXN 100005
int v[MAXN];
int main() {
int n = read();
int m = read();
for (int i = 1; i <= n; i++)
v[i] = read();
for (; m; m--) {
int t = read();
int l = read();
int r = read();
int x = read();
if (t == 1) {
if (r-l+1&1) v[r] -= v[r]>x?x:0, --r;
for (register int i = l; i <= r; i += 2) {
v[i] -= v[i] > x ? x : 0;
v[i + 1] -= v[i + 1] > x ? x : 0;
}
} else {
int ans = 0;
if (r-l+1&1)ans+=v[r]==x, --r;
for (register int i = l; i <= r; i += 2) {
ans+=v[i]==x;
ans+=v[i+1]==x;
}
printf("%d\n", ans);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment