Submission #1291032

#TimeUsernameProblemLanguageResultExecution timeMemory
1291032LIASimple game (IZhO17_game)C++17
0 / 100
10 ms15928 KiB
//
// Created by liasa on 14/11/2025.
//

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>

struct Seg {
  vll seg;
  ll sz = 1;
  Seg(ll n) {
    for (; sz < n; sz *= 2)
      ;
    seg.resize(2 * sz);
  }

  void up(ll x, ll v) {
    x += sz;
    seg[x] += v;
    for (x /= 2; x > 0; x /= 2)
      seg[x] = seg[x * 2] + seg[x * 2 + 1];
  }

  ll q(ll l, ll r) {
    l += sz, r += sz;
    ll ans = 0;
    while (l <= r) {
      if ((l & 1))
        ans += seg[l++];
      if (!(r & 1))
        ans += seg[r--];
      l /= 2;
      r /= 2;
    }
    return ans;
  }
};

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  vll h(n);
  ll sz = 1e6+10;
  vll upd(sz + 1);
  for (ll i = 0; i < n; ++i)
    cin >> h[i];
  for (ll i = 1; i < n; ++i) {
    ll a = h[i - 1], b = h[i];
    if (a == b)
      continue;
    if (a > b)
      swap(a, b);
    ll l = a + 1, r = b - 1;
    if (l <=r) {
      upd[l] += 1;
      upd[r + 1] -= 1;
    }
  }
  vll pre(sz + 1);
  pre[0] = upd[0];
  for (ll i = 1; i < sz; ++i)
    pre[i] = pre[i - 1] + upd[i];

  while (m--) {
    ll t, y;
    cin >> t;
    if(t==2) {
      cin>>y;
      cout << pre[y] << "\n";
    }
    else {
      ll a,b;
      cin>>a>>b;
    }
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...