QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#616741 | #7787. Maximum Rating | wzxtsl | RE | 0ms | 0kb | C++23 | 2.1kb | 2024-10-06 10:59:53 | 2024-10-06 10:59:54 |
answer
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define For(i,j,k) for (int i=(j);i<=(k);i++)
#define rof(i,j,k) for (int i=(j);i>=(k);i--)
#define ull unsigned long long
#define lowbit(x) ((x)&(-(x)))
#define PII pair<int,int>
#define int long long
#define endl "\n"
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const int mod = 998244353;
const double eps = 1e-9;
const int N=2e5+7;
int n,m;
struct node{
int l,r,s,id;
}t[N<<2];
map<int,int> mp;
void pushup(int rt){
t[rt].s=t[ls].s+t[rs].s;
t[rt].id=t[ls].id+t[rs].id;
return ;
}
void build(int l,int r,int rt){
t[rt].l=l;
t[rt].r=r;
if(l==r){
t[rt].s=0;
t[rt].id=0;
return ;
}
int mid=(l+r)>>1;
build(l,mid,ls);
build(mid+1,r,rs);
pushup(rt);
}
void update(int val,int rt){
if(t[rt].l==t[rt].r&&t[rt].l==val){
t[rt].s+=val;
t[rt].id++;
return ;
}
int mid=(t[rt].l+t[rt].r)>>1;
if(val<=mid) update(val,ls);
else update(val,rs);
pushup(rt);
}
void del(int val,int rt){
if(t[rt].l==t[rt].r&&t[rt].l==val){
t[rt].s-=val;
t[rt].id--;
return ;
}
int mid=(t[rt].l+t[rt].r)>>1;
if(val<=mid) del(val,ls);
else del(val,rs);
pushup(rt);
}
int query(int val,int rt){
if(t[rt].l==t[rt].r){
if(t[rt].s<=val) return t[rt].id;
else return 0;
}else if(t[rt].s<=val){
return t[rt].id;
}else if(t[ls].s>val){
query(val,ls);
}else{
return t[ls].id+query(val-t[ls].s,rs);
}
}
void solve(){
cin>>n>>m;
build(1,1e9,1);
int sum=0;
for(int i=1;i<=n;i++){
int num;
cin>>num;
mp[i]=num;
if(num>0){
update(num,1);
}else{
sum+=abs(num);
}
}
int x,y;
while(m--){
cin>>x>>y;
int num=mp[x];
mp[x]=y;
if(num>0&&y>0){
update(y,1);
del(num,1);
}else if(num>0&&y<0){
del(num,1);
sum+=abs(y);
}else if(num<0&&y>0){
sum-=abs(num);
update(y,1);
}else{
sum-=abs(num);
sum+=abs(y);
}
//cout<<query(sum,1)+1<<endl;
}
}
signed main(){
int t=1;
//cin>>t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 5 1 2 3 3 4 2 -2 1 -3 3 1 2 1