QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#757700 | #7787. Maximum Rating | jr_zlw# | WA | 1ms | 5944kb | C++17 | 2.2kb | 2024-11-17 12:27:03 | 2024-11-17 12:27:04 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(a,b,c) for(int c(a);c<=(b);++c)
#define drep(a,b,c) for(int c(a);c>=(b);--c)
using namespace std;
inline int read()
{
int res=0;char ch=getchar();bool f=0;while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
while(ch<='9'&&ch>='0')res=res*10+(ch^48),ch=getchar();return f?-res:res;
}
typedef long long ll;
int n;
const int N=4e5+10;int a[N];ll K;int S;
unsigned seed=998244353;
unsigned rnd()
{
seed^=seed<<19;
seed^=seed>>13;
seed^=seed<<7;
return seed;
}
struct Node
{
int l,r,siz,val;ll sm;unsigned key;
}t[N];int Rt,T1,T2,T3,T4,T5,cnt;
inline void update(int x)
{
t[x].sm=t[t[x].l].sm+t[t[x].r].sm+t[x].val;
t[x].siz=t[t[x].l].siz+t[t[x].r].siz+1;
}
inline void split(int cur,int k,int &x,int &y)
{
if(!cur){x=y=0;return;}
if(t[cur].val<=k){x=cur;split(t[cur].r,k,t[x].r,y);update(x);}
else{y=cur;split(t[cur].l,k,x,t[cur].l);update(y);}
}
inline int merge(int x,int y)
{
if(!x||!y)return x|y;
if(t[x].key<t[y].key){t[x].r=merge(t[x].r,y);update(x);return x;}
t[y].l=merge(x,t[y].l);update(y);return y;
}
inline void Split(int cur,ll k,int &x,int &y)
{
if(!cur){x=y=0;return;}
if(t[t[cur].l].sm+t[cur].val<=k)
{
x=cur;Split(t[cur].r,k-t[t[cur].l].sm-t[t[cur].l].val,t[cur].r,y);
update(x);
}
else
{
y=cur;Split(t[cur].l,k,x,t[cur].l);
update(y);
}
}
inline int Node(int v)
{
t[++cnt].val=v;t[cnt].siz=1;
t[cnt].sm=v;t[cnt].key=rnd();
return cnt;
}
inline void ins(int k)
{
split(Rt,k,T1,T2);
Rt=merge(merge(T1,Node(k)),T2);
}
inline void del(int k)
{
split(Rt,k,T1,T3);
split(T1,k-1,T1,T2);
T2=merge(t[T2].l,t[T2].r);
Rt=merge(merge(T1,T2),T3);
}
int main()
{
n=read();int Q=read();
rep(1,n,i)
{
a[i]=read();
if(a[i]==0)continue;
if(a[i]<0)
{
K-=a[i];
}
else
{
ins(a[i]);
++S;
}
}
while(Q--)
{
int i=read(),x=read();
if(a[i]<0)
{
K+=a[i];
}
else if(a[i]>0)
{
del(a[i]);
--S;
}
a[i]=x;
if(a[i]<0)
{
K-=a[i];
}
else if(a[i]>0)
{
ins(a[i]);
++S;
}
Split(Rt,K,T1,T2);
int T=t[T2].siz;
Rt=merge(T1,T2);
printf("%d\n",S-T+1);
}
}
/*
3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5888kb
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: 3776kb
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: 5876kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5944kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 5888kb
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 67 252 410 917 593 984 487 343 900 809 432 586 587 139 465 805 85 477 699 505 149 579 352 375 856 546 166 140 657 568 509 275 710 876 430 537 881 301 1 298 970 923 510 984 643 58 881 942 346 465 788 918 995 571 611 491 442 926 103 988 840 624 613 425 347 817 423 275 221 318 114 387 116 470 261 4...
result:
wrong answer 2nd numbers differ - expected: '65', found: '67'