QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#704741 | #7787. Maximum Rating | qikala7777 | WA | 1ms | 7828kb | C++23 | 3.1kb | 2024-11-02 20:51:44 | 2024-11-02 20:51:45 |
Judging History
answer
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define int LL
typedef tuple<int,LL,LL> TPL;
typedef pair<LL,LL> PII;
const int N=5e5+7,inf=0x3f3f3f3f;const LL Linf=0x3f3f3f3f3f3f3f3fLL;
LL qsm(LL a,LL b,LL p){LL res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
LL lowbit(LL x){return x&-x;}
int n,q,ll;
int a[N];
LL sms;
map<int,int>mp;
struct{
int op,v;
}cz[N];
vector<int>p;
int get(int x){
return lower_bound(p.begin(),p.end(),x)-p.begin()+1;
}
struct seg{
int l,r;
LL v;
LL cnt;
}tr[N<<2];
void pushup(int u){
tr[u].v=tr[u<<1].v+tr[u<<1|1].v;
tr[u].cnt=tr[u<<1].cnt+tr[u<<1|1].cnt;
}
void build(int u,int x,int y){
tr[u]={x,y,0,0};
if(x>=y){
tr[u].cnt=mp[x];
tr[u].v=tr[u].cnt*p[x-1];
return;
}
int mid=x+y>>1;
build(u<<1,x,mid),build(u<<1|1,mid+1,y);
pushup(u);
}
void change(int u,int op,int qt){
if(tr[u].l>=tr[u].r){
tr[u].cnt+=qt;
tr[u].v+=qt*p[tr[u].l-1];
return;
}
int mid=tr[u].l+tr[u].r>>1;
if(op<=mid){
change(u<<1,op,qt);
}else{
change(u<<1|1,op,qt);
}
pushup(u);
}
LL query(int u,LL sms){
//cout<<"u:"<<u<<" sms:"<<sms<<" l:"<<tr[u].l<<" tr[u].r:"<<tr[u].r<<"V:"<<tr[u].v<<endl;
if(tr[u].l>=tr[u].r){
if(tr[u].v>sms){
return sms/p[tr[u].l-1];
}
return tr[u].cnt;
}
if(tr[u].v<=sms){
return tr[u].cnt;
}
if(tr[u<<1].v>=sms){
return query(u<<1,sms);
}else{
return tr[u<<1].cnt+query(u<<1|1,sms-tr[u<<1].v);
}
}
void solve(){
cin>>n>>q;
int ks=0;//正数的个数
sms=0;//负数和
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]>0){
ks++;
p.push_back(a[i]);
}else if(a[i]<0){
sms+=-a[i];
}
}
for(int i=1;i<=q;i++){
cin>>cz[i].op>>cz[i].v;
if(cz[i].v>0)p.push_back(cz[i].v);
}
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
ll=p.size();
if(ll==0){
for(int i=0;i<q;i++){
cout<<1<<endl;
}
return;
}
for(int i=1;i<=n;i++){
if(a[i]>0){
mp[get(a[i])]++;
}
}
build(1,1,ll+1);
for(int i=1;i<=q;i++){
int x=cz[i].op,v=cz[i].v;
int t=a[x];
if(v<0){
if(t<0)sms-=-t;
else if(t>0){
--ks;
change(1,get(t),-1);
}
sms+=-v;
}else if(v>0){
if(t<0)sms-=-t;
else if(t>0){
--ks;
change(1,get(t),-1);
}
ks++;
change(1,get(v),1);
}
a[x]=v;
cout<<query(1,sms)+1<<endl;
}
}
signed main(){
IOS
int T=1;
//cin>>T;
while(T--)solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7768kb
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: 7828kb
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: 7784kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7764kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 7732kb
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 301 598 1000 1000 810 1000 942 355 1000 1000 644 764 1000 1000 1000 871 910 791 742 1000 401 1000 1000 924 913 725 645 1000 723 575 521 617 413 68...
result:
wrong answer 40th numbers differ - expected: '1', found: '301'