QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#762930 | #7787. Maximum Rating | lei | WA | 2ms | 7944kb | C++20 | 2.6kb | 2024-11-19 17:20:45 | 2024-11-19 17:20:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define PII pair<long long ,long long>
#define int long long
const int N = 2e6 + 10,MOD=1004535809,B=13331,inf=1e9+10,mod=998244353;
int dx[]={1,-1,0,0};
int dy[]={0,0,-1,1},idx;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
inline void write( int x ) {
if ( x < 0 ) putchar ('-'), x = -x;
if ( x > 9 ) write ( x / 10 ); putchar ( x % 10 | 48 );
}
int n,m,root;
int sum[N<<2],sz[N<<2];
struct node{
int l,r;
}tr[N<<2];
void update(int &u,int l,int r,int x,int v,int k)
{
if(!u) u=++idx;
if(l==r) sum[u]+=v,sz[u]+=k;
else
{
int mid=l+r>>1;
if(mid>=x) update(tr[u].l,l,mid,x,v,k);
else update(tr[u].r,mid+1,r,x,v,k);
sum[u]=sum[tr[u].l]+sum[tr[u].r];
sz[u]=sz[tr[u].l]+sz[tr[u].r];
}
}
int find(int u,int l,int r,int k)
{
if(sum[u]<=k) return -1;
if(l==r) return k/l+1;
else
{
int mid=l+r>>1;
if(sum[tr[u].l]>k) return find(tr[u].l,l,mid,k);
else return sz[tr[u].l]+find(tr[u].r,mid+1,r,k-sum[tr[u].l]);
}
}
void lei()
{
n=read();
int q=read(),cnt=0;
vector<int>a(n+1);
int res=0;
for(int i=1;i<=n;i++)
{
a[i]=read();
if(a[i]>0) update(root,1,inf,a[i],a[i],1),cnt++;
else res-=a[i];
}
while(q--)
{
int x=read(),v=read();
int k=a[x];
if(k>0)
{
update(root,1,inf,k,-k,-1);
if(v>=0)
update(root,1,inf,v,v,1);
else
{
res-=v;
cnt--;
}
}
else //k为负数
{
res+=k;
if(v>=0)
{
update(root,1,inf,v,v,1);
cnt++;
}
else res-=v;
}
//cout<<cnt<<endl;
a[x]=v;
int p=find(root,1,inf,res);
// cout<<res<<" "<<sum[1]<<endl;
// if(!p) cout<<cnt+1<<endl;
// cout<<p<<endl;
// cout<<cnt<<endl;
cout<<cnt-(p==-1?0:cnt-p+1)+1<<endl;
}
}
signed main()
{
// std::ios::sync_with_stdio(false);
// std::cin.tie(0);
// std::cout.tie(0);
// freopen("in.txt", "rt", stdin);
// freopen("out.txt", "wt", stdout);
int Tao=1;
//Tao=read();
while(Tao--) lei();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7644kb
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: 7696kb
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: 7580kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 2ms
memory: 7648kb
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: -100
Wrong Answer
time: 2ms
memory: 7944kb
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:
wrong answer 394th numbers differ - expected: '500', found: '501'