daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma GCC optimize("Ofast,no-stack-protector")
  2. #pragma GCC target("avx")
  3.  
  4. #include <cstdio>
  5. #include <cctype>
  6.  
  7. #define fin stdin
  8. //FILE *fin = fopen("a.in", "r");
  9.  
  10. #define BUF_SIZE 1 << 16
  11.  
  12. int pos = BUF_SIZE;
  13. char buf[BUF_SIZE];
  14.  
  15. inline char nextch() {
  16.     if (pos == BUF_SIZE) fread(buf, BUF_SIZE, 1, fin), pos = 0;
  17.     return buf[pos++];
  18. }
  19.  
  20. inline int read() {
  21.     char ch;
  22.     while (!isdigit(ch = nextch()));
  23.     int x = ch - '0';
  24.     while (isdigit(ch = nextch())) x = 10 * x + ch - '0';
  25.     return x;
  26. }
  27.  
  28. #define MAXN 100005
  29.  
  30. int v[MAXN];
  31.  
  32. int main() {
  33.     int n = read();
  34.     int m = read();
  35.  
  36.     for (int i = 1; i <= n; i++)
  37.         v[i] = read();
  38.  
  39.     for (; m; m--) {
  40.         int t = read();
  41.         int l = read();
  42.         int r = read();
  43.         int x = read();
  44.  
  45.         if (t == 1) {
  46.           if (r-l+1&1) v[r] -= v[r]>x?x:0, --r;
  47.             for (register int i = l; i <= r; i += 2) {
  48.                 v[i] -= v[i] > x ? x : 0;
  49.                 v[i + 1] -= v[i + 1] > x ? x : 0;
  50.             }
  51.         } else {
  52.             int ans = 0;
  53.             if (r-l+1&1)ans+=v[r]==x, --r;
  54.             for (register int i = l; i <= r; i += 2) {
  55.               ans+=v[i]==x;
  56.               ans+=v[i+1]==x;
  57.             }
  58.             printf("%d\n", ans);
  59.         }
  60.     }
  61.  
  62.     return 0;
  63. }
RAW Paste Data
Top