-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF2057D.cpp
57 lines (56 loc) · 1.09 KB
/
CF2057D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define N 800001
int ans[N],t0[N],t1[N],t2[N],t3[N];
void update(int u, int l, int r, int x, int v)
{
if (l==r)
{
ans[u] = 0;
t0[u]=v+l;
t1[u] = -v+l;
t2[u] = v-l;
t3[u] = -v-l;
return;
}
int m = (l+r)/2;
if (x<=m)
{
update(u*2, l,m,x,v);
}
else
{
update(u*2+1, m+1, r, x,v);
}
ans[u]=max({ans[u*2],ans[u*2+1],t0[u*2]+t3[u*2+1],t1[u*2]+t2[u*2+1]});
t0[u]=max(t0[u*2],t0[u*2+1]);
t1[u]=max(t1[u*2],t1[u*2+1]);
t2[u]=max(t2[u*2],t2[u*2+1]);
t3[u]=max(t3[u*2],t3[u*2+1]);
}
int main()
{
#ifdef CODEBLOCKS
freopen("in.txt", "r", stdin);
#endif // CODEBLOCKS
int t;
cin>>t;
for(int ti=0;ti<t;ti++)
{
int n,q,u,v;
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>v;
update(1,1,n,i,v);
}
cout<<ans[1]<<endl;
for(int i=0;i<q;i++)
{
cin>>u>>v;
update(1,1,n,u,v);
cout<<ans[1]<<endl;
}
}
}