花神游历各国
#include<iostream> #include<cstring> #include<algorithm> #include<queue> #include<cmath> #define maxn 5000100 using namespace std; typedef long long ll; ll tree[maxn]; ll arr[maxn]; int vis[maxn]; int root = 1; int push_down(int node, int be, int en) { if (be == en) { tree[node] = sqrt(tree[node]); if (tree[node] == 1 || tree[node] == 0) vis[node] = 1; return 0; } int l = 2 * node; int r = 2 * node + 1; int mid = (be + en) / 2; if(!vis[l]) push_down(l, be, mid); if(!vis[r]) push_down(r, mid + 1, en); tree[node] = tree[l] + tree[r]; if (vis[l] && vis[r]) vis[node] = 1; } ll update(int node, int be, int en, int LL, int RR) { if (RR < be || LL > en) return 0; else if (be >= LL && RR >= en) { if (vis[node]) return tree[node]; else { push_down(node, be, en); return tree[node]; } } int l = 2 * node; int r = 2 * node + 1; int mid = (be + en) / 2; update(l, be, mid, LL, RR); update(r, mid + 1, en, LL, RR); tree[node] = tree[l] + tree[r]; return 0; } int bulit(int node, int be, int en) { if (be == en) { tree[node] = arr[be]; return 0; } int l = 2 * node; int r = 2 * node + 1; int mid = (be + en) / 2; bulit(l, be, mid); bulit(r, mid + 1, en); tree[node] = tree[l] + tree[r]; return tree[node]; } ll qurry(int node, int be, int en, int LL, int RR) { if (RR < be || LL > en) return 0; else if (be >= LL && RR >= en) return tree[node]; int l = 2 * node; int r = 2 * node + 1; ll val1 = 0; ll val2 = 0; int mid = (be + en) / 2; val1 = qurry(l, be, mid, LL, RR); val2 = qurry(r, mid + 1, en, LL, RR); return val1 + val2; } int n, m; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &arr[i]); } bulit(1, 1, n); int t; int be, en; ll vv; scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d", &t); if (t == 2) { scanf("%d %d", &be, &en); update(1, 1, n, be, en); } else if (t == 1) { scanf("%d %d", &be, &en); ll val = qurry(1, 1, n, be, en); printf("%lld\n", val); } } }
寻找真正的热爱