QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#705422 | #7787. Maximum Rating | xxk2006 | WA | 2ms | 9964kb | C++23 | 3.2kb | 2024-11-02 23:25:14 | 2024-11-02 23:25:19 |
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;
if(n==1000)cout<<sum<<endl;
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<<sum<<endl;
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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 7700kb
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: 7700kb
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: 9948kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5724kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 9964kb
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:
1000 54 yes-2147482648 935 yes-2147482648 748 yes-2147482648 590 yes-2147482648 85 yes-2147482648 408 yes-2147482648 17 yes-2147482648 513 yes-2147482648 657 yes-2147482648 101 yes-2147482648 191 yes-2147482648 568 yes-2147482648 414 yes-2147482648 413 yes-2147482648 861 yes-2147482648 536 yes-21474...
result:
wrong answer 1st numbers differ - expected: '946', found: '1000'