QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#713327 | #7787. Maximum Rating | Soestx | WA | 2ms | 7788kb | C++23 | 2.0kb | 2024-11-05 19:00:31 | 2024-11-05 19:00:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pll pair<int,int>
#define fi first
#define se second
#define lowbit(x) (x&(-x))
typedef long long LL;
typedef unsigned long long ull;
int n, m, k;
const int N = 1e6 + 10, M = 1e6, mod = 998244353;
int num[N], book[N];
int res, cnt;
int uni[N];
struct stu
{
int sum,con;
}st[N<<2];
void push_up(int id)
{
st[id].sum=st[id<<1].sum+st[id<<1|1].sum;
st[id].con=st[id<<1].con+st[id<<1|1].con;
}
void modify(int id,int l,int r,int x,int y)
{
if(l==r)
{
st[id].sum+=y*uni[x];
st[id].con+=y;
return;
}
int mid=(l+r)>>1;
if(mid>=x) modify(id<<1,l,mid,x,y);
else modify(id<<1|1,mid+1,r,x,y);
push_up(id);
}
int quer(int id,int l,int r,int x)
{
if(l==r)
{
int t=x/uni[l];
return min(t,st[id].con);
}
int mid=(l+r)>>1;
if(x>=st[id<<1].sum) return st[id<<1].con+quer(id<<1|1,mid+1,r,x-st[id<<1].con);
else return quer(id<<1,l,mid,x);
}
int get(int x)
{
return lower_bound(uni+1,uni+1+m,x)-uni;
}
void solve() {
int con=0;
cin>>n>>k;
vector<pll> vt;
vector<int> v;
uni[++m]=1;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
if(x>0)
{
uni[++m]=x;
}
else con-=x;
num[i]=x;
}
for(int i=1;i<=k;i++)
{
int a,b;
cin>>a>>b;
if(b>0) uni[++m]=b;
vt.push_back({a,b});
}
sort(uni+1,uni+1+m);
m=unique(uni+1,uni+1+m)-uni-1;
for(int i=1;i<=n;i++)
{
if(num[i]<=0) continue;
modify(1,1,m,get(num[i]),1);
}
for(auto it:vt)
{
int a=it.fi,b=it.se;
if(num[a]>0) modify(1,1,m,get(num[a]),-1);
if(num[a]<0) con+=num[a];
num[a]=b;
if(num[a]>0) modify(1,1,m,get(num[a]),1);
if(num[a]<0) con-=num[a];
//for(int i=1;i<=n;i++) cout<<num[i]<<" ";cout<<endl;
// cout<<con<<"---"<<st[1].con<<endl;;
cout<<quer(1,1,m,con)+1<<endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
//cin >> T;
while (T--) {
solve();
}
return 0;
}
/*
100 100 10 20
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7772kb
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: 7648kb
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: 1ms
memory: 7604kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7624kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 2ms
memory: 7788kb
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:
946 65 252 410 915 592 983 487 343 899 809 432 586 587 139 464 804 84 476 699 504 149 579 352 375 856 545 166 140 657 568 509 275 710 873 430 537 879 301 1 298 970 923 510 984 642 55 879 941 344 464 788 917 994 571 610 491 442 926 101 986 840 624 613 425 345 816 423 275 221 317 113 386 116 469 260 4...
result:
ok 1000 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 7752kb
input:
1000 1000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000...
output:
500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 ...
result:
ok 1000 numbers
Test #7:
score: -100
Wrong Answer
time: 2ms
memory: 7724kb
input:
1000 1000 -485078954 -474724347 -284958745 -99994191 -853392841 -796786314 -87134718 -861459498 -982809180 -184620712 -618476092 -244916830 -349486182 -751407510 -874417202 -419521829 -888338757 -735353446 -426330733 -715383449 -48093437 -359419189 -474876639 -887614191 -157085227 -51186523 -4851821...
output:
2 3 4 5 6 7 8 9 10 11 12 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 51 52 53 54 55 56 57 58 59 60 60 61 62 63 64 65 65 66 67 68 69 70 71 72 73 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 88 89 90 91 92 92 93 94 95 96...
result:
wrong answer 746th numbers differ - expected: '505', found: '506'