QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#705405 | #7787. Maximum Rating | xxk2006 | WA | 1ms | 9952kb | C++23 | 3.1kb | 2024-11-02 23:20:25 | 2024-11-02 23:20:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define Enter putchar('\n')
#define spc putchar(' ')
#define pb push_back
#define fi first
#define se second
inline void read(int &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
inline void lread(long long &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
void print(long long num){if(num<0){putchar('-');num=-num;}if(num>9){print(num/10);}putchar((num%10)^48);}
const int N=2e5+9;
struct node{
int pos,v;
}ask[N];
int va[N],tong[N<<1],s[N<<2],g[N<<2];
LL t[N<<2];
unordered_map<int,int> mp;
void ad(int p,int l,int r,int x,int y){
if(l==r){
g[p]=y;
++s[p];
t[p]=1ll*g[p]*s[p];
return;
}
int mid=l+r>>1;
if(x<=mid)ad(p<<1,l,mid,x,y);
else ad(p<<1|1,mid+1,r,x,y);
t[p]=t[p<<1]+t[p<<1|1];
s[p]=s[p<<1]+s[p<<1|1];
}
void cg(int p,int l,int r,int x,int y){
if(l==r){
t[p]=g[p]=s[p]=0;
return;
}
int mid=l+r>>1;
if(x<=mid)cg(p<<1,l,mid,x,y);
else cg(p<<1|1,mid+1,r,x,y);
t[p]=t[p<<1]+t[p<<1|1];
s[p]=s[p<<1]+s[p<<1|1];
}
int query(int p,int l,int r,long long x){
if(l==r){
if(g[p]==0)cout<<"yes";
return ceil(1.0*x/g[p]);
}
int mid=l+r>>1;
if(t[p<<1|1]<x)return s[p<<1|1]+query(p<<1,l,mid,x-t[p<<1|1]);
return query(p<<1|1,mid+1,r,x);
}
void pr(int p,int l,int r){
if(l==r){
print(l),spc,print(r),spc,print(t[p]),spc,print(s[p]),Enter;
return;
}
int mid=l+r>>1;
pr(p<<1,l,mid);
pr(p<<1|1,mid+1,r);
print(l),spc,print(r),spc,print(t[p]),spc,print(s[p]),Enter;
}
int main(){
int n,Q,tot=0,cnt=0;
long long sum=0;
read(n),read(Q);
for(int i=1;i<=n;i++){
read(va[i]);
if(va[i]>0){
++tot;
tong[++cnt]=va[i];
}
sum+=va[i];
}
for(int i=1;i<=Q;i++){
read(ask[i].pos),read(ask[i].v);
if(ask[i].v>0)tong[++cnt]=ask[i].v;
}
sort(tong+1,tong+cnt+1);
int kt=unique(tong+1,tong+cnt+1)-tong-1;
for(int i=1;i<=kt;i++)mp[tong[i]]=i;
for(int i=1;i<=n;i++){
if(va[i]>0)ad(1,1,kt,mp[va[i]],va[i]);
}
//print(tot-query(1,1,n,sum)+1),Enter;
for(int i=1;i<=Q;i++){
sum-=va[ask[i].pos];
sum+=ask[i].v;
if(va[ask[i].pos]>0)--tot;
if(ask[i].v>0)++tot;
if(va[ask[i].pos]>0)cg(1,1,kt,mp[va[ask[i].pos]],0);
//print(mp[ask[i].v]),spc,print(ask[i].v),Enter;
//Enter;
//pr(1,1,kt),Enter;
if(ask[i].v>0)ad(1,1,kt,mp[ask[i].v],ask[i].v);
//pr(1,1,kt),Enter;
va[ask[i].pos]=ask[i].v;
if(sum<=0){
print(tot+1),Enter;
continue;
}
if(s[1]==0)cout<<"no";
print(tot-query(1,1,kt,sum)+1),Enter;
}
return 0;
}
/*
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: 1ms
memory: 7684kb
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: 9728kb
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: 9740kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5556kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 9952kb
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:
noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-2147482648 noyes-21474...
result:
wrong output format Expected integer, but "noyes-2147482648" found