QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751041 | #7787. Maximum Rating | sunnygreen# | RE | 3ms | 16032kb | C++14 | 3.0kb | 2024-11-15 16:49:56 | 2024-11-15 16:49:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define fi first
#define se second
#define mk make_pair
#define eb emplace_back
#define rep(i,l,r) for(int i=(l); i<=(r); ++i)
#define rep_(i,l,r) for(int i=(l); i>=(r); --i)
typedef long long lr;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
constexpr int mod1=998244353,mod2=1e9+7;
constexpr db pi=3.141592653589793,eps=1e-9;
constexpr int inf32=0x3f3f3f3f,Inf32=0xc0c0c0c0;
constexpr lr inf64=0x3f3f3f3f3f3f3f3f,Inf64=0xc0c0c0c0c0c0c0c0;
template<typename T>il T Max(T x,T y) { return (x>y)? x:y; }
template<typename T>il T Min(T x,T y) { return (x<y)? x:y; }
template<typename T>il T gcd(T x,T y) { return (!y)? x:gcd(y,x%y); }
template<typename T>il T Abs(T x) { return (x>0)? x:(-x); }
template<typename T>il T Rnd(T l,T r,mt19937_64 &eng)
{
uniform_int_distribution<T> uid(l,r);
return uid(eng);
}
mt19937_64 eng(chrono::high_resolution_clock::now().time_since_epoch().count());
constexpr int N=200200;
struct node
{
lr sum; int cnt;
node() {}
node(lr Sum,int Cnt) { sum=Sum,cnt=Cnt; }
};
node tr[N<<1]; lr tags[N<<1]; int tagc[N<<1];
int n,q,a[N],c[N],x[N],y[N]; lr neg;
pii b[N<<1],tmp[N<<1]; int id[N<<1]; multiset<int> s;
il void Pushdown(int k)
{
tr[k<<1].sum+=tags[k],tr[k<<1].cnt+=tagc[k],tags[k<<1]+=tags[k],tagc[k<<1]+=tagc[k];
tr[k<<1|1].sum+=tags[k],tr[k<<1|1].cnt+=tagc[k],tags[k<<1|1]+=tags[k],tagc[k<<1|1]+=tagc[k];
tags[k]=0,tagc[k]=0;
}
il void Modify(int k,int l,int r,int x,int y,lr v1,int v2)
{
if(l>y||r<x)
return;
if(l>=x&&r<=y)
{
tr[k].sum+=v1,tr[k].cnt+=v2;
tags[k]+=v1,tagc[k]+=v2;
return;
}
Pushdown(k);
int mid=(l+r)>>1;
Modify(k<<1,l,mid,x,y,v1,v2),Modify(k<<1|1,mid+1,r,x,y,v1,v2),tr[k]=tr[k<<1];
}
il int Query(int k,int l,int r,lr x)
{
if(l==r)
return tr[k].cnt;
Pushdown(k);
int mid=(l+r)>>1;
if(tr[k<<1|1].sum>x)
return Query(k<<1,l,mid,x);
else
return Query(k<<1|1,mid+1,r,x);
}
il void Solve()
{
cin>>n>>q;
int m=0;
rep(i,1,n)
{
cin>>a[i];
if(a[i]>0)
b[++m]=mk(a[i],m);
if(a[i]<0)
neg-=a[i];
}
rep(i,1,q)
{
cin>>x[i]>>y[i];
if(y[i]>0)
b[++m]=mk(y[i],m);
}
rep(i,1,m)
tmp[i]=b[i];
sort(tmp+1,tmp+1+m);
rep(i,1,m)
id[i]=lower_bound(tmp+1,tmp+1+m,b[i])-tmp;
int pos=0;
rep(i,1,n)
if(a[i]>0)
++pos,Modify(1,1,m,id[pos],m,a[i],1),c[i]=pos,s.insert(a[i]);
rep(i,1,q)
{
if(a[x[i]]>0)
Modify(1,1,m,id[c[x[i]]],m,-a[x[i]],-1),s.erase(s.find(a[x[i]]));
if(a[x[i]]<0)
neg+=a[x[i]];
a[x[i]]=y[i];
if(a[x[i]]>0)
++pos,Modify(1,1,m,id[pos],m,a[x[i]],1),c[x[i]]=pos,s.insert(a[x[i]]);
if(a[x[i]]<0)
neg-=a[x[i]];
if(neg<*s.begin())
cout<<1<<'\n';
else
cout<<Query(1,1,m,neg)+1<<'\n';
}
}
int main()
{
#ifdef LOCAL
string fpre="test",isuf="in",osuf="out";
assert(freopen((fpre+"."+isuf).c_str(),"r",stdin));
assert(freopen((fpre+"."+osuf).c_str(),"w",stdout));
#endif
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
while(T--)
Solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 16032kb
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: 3ms
memory: 16028kb
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: 0ms
memory: 13988kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Runtime Error
input:
1 1 -1000000000 1 -1000000000