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
58
59
60
61
62
63
64
65
|
#include <bits/stdc++.h>
using namespace std;
#define ls now<<1
#define rs now<<1|1
#define endl "\n"
#define lowbit(x) ((x)&(-x))
typedef long long ll;
const int N=2e5+7, mod=1e9+7;
struct Node{
int l,r,cnt;
ll sum;
}tr[N*2*32];
int tot=0,rt=0;
ll a[N];
void add(int& now,int l,int r,int x,int v){
if(!now)now=++tot;
tr[now].sum+=x*v;
tr[now].cnt+=v;
if(l==r)return;
ll mid=(l+r)>>1;
if(x<=mid)add(tr[now].l,l,mid,x,v);
else add(tr[now].r,mid+1,r,x,v);
}
int ask(int now,int l,int r,ll x){
if(!now)return 0;
if(tr[now].sum<=x)return 0;
if(l==r)return tr[now].cnt-(x/l);
ll mid=(l+r)>>1;
if(tr[tr[now].l].sum>x)return tr[tr[now].r].cnt+ask(tr[now].l,l,mid,x);
else return ask(tr[now].r,mid+1,r,x-tr[tr[now].l].sum);
}
void solve(){
int n,q,cnt=0;
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]>0)++cnt;
add(rt,-1e9,1e9,a[i],1);
}
while(q--){
ll x,v;
cin>>x>>v;
if(a[x]>0)--cnt;
add(rt,-1e9,1e9,a[x],-1);
a[x]=v;
add(rt,-1e9,1e9,a[x],1);
if(a[x]>0)++cnt;
int tmp=ask(rt,-1e9,1e9,0);
cout<<cnt-tmp+1<<endl;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t=1;
// cin>>t;
while(t--)solve();
return 0;
}
|