Description
Input
Output
输出m行,每行一个整数,代表输入中每次程序变化后系统所需要的空闲内存单位数。
Sample Input
2 3
1 4
1 4
2 2 1
2 1 1
1 1 1
Sample Output
2
3
1
Data Constraint
对于30%的数据,有1<=n,m<=1000
对于100%的数据,有1<=n,m<=100000
Hint
解题思路
Code
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,g[200005];
struct nd1{
long long x,y;
int c,rk;
}a[200005],f[800005],b[200005];
bool cmp(nd1 x,nd1 y){return x.y < y.y;}
void change(int l,int r,int k,int u,long long x,long long y)
{
if (l == r && l == u)
{
f[k].x = x;
f[k].y = y;
return;
}
int mid = l + r >> 1;
if (u <= mid) change(l,mid,k << 1,u,x,y);
else change(mid + 1,r,k << 1 | 1,u,x,y);
f[k].x = f[k << 1].x + f[k << 1 | 1].x;
f[k].y = max(f[k << 1].y,f[k << 1 | 1].y - f[k << 1].x);
}
int main()
{
int sum = 0;
scanf("%d%d",&n,&m);
for (int i = 1; i <= n; i++) scanf("%lld%lld",&a[i].x,&a[i].y),a[i].rk = i,b[i] = a[i];
for (int i = 1; i <= m; i++) scanf("%d%lld%lld",&a[i + n].c,&a[i + n].x,&a[i + n].y),a[i + n].rk = i + n,b[i + n] = a[i + n];
sort(a + 1,a + 1 + n + m,cmp);
for (int i = 1; i <= n + m; i++) g[a[i].rk] = i;
for (int i = 1; i <= n; i++) change(1,n + m,1,g[b[i].rk],b[i].x,b[i].y);
for (int i = 1; i <= m; i++)
{
change(1,n + m,1,g[b[i + n].c],0,0);
change(1,n + m,1,g[b[i + n].rk],b[i + n].x,b[i + n].y);
g[b[i + n].c] = g[b[i + n].rk];
printf("%lld
",f[1].y);
}
}