HDU 5306 Gorgeous Sequence
来源:互联网 发布:那个软件有柯南漫画 编辑:程序博客网 时间:2024/06/09 22:25
Gorgeous Sequence
Problem Description
There is a sequence a of length n . We use ai to denote the i -th element in this sequence. You should do the following three types of operations to this sequence.
0 x y t : For every x≤i≤y , we use min(ai,t) to replace the original ai 's value.
1 x y : Print the maximum value of ai that x≤i≤y .
2 x y : Print the sum of ai that x≤i≤y .
Input
The first line of the input is a single integer T , indicating the number of testcases.
The first line contains two integersn and m denoting the length of the sequence and the number of operations.
The second line containsn separated integers a1,…,an (∀1≤i≤n,0≤ai<231 ).
Each of the followingm lines represents one operation (1≤x≤y≤n,0≤t<231 ).
It is guaranteed thatT=100 , ∑n≤1000000, ∑m≤1000000 .
The first line contains two integers
The second line contains
Each of the following
It is guaranteed that
Output
For every operation of type 1 or 2 , print one line containing the answer to the corresponding query.
Sample Input
15 51 2 3 4 51 1 52 1 50 3 5 31 1 52 1 5
Sample Output
515312HintPlease use efficient IO method
参考了这位犇的代码:http://blog.csdn.net/keshuai19940722/article/details/47343557
这个输入外挂真的是懵逼了。。。。。
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define endl "\n"#define lson(u) (u << 1)#define rson(u) (u << 1 | 1)const int MAXN = 1000000 + 5;/******************************* * 输入外挂,只适合数字 *******************************//*********** input *************/char *ch, *ch1, buf[40*1024000+5], buf1[40*1024000+5];void read(int &x) { for (++ch; *ch <= 32; ++ch); for (x = 0; '0' <= *ch; ch++) x = x * 10 + *ch - '0';}/******************************/struct segNode{ int L, R, Max, T, Cnt; ll Sum;}node[MAXN << 2];inline void PushUp(int u) { node[u].Max = max(node[lson(u)].Max, node[rson(u)].Max); node[u].Sum = node[lson(u)].Sum + node[rson(u)].Sum; node[u].Cnt = node[lson(u)].Cnt + node[rson(u)].Cnt;}inline void Update(int u, int alter) { if(node[u].T != 0 && node[u].T <= alter) return ; node[u].T = alter; if(node[u].Cnt != node[u].R - node[u].L + 1) { node[u].Max = alter; node[u].Sum += 1LL * (node[u].R - node[u].L + 1 - node[u].Cnt) * alter; node[u].Cnt = node[u].R - node[u].L + 1; }}void dfs(int u, int alter) { if(node[u].Max < alter) return ; node[u].T = 0; if(node[u].L == node[u].R) { node[u].Sum = node[u].Max = node[u].Cnt = 0; return ; } dfs(lson(u), alter); dfs(rson(u), alter); PushUp(u);}inline void PushDown(int u) { if(node[u].T == 0) return ; Update(lson(u), node[u].T); Update(rson(u), node[u].T);}void build(int u, int l, int r) { node[u].L = l, node[u].R = r, node[u].T = 0; if(l == r) { //scanf("%d", &node[u].Max); //cin >> node[u].Max; read(node[u].Max); node[u].T = node[u].Sum = node[u].Max; node[u].Cnt = 1; return ; } int mid = (l + r) >> 1; build(lson(u), l, mid); build(rson(u), mid+1, r); PushUp(u);}void Modify(int u, int l, int r, int alter) { if(node[u].Max <= alter) return ; if(l <= node[u].L && node[u].R <= r) { dfs(u, alter); Update(u, alter); return ; } int mid = (node[u].L + node[u].R) >> 1; PushDown(u); if(l <= mid) { Modify(lson(u), l, r, alter); } if(r > mid) { Modify(rson(u), l, r, alter); } PushUp(u);}void Query(int u, int l, int r, ll& sum, int& mx) { if(l <= node[u].L && node[u].R <= r) { sum += node[u].Sum; mx = max(mx, node[u].Max); return ; } int mid = (node[u].L + node[u].R) >> 1; PushDown(u); if(l <= mid) { Query(lson(u), l, r, sum, mx); } if(r > mid) { Query(rson(u), l, r, sum, mx); } PushUp(u);}int main() { //ios::sync_with_stdio(false); ch = buf - 1; ch1 = buf1 - 1; fread(buf, 1, 1000 * 35 * 1024, stdin); int T, n, m, op, x, y, num, mx; ll sum; read(T); //cout << T << " MotherFucker" << endl; //cin >> T; while(T--) { //cin >> n >> m; read(n), read(m); build(1, 1, n); for(int i = 0; i < m; ++i) { read(op), read(x), read(y); //cin >> op >> x >> y; if(op) { sum = mx = 0; Query(1, x, y, sum , mx); if(op == 1) { printf("%d\n", mx); //cout << mx << endl; } else { //cout << sum << endl; printf("%lld\n", sum); } } else { read(num); //cin >> num; Modify(1, x, y, num); } } }}
0 0
- hdu 5306 Gorgeous Sequence
- hdu 5306 Gorgeous Sequence
- HDU 5306 Gorgeous Sequence
- hdu 5306 Gorgeous Sequence
- hdu 5306 Gorgeous Sequence(线段树)
- HDU 5306 Gorgeous Sequence(线段树)
- HDU 5306 Gorgeous Sequence 线段树
- HDU 5306 Gorgeous Sequence(线段树)
- [线段树 区间最值操作] HDU 5306 Gorgeous Sequence
- Gorgeous Sequence
- Gorgeous Sequence
- HDOJ 5306 Gorgeous Sequence 线段树
- [HDU] 5306 Gorgeous Sequence [区间取min&求和&求max][线段树]
- hdu5306 Gorgeous Sequence
- [题解]hdu5306 Gorgeous Sequence
- 【Gorgeous】
- hdu5306 Gorgeous Sequence(线段树:复杂区间更新)
- hdu 1711 Number Sequence
- opencv nRows = I.rows * channels 问题
- unit9
- J2EE性能优化(4)Tomcat和JVM调优
- 【GDOI2017模拟一试4.11】颜色树
- centos6.5下安装tomcat并运行
- HDU 5306 Gorgeous Sequence
- 12 个 CSS 高级技巧汇总
- PHP正则表达式常用例子
- CvMat,Mat,Iplimage的理解和应用
- Linux内核中的等待队列--init_waitqueue_head等
- Hello World
- C++的Json解析库:jsoncpp
- View角度与弧度(转载)-2
- 解决url中有空格 在encode的时候HttpURLConnection识别不了的问题