传送门:点击打开链接
题意:强制在线,单点更新,区间询问,询问这个区间的数从小到大排序后,是否能构成等差为k的等差数列
思路:利用线段树维护数字之和,维护平方和,因为平方和很大所以还要取模,还要维护区间内的最小值
然后每次查询先取出最小值,然后通过等差k求出区间内数字和以及平方和应该等于多少,然后再用线段树查询,看是否等于这么多。
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<functional>
#define fuck(x) cout<<"["<<x<<"]"
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int>PII;
const int MX = 3e5 + 5;
const int mod = 1e9 + 9;
const int INF = 0x3f3f3f3f;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
LL A[MX], inv;
LL s1[MX << 2], s2[MX << 2], MIN[MX << 2];
LL power(LL a, LL b) {
LL ret = 1;
while(b) {
if(b & 1) ret = ret * a % mod;
a = a * a % mod;
b >>= 1;
}
return ret;
}
void push_up(int rt) {
s1[rt] = s1[rt << 1] + s1[rt << 1 | 1];
s2[rt] = (s2[rt << 1] + s2[rt << 1 | 1]) % mod;
MIN[rt] = min(MIN[rt << 1], MIN[rt << 1 | 1]);
}
void build(int l, int r, int rt) {
if(l == r) {
s1[rt] = MIN[rt] = A[l];
s2[rt] = A[l] * A[l] % mod;
return;
}
int m = (l + r) >> 1;
build(lson); build(rson);
push_up(rt);
}
LL query(int id, int L, int R, int l, int r, int rt) {
if(L <= l && r <= R) {
if(id == 1) return s1[rt];
if(id == 2) return s2[rt];
}
int m = (l + r) >> 1; LL ret = 0;
if(L <= m) ret += query(id, L, R, lson);
if(R > m) ret += query(id, L, R, rson);
if(id == 2) ret %= mod;
return ret;
}
void update(int pos, LL val, int l, int r, int rt) {
if(l == r) {
s1[rt] = MIN[rt] = val;
s2[rt] = val * val % mod;
return;
}
int m = (l + r) >> 1;
if(pos <= m) update(pos, val, lson);
else update(pos, val, rson);
push_up(rt);
}
LL query_min(int L, int R, int l, int r, int rt) {
if(L <= l && r <= R) {
return MIN[rt];
}
int m = (l + r) >> 1; LL ret = INF;
if(L <= m) ret = min(ret, query_min(L, R, lson));
if(R > m) ret = min(ret, query_min(L, R, rson));
return ret;
}
LL gets1(LL a, LL l, LL k) {
return a * l + (l - 1) * l / 2 * k;
}
LL gets2(LL a, LL l, LL k) {
LL ret = a * a % mod * l % mod;
ret = (ret + (l - 1) * l % mod * k % mod * a % mod) % mod;
ret += l * (l - 1) % mod * (2 * l - 1) % mod * k % mod * k % mod * inv % mod;
return ret % mod;
}
int main() {
int n, m; //FIN;
while(~scanf("%d%d", &n, &m)) {
inv = power(6, mod - 2);
for(int i = 1; i <= n; i++) {
scanf("%lld", &A[i]);
}
build(1, n, 1);
int cnt = 0;
for(int i = 1; i <= m; i++) {
int op, a, b, c;
scanf("%d%d%d", &op, &a, &b);
a ^= cnt; b ^= cnt;
if(op == 1) update(a, b, 1, n, 1);
else {
bool sign = true;
scanf("%d", &c); c ^= cnt;
int Min = query_min(a, b, 1, n, 1);
LL s = gets1(Min, b - a + 1, c);
if(s != query(1, a, b, 1, n, 1)) sign = false;
if(sign && gets2(Min, b - a + 1, c) != query(2, a, b, 1, n, 1)) sign = false;
if(sign) cnt++, printf("Yes\n");
else printf("No\n");
}
}
}
return 0;
}