QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#679709 | #7787. Maximum Rating | PDF_vegetable | RE | 0ms | 7988kb | C++14 | 2.2kb | 2024-10-26 18:12:31 | 2024-10-26 18:12:31 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define MAXN 200000
#define INF 1000000000
#define LL long long
#define Pr pair<int,int>
#define X first
#define Y second
LL read(){
LL x=0,F=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*F;
}
int n,q,a[MAXN+5];
int du[MAXN+5],qx[MAXN+5],qv[MAXN+5];
int m,val[MAXN+5];
LL fsum;
struct Seg_tree{
LL sum[(MAXN<<2)+5];
int cnt[(MAXN<<2)+5];
void Insert(int x,int l,int r,int pos,int val,int f){
if(l==r){
sum[x]+=f*val;
cnt[x]+=f;
return ;
}
int mid=(l+r)>>1;
if(pos<=mid)Insert(x<<1,l,mid,pos,val,f);
else Insert(x<<1|1,mid+1,r,pos,val,f);
sum[x]=sum[x<<1]+sum[x<<1|1];
cnt[x]=cnt[x<<1]+cnt[x<<1|1];
}
int findnum(int x,int l,int r,LL S){
if(l==r)return min(S/val[l],1LL*cnt[x]);
int mid=(l+r)>>1;
if(S<=sum[x<<1])return findnum(x<<1,l,mid,S);
else return findnum(x<<1|1,mid+1,r,S-sum[x<<1])+cnt[x<<1];
}
}T;
int main(){
n=read(),q=read();
for(int i=1;i<=n;i++){
a[i]=read();
if(a[i]>0)val[++m]=a[i];
else fsum+=a[i];
}
for(int i=1;i<=q;i++){
qx[i]=read();
qv[i]=read();
if(qv[i]>0)val[++m]=qv[i];
}
sort(val+1,val+m+1);
m=unique(val+1,val+m+1)-val-1;
for(int i=1;i<=n;i++)
if(a[i]>0){
int v=lower_bound(val+1,val+m+1,a[i])-val;
//printf("Insert %d %d-%d\n",i,v,a[i]);
T.Insert(1,1,m,v,a[i],1);
}
for(int i=1;i<=q;i++){
if(a[qx[i]]<=0)fsum-=a[qx[i]];
else{
int v=lower_bound(val+1,val+m+1,a[qx[i]])-val;
T.Insert(1,1,m,v,a[qx[i]],-1);
}
a[qx[i]]=qv[i];
if(qv[i]<=0)fsum+=a[qx[i]];
else{
int v=lower_bound(val+1,val+m+1,a[qx[i]])-val;
T.Insert(1,1,m,v,a[qx[i]],1);
}
//printf("::%lld\n",-fsum);
printf("%d\n",T.findnum(1,1,m,-fsum)+1);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5836kb
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: 3732kb
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: 0ms
memory: 7988kb
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