QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#639258 | #7787. Maximum Rating | Hide_In_The_Shadow | WA | 1ms | 3736kb | C++23 | 3.1kb | 2024-10-13 18:35:12 | 2024-10-13 18:35:13 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
template<typename T>void read(T &x){
x=0;
char c=getchar();
T ret=0;
while(!isdigit(c))ret|=!(c^'-'),c=getchar();
while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
if(ret)x=(~x)+1;
}
template<typename T,typename ...Args>
void read(T &x,Args &...xs){
read(x);read(xs...);
}
template<typename T>void print(T x){
if(x<0)putchar('-'),x=(~x)+1;
if(x>9)print(x/10);
putchar((x-x/10*10)^48);
}
template<typename T>void wr1(T x){
print(x);putchar(' ');
}
template<typename T>void wr2(T x){
print(x);putchar('\n');
}
int n,q;
mt19937 rnd(time(0));
struct FHQ{
int root,x,y,z,cnt;
struct node{
ll v,sum;
int l,r,key,siz;
}t[414514];
int newnode(ll v){
t[++cnt].v=v;
t[cnt].sum=v;
t[cnt].key=rnd();
t[cnt].siz=1;
return cnt;
}
void pushup(int x){
t[x].siz=t[t[x].l].siz+t[t[x].r].siz+1;
t[x].sum=t[t[x].l].sum+t[t[x].r].sum+t[x].v;
}
void split(int now,ll v,int &x,int &y){
if(!now)x=y=0;
else{
if(t[now].v<=v){
x=now;
split(t[now].r,v,t[now].r,y);
}
else{
y=now;
split(t[now].l,v,x,t[now].l);
}
pushup(now);
}
}
int merg(int x,int y){
if(!x||!y)return x|y;
else{
if(t[x].key>t[y].key){
t[x].r=merg(t[x].r,y);
pushup(x);
return x;
}
else{
t[y].l=merg(x,t[y].l);
pushup(y);
return y;
}
}
}
void insrt(int v){
split(root,v-1,x,y);
root=merg(merg(x,newnode(v)),y);
}
void remov(int v){
split(root,v-1,x,y);
split(y,v,z,y);
z=merg(t[z].l,t[z].r);
root=merg(merg(x,z),y);
}
ll get_sum(int rank){
int now=root;
ll sum=0;
while(now){
int s=t[t[now].l].siz+1;
if(s==rank)break;
else{
if(s<rank){
rank-=s;
sum+=t[t[now].l].sum+t[now].v;
now=t[now].r;
}
else{
now=t[now].l;
}
}
}
return sum+t[now].v+t[t[now].l].sum;
}
}T;
int cnt;
ll a[214514];
int bs(){
int l=0,r=n;
while(l<r){
int mid=(l+r+1)>>1;
if(T.get_sum(mid)<0){
l=mid;
}
else{
r=mid-1;
}
}
return l;
}
int main(){
read(n,q);
for(int i=1;i<=n;++i){
read(a[i]);
T.insrt(a[i]);
if(a[i]>0)cnt++;
}
for(int i=1;i<=q;++i){
ll x,v;
read(x,v);
if(a[x]>0&&v<=0)cnt--;
if(a[x]<=0&&v>0)cnt++;
T.remov(a[x]);
a[x]=v;
T.insrt(v);
int id=bs();
wr2(cnt-(n-id)+1);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 3736kb
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: 3736kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3732kb
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:
945 64 251 409 914 591 982 486 342 898 808 431 585 586 138 463 803 83 475 698 503 148 578 351 374 855 544 165 139 656 567 508 274 709 872 429 536 878 300 0 297 969 922 509 983 641 54 878 940 343 463 787 916 993 570 609 490 441 925 100 985 839 623 612 424 344 815 422 274 220 316 112 385 115 468 259 4...
result:
wrong answer 1st numbers differ - expected: '946', found: '945'