UVA - 12532 Interval Product
来源:互联网 发布:mysql存储图片 编辑:程序博客网 时间:2024/06/02 03:28
题目l链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=572&page=show_problem&problem=4150
题目l大意:输入n,m,接下来输入n个数(编号1到n),接下来m个操作 C a b把第a个数改为b,P a b输出Xa到Xb的乘积(0+或-)
线段树的水题,但学校组队赛的时候最后时刻因为测试组数的低级错误错失绝杀。唉。。就这样吧。
贴下自己的代码,写的真好。
#include<iostream>#include<string>using namespace std;const int MAXN = 100010;struct node{int r;int l;int m;}tree[3 * MAXN];int s[MAXN];int father[MAXN];void build(int l, int r, int i){tree[i].l = l; tree[i].r = r;if (l == r){tree[i].m = s[l];father[l] = i;return;}int mid = (l + r) >> 1, ls = i << 1, rs = ls + 1;build(l, mid, ls);build(mid + 1, r, rs);tree[i].m = tree[rs].m*tree[ls].m;}void update(int k, int v, int i){if (tree[i].l == tree[i].r){tree[i].m = v;return;}int mid = (tree[i].l + tree[i].r) >> 1, ls = i << 1, rs = ls + 1;if (k <= mid) update(k, v, ls);else update(k, v, rs);tree[i].m = tree[ls].m*tree[rs].m;}int query(int l, int r, int i){if (tree[i].l == l && tree[i].r == r)return tree[i].m;int mid = (tree[i].l + tree[i].r) >> 1, ls = i << 1, rs = ls + 1;if (r <= mid) return query(l, r, ls);else if (l>mid)return query(l, r, rs);else return query(l, mid, ls)*query(mid + 1, r, rs);}int main(){int n, k;int num;while (cin >> n >> k){for (int i = 1; i <= n; i++){cin >> num;if (num == 0) s[i] = 0;else if (num > 0) s[i] = 1;else s[i] = -1;}build(1, n, 1);char op;int a, b;char str[MAXN] = "0";int kk = 0;for (int i = 1; i <= k; i++){cin >> op;if (op == 'C'){cin >> a >> b;if (b > 0) b = 1;else if (b < 0) b = -1;update(a, b, 1);}else if (op == 'P'){cin >> a >> b;int temp = query(a, b, 1);if (temp == 0) str[kk++] = '0';else if (temp>0) str[kk++] = '+';else if (temp < 0) str[kk++] = '-';}}str[kk] = '\0';cout << str << endl;}}
0 0
- UVA - 12532 Interval Product
- UVA 12532 Interval Product
- UVA - 12532 Interval Product
- UVA - 12532 Interval Product
- UVa 12532 - Interval Product
- UVa Online Judge 12532 - Interval Product
- UVa12532 - Interval Product(Fenwick树)
- UVa12532 - Interval Product(线段树)
- UVA12532 Interval Product(线段树)
- uva Product
- UVALive 6139 Interval Product(树状数组)
- UVa 10106 Product
- UVa OJ 10106-Product
- Uva 10106 Product
- uva 10106 Product
- UVa 10106 - Product
- uva-10106 - Product
- UVA 10106 Product
- (大数据之hadoop)hadoop2.2.0的伪分布式安装说明
- LeetCode OJ Reverse Words in a String
- 机器人技术—基于DELPHI的数据采集与分析类上位机软件的编写
- Xcode下使用SVN教程
- Chat-online
- UVA - 12532 Interval Product
- UVA 10130 SuperSale (DP 01背包)
- time.h
- JS中日期和时间的获取
- 请教一下 服务器的环境是用PHPstudy搭建的用的80口?
- Singleton pattern
- 4-使用synchronized实现线程间通信-实现线程间通信方式(1)
- Decorator pattern
- 大学三年