QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#704735 | #7787. Maximum Rating | qikala7777 | WA | 1ms | 7768kb | C++23 | 3.0kb | 2024-11-02 20:49:52 | 2024-11-02 20:49:55 |
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/tr[u].cnt;
}
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);
}
cout<<query(1,sms)+1<<endl;
}
}
signed main(){
IOS
int T=1;
//cin>>T;
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7768kb
input:
3 5 1 2 3 3 4 2 -2 1 -3 3 1 2 1
output:
1 3 2 2 2
result:
wrong answer 2nd numbers differ - expected: '2', found: '3'