Can you answer these queries (HDU 4027)
来源:互联网 发布:瞩目视频会议软件下载 编辑:程序博客网 时间:2024/06/17 00:05
https://vjudge.net/problem/HDU-4027
题意:给一个数组序列, 数组长度为100000,现在有两种操作,
一种操作是将某一个固定区间所有数开方(向下取整),
另一种操作是询问某个区间的所有数字之和。
题意:给一个数组序列, 数组长度为100000,现在有两种操作,
一种操作是将某一个固定区间所有数开方(向下取整),
另一种操作是询问某个区间的所有数字之和。
思路: 当sum[rt] = r-l+1的时候就不需要往下递归了, 其他时候照常
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>#include <vector>#include <cmath>#include <stack>#include <string>#include <sstream>#include <map>#include <set>#define pi acos(-1.0)#define LL long long#define ULL unsigned long long#define inf 0x3f3f3f3f#define INF 1e18#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1using namespace std;typedef pair<int, int> P;const double eps = 1e-10;const int maxn = 1e5 + 5;const int N = 1e4 + 5;const int mod = 1e8;LL sum[maxn<<2]; void Build(int l, int r, int rt){ if (l == r){ scanf("%I64d", &sum[rt]); return; } int mid = (l + r) >> 1; Build(lson); Build(rson); sum[rt] = sum[rt<<1] + sum[rt<<1|1];} LL Query(int L, int R, int l, int r, int rt){ if (L<=l && r<=R) return sum[rt]; int mid = (l + r) >> 1; LL res = 0; if (L <= mid) res += Query(L, R, lson); if (R > mid) res += Query(L, R, rson); return res;}void Update(int L, int R, int l, int r, int rt){ if (L<=l && r<=R && sum[rt] == r-l+1){ return; } if (l == r){ sum[rt] = sqrt(sum[rt]); return ; } int mid = (l + r) >> 1; if (L <= mid) Update(L, R, lson); if (R > mid) Update(L, R, rson); sum[rt] = sum[rt<<1] + sum[rt<<1|1];}int main(void){// freopen("in.txt", "r", stdin); int n, m, cas = 1; while (cin >> n){ Build(1, n, 1); cin >> m; printf("Case #%d:\n", cas++); for (int i = 1; i <= m; i++){ int T, l, r; cin >> T >> l >> r; int a = min(l, r); int b = max(l, r); if (T == 0){ Update(a, b, 1, n, 1); } else { cout << Query(a, b, 1, n, 1) << endl; } } cout << endl; }return 0;}
0 0
- HDU--4027(Can you answer these queries?)
- HDU-4027-Can you answer these queries
- hdu 4027 Can you answer these queries?
- HDU-4027-Can you answer these queries?
- hdu 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- HDU 4027 Can you answer these queries?
- HDU--4027(Can you answer these queries?)
- hdu - 4027 Can you answer these queries?
- hdu-4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- HDU 4027 Can you answer these queries?
- hdu-4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- HDU 4027 Can you answer these queries?
- hdu 4027 Can you answer these queries?
- nginx 出现不该出现的 access.log 日志
- java性能优化注意的几个细节规则
- Java静态类
- Android SD卡状态监听
- U-Box of Bricks
- Can you answer these queries (HDU 4027)
- Android智能心跳微信
- LeetCode #57 | Insert Interval
- NYOJ-305-表达式求值(第四届河南省程序设计大赛C题(模拟+栈||递归)(sscanf函数的应用))
- ios控制器之间传值-单例传值
- Oracle insert大数据量经验之谈
- Docker的使用--制作自己的镜像(四)
- Ubuntu下指令-查看端口的占用情况以及抓包
- 使用MVP+Retrofit+RxJava实现的的Android Demo (下)使用Retrofit+RxJava处理网络请求