标签:tac php parent algorithm text == http highlight color
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 16260 Accepted Submission(s): 3809
#include <stdio.h> #include <iostream> #include <algorithm> #include <cstdlib> #include <sstream> #include <numeric> #include <cstring> #include <bitset> #include <string> #include <deque> #include <stack> #include <cmath> #include <queue> #include <set> #include <map> using namespace std; #define INF 0x3f3f3f3f #define LC(x) (x<<1) #define RC(x) ((x<<1)+1) #define MID(x,y) ((x+y)>>1) #define CLR(arr,val) memset(arr,val,sizeof(arr)) #define FAST_IO ios::sync_with_stdio(false);cin.tie(0); typedef pair<int, int> pii; typedef long long LL; const double PI = acos(-1.0); const int N = 100010; struct seg { int l, mid, r; LL sum; int cnt; }; seg T[N << 2]; LL arr[N]; void pushup(int k) { T[k].sum = T[LC(k)].sum + T[RC(k)].sum; } void build(int k, int l, int r) { T[k].l = l; T[k].r = r; T[k].mid = MID(l, r); T[k].sum = T[k].cnt = 0; if (l == r) T[k].sum = arr[l]; else { build(LC(k), l, T[k].mid); build(RC(k), T[k].mid + 1, r); pushup(k); } } void SQ(int k, int l, int r) { if (l <= T[k].l && T[k].r <= r) ++T[k].cnt; if (T[k].cnt >= 7) return; if (T[k].l == T[k].r) { T[k].sum = sqrt(T[k].sum); return ; } if (r <= T[k].mid) SQ(LC(k), l, r); else if (l > T[k].mid) SQ(RC(k), l, r); else SQ(LC(k), l, T[k].mid), SQ(RC(k), T[k].mid + 1, r); pushup(k); } LL query(int k, int l, int r) { if (l <= T[k].l && T[k].r <= r) return T[k].sum; else { if (r <= T[k].mid) return query(LC(k), l, r); else if (l > T[k].mid) return query(RC(k), l, r); else return query(LC(k), l, T[k].mid) + query(RC(k), T[k].mid + 1, r); } } int main(void) { int i; int tcase = 1; int n, m; while (~scanf("%d", &n)) { for (i = 1; i <= n; ++i) scanf("%I64d", &arr[i]); build(1, 1, n); scanf("%d", &m); printf("Case #%d:\n", tcase++); while (m--) { int l, r, ops; scanf("%d%d%d", &ops, &l, &r); if (l > r) swap(l, r); if (!ops) SQ(1, l, r); else printf("%I64d\n", query(1, l, r)); } puts(""); } return 0; }
HDU 4027 Can you answer these queries?(线段树区间开方)
标签:tac php parent algorithm text == http highlight color
原文地址:http://www.cnblogs.com/Blackops/p/6978394.html