QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#703857 | #7787. Maximum Rating | qikala7777 | WA | 1ms | 7804kb | C++23 | 3.3kb | 2024-11-02 18:43:42 | 2024-11-02 18:43:42 |
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;
typedef tuple<int,LL,LL> TPL;
typedef pair<LL,LL> PII;
const int N=4e5+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;}
#define int LL
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;
}else{
int mid=x+y>>1;
build(u<<1,x,mid),build(u<<1|1,mid+1,y);
pushup(u);
return;
}
}
void change(int u,int op,int qt){
if(tr[u].l>=tr[u].r){
if(tr[u].l!=op)return;
tr[u].cnt+=qt;
tr[u].v=tr[u].cnt*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){
if(p[tr[u].l-1]==0)return 0;
return sms/p[tr[u].l-1];
}else{
return tr[u].cnt;
}
}
if(tr[u].v<=sms){
return tr[u].cnt;
}else{
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;//负数和
p.push_back(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();
for(int i=1;i<=n;i++){
if(a[i]>0){
mp[get(a[i])]++;
}
}
build(1,1,ll);
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);
}
LL kmax=ks;
a[x]=v;
LL kmin=ks-query(1,sms);
//cout<<query(1,sms)<<endl;
cout<<"kmin:"<<kmin<<endl;
cout<<kmax-kmin+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: 7804kb
input:
3 5 1 2 3 3 4 2 -2 1 -3 3 1 2 1
output:
u:1 sms:0 l:1 tr[u].r:5V:7 u:2 sms:0 l:1 tr[u].r:3V:3 u:4 sms:0 l:1 tr[u].r:2V:1 u:8 sms:0 l:1 tr[u].r:1V:0 kmin:3 1 u:1 sms:2 l:1 tr[u].r:5V:5 u:3 sms:1 l:4 tr[u].r:5V:4 u:7 sms:1 l:5 tr[u].r:5V:4 kmin:1 2 u:1 sms:5 l:1 tr[u].r:5V:4 kmin:0 2 u:1 sms:5 l:1 tr[u].r:5V:1 kmin:0 2 u:1 sms:3 l:1 tr[u].r...
result:
wrong output format Expected integer, but "u:1" found