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 .
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 integers n and m denoting the length of the sequence and the number of operations.
The second line contains n separated integers a1,…,an ( ∀1≤i≤n,0≤ai<231 ).
Each of the following m lines represents one operation ( 1≤x≤y≤n,0≤t<231 ).
It is guaranteed that T=100 , ∑n≤1000000, ∑m≤1000000 .
The first line contains two integers n and m denoting the length of the sequence and the number of operations.
The second line contains n separated integers a1,…,an ( ∀1≤i≤n,0≤ai<231 ).
Each of the following m lines represents one operation ( 1≤x≤y≤n,0≤t<231 ).
It is guaranteed that T=100 , ∑n≤1000000, ∑m≤1000000 .
Output
For every operation of type
1
or
2
, print one line containing the answer to the corresponding query.
Sample Input
1 5 5 1 2 3 4 5 1 1 5 2 1 5 0 3 5 3 1 1 5 2 1 5
Sample Output
5 15 3 12HintPlease use efficient IO method
这个输入外挂真的是懵逼了。。。。。
#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);
}
}
}
}