QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607729#7787. Maximum RatingfengyuyueRE 2ms9848kbC++143.6kb2024-10-03 16:01:072024-10-03 16:01:11

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 16:01:11]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:9848kb
  • [2024-10-03 16:01:07]
  • 提交

answer

#include<bits/stdc++.h>

#define int long long
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define gc getchar
#define pc putchar
#define pii pair<int,int>
#define pil pair<int,long long>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define For(i,l,r) for(int i=(l);i<=(r);i++)
#define IFor(i,r,l) for(int i=(r);i>=(l);i--)
#define for_son(u) for(int e=head[u];e;e=nxt[e])
#define eps (1e-8)
#define INF 0x3f3f3f3f

using namespace std;

char aa;

namespace ljh
{

namespace IO
{
    int rd()
    {
        int x=0,f=1;
        char ch=gc();
        while(!isdigit(ch)){
            if(ch=='-') f=-1;
            ch=gc();
        }
        while(isdigit(ch)){
            x=x*10+ch-'0';
            ch=gc();
        }
        return x*f;
    }
    void wr(int x,char ch)
    {
        if(x<0) x=-x,pc('-');
        static char st[24];
        int top=0;
        do{
            st[top++]=x%10+'0',x/=10;
        }while(x);
        while(top) pc(st[--top]);
        pc(ch);
    }
    ll ll_rd()
    {
        ll x=0;int f=1;
        char ch=gc();
        while(!isdigit(ch)){
            if(ch=='-') f=-1;
            ch=gc();
        }
        while(isdigit(ch)){
            x=x*10+ch-'0';
            ch=gc();
        }
        return x*f;
    }
    void ll_wr(ll x,char ch)
    {
        if(x<0) x=-x,pc('-');
        static char st[24];
        int top=0;
        do{
            st[top++]=x%10+'0',x/=10;
        }while(x);
        while(top) pc(st[--top]);
        pc(ch);
    }
}

using namespace IO;

const int N=2e5+5,mod=0;

int n,q,a[N],raw[N<<1],b[N],p[N],m;
ll sum;

struct Tree{
	int l,r,num;
	ll sum;
	#define ls (p<<1)
	#define rs (p<<1|1)
	#define l(p) t[p].l
	#define r(p) t[p].r
	#define sum(p) t[p].sum
	#define num(p) t[p].num
}t[N<<3];

void lisan()
{
	sort(raw+1,raw+m+1);
	m=unique(raw+1,raw+m+1)-(raw+1);
}

int idx(int x)
{
	return lower_bound(raw+1,raw+m+1,x)-raw;
}

void build(int p,int l,int r)
{
	t[p]={l,r,0,0ll};
	if(l==r){
		return ;
	}
	int mid=(l+r)>>1;
	build(ls,l,mid);
	build(rs,mid+1,r);
}

void up(int p)
{
	num(p)=num(ls)+num(rs);
	sum(p)=sum(ls)+sum(rs);
}

void change(int p,int x,int v)
{
	if(l(p)==r(p)){
		num(p)+=v;
		sum(p)+=1ll*l(p)*v;
		return ;
	}
	int mid=(l(p)+r(p))>>1;
	if(x<=mid) change(ls,x,v);
	else change(rs,x,v);
	up(p);
}

int ask(int p,ll sum)
{
	if(sum(p)<=sum) return num(p);
	if(l(p)==r(p)) return 0;
//	int mid=(l(p)+r(p))>>1;
	if(sum<sum(ls)) return ask(ls,sum);
	else return num(ls)+ask(rs,sum-sum(ls));
}

void solve()
{
	n=rd(),q=rd();
	For(i,1,n){
		a[i]=rd();
		if(a[i]>0) raw[++m]=a[i];
		else sum+=a[i];
	}
	For(i,1,q){
		p[i]=rd(),b[i]=rd();
		if(b[i]>0) raw[++m]=b[i];
	}
	lisan();
	build(1,1,m);
	For(i,1,n){
		if(a[i]>0) change(1,idx(a[i]),1);
	}
	For(i,1,q){
		if(a[p[i]]<=0){
			sum-=a[p[i]];
		}
		else{
			change(1,idx(a[p[i]]),-1);
		}
		if(b[i]<=0){
			sum+=b[i];
		}
		else{
			change(1,idx(b[i]),1);
		}
		a[p[i]]=b[i];
		int siz=ask(1,-sum);
		wr(siz+1,'\n');
	}
}

void main()
{
	int T=1;
	while(T--) solve();
}

/*
3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1
*/

}

char bb;

signed main()
{
//  freopen("1.in","r",stdin);
//  freopen("1.out","w",stdout);    
//  int st=clock();
    ljh::main();
//  int ed=clock();
//  cerr<<ed-st<<"ms"<<endl;
//      cerr<<(&bb-&aa)/1024/1024<<"MB"<<endl;
//  fclose(stdin);
//  fclose(stdout);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7752kb

input:

3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1

output:

1
2
2
2
3

result:

ok 5 number(s): "1 2 2 2 3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 9848kb

input:

3 5
1 2 3
3 4
2 -2
1 3
3 1
2 1

output:

1
2
1
2
1

result:

ok 5 number(s): "1 2 1 2 1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5760kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: -100
Runtime Error

input:

1 1
-1000000000
1 -1000000000

output:


result: