QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#563010 | #7787. Maximum Rating | cyc_43346 | WA | 3ms | 9868kb | C++20 | 1.8kb | 2024-09-14 00:07:51 | 2024-09-14 00:07:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define int long long
int n,q,c2[1110000],tot,sz;
LL c1[1110000],a[1110000];
pair<int,int> rea[210000];
map<int,int> mp;
inline int lowbit(int x) {
return x&(-x);
}
void change1(int x,LL k)
{
while(x<=tot) {
c1[x]+=k;
x+=lowbit(x);
}
}
LL query1(int x)
{
LL sum=0;
while(x>0) {
sum+=c1[x];
x-=lowbit(x);
}
return sum;
}
void change2(int x,int k)
{
while(x<=tot) {
c2[x]+=k;
x+=lowbit(x);
}
}
int query2(int x)
{
int sum=0;
while(x>0) {
sum+=c2[x];
x-=lowbit(x);
}
return sum;
}
inline bool check(int x)
{
LL sum=query1(x);
return sum<=0;
}
void solve()
{
cin>>n>>q; tot=0;
for(int i=1;i<=n;i++) {
cin>>a[i];
mp[a[i]]=1;
}
for(int i=1;i<=q;i++) {
cin>>rea[i].first>>rea[i].second;
mp[rea[i].second]=1;
}
for(auto it=mp.begin();it!=mp.end();it++) {
it->second=++tot;
}
for(int i=1;i<=n;i++) {
change1(mp[a[i]],a[i]);
change2(mp[a[i]],1);
if(a[i]>0) ++sz;
}
for(int i=1;i<=q;i++) {
change1(mp[rea[i].second],rea[i].second),change2(mp[rea[i].second],1);
change1(mp[a[rea[i].first]],-a[rea[i].first]),change2(mp[a[rea[i].first]],-1);
if(a[rea[i].first]>0) --sz;
if(rea[i].second>0) ++sz;
a[rea[i].first]=rea[i].second;
int l=0,r=tot,pos;
while(l<=r) {
int mid=l+r>>1;
if(check(mid)) l=mid+1,pos=mid;
else r=mid-1;
}
int sum=query2(pos);
//cout << sum << endl;
cout<<sz-n+sum+1<<endl;
}
}
signed main()
{
cin.tie(0) -> sync_with_stdio(false);
solve();
//return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9820kb
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: 1ms
memory: 9868kb
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: 9860kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 9820kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 3ms
memory: 9792kb
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:
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 1 1 1 1 1 ...
result:
wrong answer 1st numbers differ - expected: '946', found: '1'