QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#610262 | #7787. Maximum Rating | wzxtsl# | WA | 1ms | 5740kb | C++23 | 1.8kb | 2024-10-04 15:25:56 | 2024-10-04 15:26:02 |
Judging History
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=2e6+7;
int n,m;
int a[N];
int mp[N];
void solve(){
cin>>n>>m;
int sum=0,len=0;
for(int i=1;i<=n;i++){
cin>>a[i];
mp[i]=a[i];
if(a[i]<=0){
sum+=abs(a[i]);
len++;
}
}
sort(a+1,a+n+1);
int num=0,pos=0;
int x,y;
while(m--){
cin>>x>>y;
num=mp[x];
mp[x]=y;
if(y<=0){
if(num<=0){
sum=sum-abs(num)+abs(y);
}else{
sum=sum+abs(y);
len++;
}
}else if(y>0){
if(num<=0){
sum=sum-abs(num);
len--;
}
}
pos=lower_bound(a+1,a+n+1,num)-a;
//cout<<pos<<endl;
if(y>num){
a[pos]=y;
for(int i=x;i<=n;i++){
if(a[x]>y) swap(a[x],y);
else break;
}
}else if(y<num){
a[pos]=y;
for(int i=x-1;i>=1;i--){
if(a[x]<y) swap(a[x],y);
else break;
}
}
// for(int i=1;i<=n;i++){
// cout<<a[i]<<" ";
// }
// cout<<endl;
pos=lower_bound(a+1,a+n+1,sum)-a;
cout<<pos-len<<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: 100
Accepted
time: 0ms
memory: 5740kb
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: -100
Wrong Answer
time: 1ms
memory: 5724kb
input:
3 5 1 2 3 3 4 2 -2 1 3 3 1 2 1
output:
1 2 2 2 3
result:
wrong answer 3rd numbers differ - expected: '1', found: '2'