constint N = 1e5 + 5, M = 320; int n, q, a[N], b[N * 2], cur; structQuery { std::string op; int x, y, p; } Q[N]; int num, st[M], ed[M], belong[N], f[M][N]; intcalc(int l, int r, int pos){ int x = belong[l], y = belong[r]; if (x == y) { int res = 0; for (int i = l; i <= r; ++ i) { res += a[i] == pos; } return res; } int res = f[y - 1][pos] - f[x][pos]; for (int i = l; i <= ed[x]; ++ i) { res += a[i] == pos; } for (int i = st[y]; i <= r; ++ i) { res += a[i] == pos; } return res; } signedmain(){ std::cin.tie(nullptr)->sync_with_stdio(false); std::cin >> n >> q; for (int i = 1; i <= n; ++ i) { std::cin >> a[i]; } std::copy(a + 1, a + n + 1, b + 1); cur = n; for (int i = 1; i <= q; ++ i) { std::string op; int x, y, p; std::cin >> op; if (op == "Q") { std::cin >> x >> y >> p; Q[i] = {op, x, y, p};
} else { std::cin >> x >> p; Q[i] = {op, x, 0, p}; b[++ cur] = p; } } std::sort(b + 1, b + cur + 1); cur = std::unique(b + 1, b + cur + 1) - (b + 1); for (int i = 1; i <= n; ++ i) { a[i] = std::lower_bound(b + 1, b + cur + 1, a[i]) - b; } num = sqrt(n); for (int i = 1; i <= num; ++ i) { st[i] = n / num * (i - 1) + 1; ed[i] = n / num * i; } ed[num] = n; for (int i = 1; i <= num; ++ i) { std::fill(belong + st[i], belong + ed[i] + 1, i); for (int j = st[i]; j <= ed[i]; ++ j) { ++ f[i][a[j]]; } for (int j = 1; j <= cur; ++ j) { f[i][j] += f[i - 1][j]; } } for (int i = 1; i <= q; ++ i) { auto [op, x, y, p] = Q[i]; if (op == "Q") { int pos = std::lower_bound(b + 1, b + cur + 1, p) - b; std::cout << calc(x, y, pos) << '\n'; } else { int pos = belong[x]; int kk = std::lower_bound(b + 1, b + cur + 1, p) - b; for (int j = pos; j <= num; ++ j) { -- f[j][a[x]]; ++ f[j][kk]; } a[x] = kk; } } return0; }
constint N = 150005; int n, q, a[N]; int sum[400][400]; signedmain(){ std::cin.tie(nullptr)->sync_with_stdio(false); std::cin >> n >> q; int m = sqrt(n); for (int i = 1; i <= n; ++ i) { std::cin >> a[i]; for (int j = 1; j <= m; ++ j) { sum[j][i % j] += a[i]; } } while (q -- ) { std::string op; int x, y; std::cin >> op >> x >> y; if (op == "A") { if (x <= m) { std::cout << sum[x][y] << '\n'; } else { int ans = 0; for (int i = y; i <= n; i += x) { ans += a[i]; } std::cout << ans << '\n'; } } else { for (int i = 1; i <= m; ++ i) { sum[i][x % i] -= a[x] - y; } a[x] = y; } } return0; }
constint N = 2e5 + 5, M = 450; int n, q, a[N]; int num, st[M], ed[M], belong[N], step[N], to[N]; signedmain(){ std::cin.tie(nullptr)->sync_with_stdio(false);
std::cin >> n; for (int i = 1; i <= n; ++ i) { std::cin >> a[i]; } num = sqrt(n); for (int i = 1; i <= num; ++ i) { st[i] = n / num * (i - 1) + 1; ed[i] = n / num * i; } ed[num] = n; for (int i = 1; i <= num; ++ i) { std::fill(belong + st[i], belong + ed[i] + 1, i); for (int j = ed[i]; j >= st[i]; -- j) { if (j + a[j] > ed[i]) { step[j] = 1; to[j] = j + a[j]; } else { step[j] = step[j + a[j]] + 1; to[j] = to[j + a[j]]; } } } std::cin >> q; while (q -- ) { int op, x, y; std::cin >> op >> x; ++ x; if (op == 2) { std::cin >> y; if (a[x] == y) { continue; } a[x] = y; for (int j = ed[belong[x]]; j >= st[belong[x]]; -- j) { if (j + a[j] > ed[belong[x]]) { step[j] = 1; to[j] = j + a[j]; } else { step[j] = step[j + a[j]] + 1; to[j] = to[j + a[j]]; } } } else { int res = 0; while (x <= n) { res += step[x]; x = to[x]; } std::cout << res << '\n'; } } return0; }
constint N = 5e5 + 5; int n, m, a[N], b[N], cur; std::vector< int > pos[N]; int st[N], ed[N], belong[N], num; int f[720][720], cnt[N], idx[N]; intQuery(int l, int r){ int x = belong[l], y = belong[r], ans = 0; if (x == y) { for (int i = l; i <= r; ++ i) { cnt[a[i]] = 0; } for (int i = l; i <= r; ++ i) { ans = std::max(ans, ++cnt[a[i]]); } return ans; } ans = f[x + 1][y - 1]; for (int i = l; i <= ed[x]; ++ i) { while (idx[i] + ans < pos[a[i]].size() && pos[a[i]][idx[i] + ans] <= r) { ++ ans; } } for (int i = st[y]; i <= r; ++ i) { while (idx[i] - ans >= 0 && pos[a[i]][idx[i] - ans] >= l) { ++ ans; } } return ans; } signedmain(){ std::cin.tie(nullptr)->sync_with_stdio(false);
std::cin >> n >> m; for (int i = 1; i <= n; ++ i) { std::cin >> a[i]; } std::copy(a + 1, a + n + 1, b + 1); std::sort(b + 1, b + n + 1); cur = std::unique(b + 1, b + n + 1) - (b + 1); for (int i = 1; i <= n; ++ i) { a[i] = std::lower_bound(b + 1, b + cur + 1, a[i]) - b; pos[a[i]].push_back(i); idx[i] = (int)pos[a[i]].size() - 1; } num = sqrt(n); for (int i = 1; i <= num; ++ i) { st[i] = n / num * (i - 1) + 1; ed[i] = n / num * i; } ed[num] = n; for (int i = 1; i <= num; ++ i) { for (int j = st[i]; j <= ed[i]; ++ j) { belong[j] = i; } memset(cnt, 0, sizeof cnt); for (int j = i; j <= num; ++ j) { f[i][j] = f[i][j - 1]; for (int k = st[j]; k <= ed[j]; ++ k) { f[i][j] = std::max(f[i][j], ++ cnt[a[k]]); } } } int lastans = 0; while (m -- ) { int l, r; std::cin >> l >> r; l ^= lastans; r ^= lastans; std::cout << (lastans = Query(l, r)) << '\n'; } return0; }