QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607753#7787. Maximum RatingfengyuyueWA 2ms11900kbC++143.6kb2024-10-03 16:06:432024-10-03 16:06:44

Judging History

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

  • [2024-10-03 16:06:44]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11900kb
  • [2024-10-03 16:06:43]
  • 提交

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)
{
	if(l>r) return ;
	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 min(num(p),sum/l(p));
	}
//	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();
}

/*
5 1
1 1 1 1 1
1 -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: 1ms
memory: 9876kb

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: 1ms
memory: 7676kb

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: 7772kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

1000 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

946
65
252
410
915
592
983
487
343
899
809
432
586
587
139
464
804
84
476
699
504
149
579
352
375
856
545
166
140
657
568
509
275
710
873
430
537
879
301
1
298
970
923
510
984
642
55
879
941
344
464
788
917
994
571
610
491
442
926
101
986
840
624
613
425
345
816
423
275
221
317
113
386
116
469
260
4...

result:

ok 1000 numbers

Test #6:

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

input:

1000 1000
1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000...

output:

500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
...

result:

ok 1000 numbers

Test #7:

score: -100
Wrong Answer
time: 2ms
memory: 11900kb

input:

1000 1000
-485078954 -474724347 -284958745 -99994191 -853392841 -796786314 -87134718 -861459498 -982809180 -184620712 -618476092 -244916830 -349486182 -751407510 -874417202 -419521829 -888338757 -735353446 -426330733 -715383449 -48093437 -359419189 -474876639 -887614191 -157085227 -51186523 -4851821...

output:

2
3
4
5
6
7
8
9
10
11
12
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
51
52
53
54
55
56
57
58
59
60
60
61
62
63
64
65
65
66
67
68
69
70
71
72
73
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
88
89
90
91
92
92
93
94
95
96...

result:

wrong answer 746th numbers differ - expected: '505', found: '506'