求调awa
查看原帖
求调awa
246331
mystic_qwq楼主2024/9/3 20:55

很折磨,调了一晚上,只过 subtask 求助喵

link

#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 10;
map<int, int> mp;
set<int> s[N];
int n, m, a[N], pre[N];
struct node {
  int L, R, Mn, Mx, Gcd, MnP;
  node operator+(const node& t) const {
    return {L,
            t.R,
            min(Mn, t.Mn),
            max(Mx, t.Mx),
            __gcd(abs(R - t.L), __gcd(Gcd, t.Gcd)),
            max(MnP, t.MnP)};
  }
} t[N << 2];
#define ls h * 2
#define rs h * 2 + 1
#define tr int h, int l, int r
#define mid (l + r >> 1)
#define lson ls, l, mid
#define rson rs, mid + 1, r
#define all t[h].L = t[h].R = t[h].Mn = t[h].Mx
void pushup(int h) {
  t[h] = t[ls] + t[rs];
}
void build(tr) {
  if (l == r) {
    all = a[l], t[h].Gcd = 0, t[h].MnP = pre[l];
    return;
  }
  build(lson);
  build(rson);
  pushup(h);
}
void modify(tr, int x, int y) {
  if (l == r) {
    all = y, t[h].Gcd = 0, t[h].MnP = pre[l];
    return;
  }
  if (x <= mid)
    modify(lson, x, y);
  else
    modify(rson, x, y);
  pushup(h);
}
node query(tr, int x, int y) {
  if (x <= l && r <= y)
    return t[h];
  if (y <= mid)
    return query(lson, x, y);
  if (x > mid)
    return query(rson, x, y);
  return query(lson, x, y) + query(rson, x, y);
}
int rr, tot;
main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    a[i] = x;
    int& id = mp[x];
    if (!id)
      id = ++tot;
    else
      pre[i] = *s[id].rbegin();
    s[id].insert(i);
  }
  // for(int i=1;i<=tot;++i,cout<<'\n')
  // for(int j:s[i]) cout<<j<<' ';
  build(1, 1, n);
  for (int op, x, y, l, r, k; m--;) {
    cin >> op;
    if (op == 1) {
      cin >> x >> y, x ^= rr, y ^= rr;
      // cout<<x<<' '<<y<<'\n';
      if (y == a[x])
        continue;
      int& ido = mp[a[x]];
      set<int>::iterator it1 = s[ido].erase(s[ido].find(x));
      auto it2 = it1;
      // assert(it1!=s[ido].end());assert(*it1==x);
      // printf("ido:%d (%d)",*it1,ido);
      if (it1 != s[ido].end()) {
        int x = *it1;
        if (it1 != s[ido].begin())
          pre[x] = *--it2;
        else
          pre[x] = 0;
        modify(1, 1, n, x, a[x]);
      }
      // printf("edqwq ");
      int& id = mp[y];
      if (!id)
        id = ++tot, s[id].insert(x), pre[x] = 0;
      else {
        auto it = s[id].insert(x).first, it1 = ++it, it2 = it;
        // printf("id:%d (%d)\n",*it,id);
        if (it != s[id].begin()) {
          pre[x] = *--it2;
        } else
          pre[x] = 0;
        // printf("czc ");
        if (it1 != s[id].end()) {
          int X = *it1;
          pre[X] = x;
          modify(1, 1, n, X, a[X]);
        }
      }
      a[x] = y;
      modify(1, 1, n, x, y);
    } else {
      cin >> l >> r >> k;
      l ^= rr, r ^= rr, k ^= rr;
      if (l > r)
        swap(l, r);
      node res = query(1, 1, n, l, r);
      int Mx = res.Mx, Mn = res.Mn, Gc = res.Gcd, MnP = res.MnP;
#define Cont        \
  {                 \
    cout << "No\n"; \
    continue;       \
  }
      if (MnP >= l || Mx - Mn != k * (r - l) || Gc != k)
        Cont else ++rr, cout << "Yes\n";
    }
  }
}
2024/9/3 20:55
加载中...