放个代码吧,开个坑
#include<bits/stdc++.h>
#define rep(i,a,b) for (register int i=(a);i<=(b);i++)
#define drep(i,a,b) for (register int i=(a);i>=(b);i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
inline ll read()
{
ll sum=0,f=0;char c=getchar();
while (!isdigit(c)) f|=(c=='-'),c=getchar();
while (isdigit(c)) sum=(sum<<1)+(sum<<3)+(c^48),c=getchar();
return f?-sum:sum;
}
inline void setfile()
{
#ifndef ntftxdy
freopen("call.in","r",stdin);
freopen("call.out","w",stdout);
#endif
}
const int N=1000010;
int n,a[N],win[N],pos[N];
struct node{int val,id;bool operator < (const node &a) const{return a.val==val?id<a.id:val<a.val;}};
deque<node>q1,q2;
inline bool cmp(node x,node y){return x.val==y.val?x.id<y.id:x.val<y.val;}
inline bool getmin(){return q1.size()?q2.size()?(cmp(q1.back(),q2.back())):1:0;}
inline bool getmax(){return q1.size()?q2.size()?(!cmp(q1.front(),q2.front())):1:0;}
inline int solve()
{
while (q1.size()) q1.pop_back();
while (q2.size()) q2.pop_back();
rep(i,1,n) q1.push_front((node){a[i],i});
rep(i,1,n-1)
{
node bg=(getmax()?q1:q2).front(),sm=(getmin()?q1:q2).back();
(getmax()?q1:q2).pop_front(),(getmin()?q1:q2).pop_back();
q2.push_back((node){bg.val-sm.val,bg.id});
node _sm=(getmin()?q1:q2).back();
if (_sm.id==bg.id)
{
return n-(i-1)-(q1.size()+q2.size())%2;
}
}
return 1;
}
int main()
{
int T=read();n=read();
rep(i,1,n) a[i]=read();
printf("%d
",solve());
rep(i,1,T-1)
{
int k=read();
for (int j=1,x,y;j<=k;j++) x=read(),y=read(),a[x]=y;
printf("%d
",solve());
}
return 0;
}