传送门
分析
用平方和哈希,线段树维护即可
代码
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int N = 5e5 + 10;
const ll mod = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a) {
char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {if (c == '-')f = -1; c = getchar();}
while (isdigit(c)) {x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
int gcd(int a, int b) {return (b > 0) ? gcd(b, a % b) : a;}
int n;
ll a[N];
struct Node {
int l, r;
ll max, min;
ll sum;
} tr[N * 4];
void push(int u) {
tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
tr[u].max = max(tr[u << 1].max , tr[u << 1 | 1].max);
tr[u].min = min(tr[u << 1].min , tr[u << 1 | 1].min);
}
void build(int u, int l, int r) {
tr[u] = {l, r};
if (l == r) {
tr[u].sum = a[l] * a[l];
tr[u].max = tr[u].min = a[l];
return;
}
int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
push(u);
}
void modify(int u, int p, ll x) {
if (tr[u].l == tr[u].r) {
tr[u].sum = x * x;
tr[u].max = tr[u].min = x;
tr[u].min = tr[u].min = x;
return;
}
int mid = tr[u].l + tr[u].r >> 1;
if (p <= mid) modify(u << 1, p, x);
else modify(u << 1 | 1, p, x);
push(u);
}
ll query_max(int u, int l, int r) {
if (tr[u].l >= l && tr[u].r <= r) {
return tr[u].max;
}
int mid = tr[u].l + tr[u].r >> 1;
ll res = -INF;
if (l <= mid) res = query_max(u << 1, l, r);
if (r > mid) res = max(res, query_max(u << 1 | 1, l, r));
return res;
}
ll query_min(int u, int l, int r) {
if (tr[u].l >= l && tr[u].r <= r) {
return tr[u].min;
}
int mid = tr[u].l + tr[u].r >> 1;
ll res = INF;
if (l <= mid) res = query_min(u << 1, l, r);
if (r > mid) res = min(query_min(u << 1 | 1, l, r), res);
return res;
}
ll getsum(ll l, ll r) {
return r * (r + 1) * (2 * r + 1) - l * (l + 1) * (2 * l + 1) ;
}
ll query(int u, int l, int r) {
if (tr[u].l >= l && tr[u].r <= r) {
return tr[u].sum;
}
int mid = tr[u].l + tr[u].r >> 1;
ll res = 0;
if (l <= mid) res = query(u << 1, l, r);
if (r > mid) res += query(u << 1 | 1, l, r);
return res;
}
int main() {
int n, m;
read(n), read(m);
for (int i = 1; i <= n; i++) read(a[i]);
build(1, 1, n);
while (m--) {
int op, x, y;
read(op), read(x), read(y);
if (op == 1) modify(1, x, y);
else {
ll ppp = query(1, x, y);
ll MIN = query_min(1, x, y), MAX = query_max(1, x, y);
ll pppp = getsum(MIN - 1, MAX);
// cout << MIN << ' ' << MAX << ' ' << pppp << endl;
if (ppp * 6 == pppp) puts("damushen");
else puts("yuanxing");
}
}
return 0;
}
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/