QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707147 | #7787. Maximum Rating | red_jiu | WA | 2ms | 11776kb | C++23 | 2.4kb | 2024-11-03 14:50:28 | 2024-11-03 14:50:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int n, m;
long long sum, cnt;
long long a[N], p[N], w[N];
vector<int>num;
long long tree[N << 2];
int siz[N << 2];
void update(int i, int l, int r, int pos, long long qw, int qsiz)
{
if(l > r) return;
if(l == r)
{
tree[i] += qw;
siz[i] += qsiz;
return;
}
int mid = (l + r) >> 1;
if(pos <= mid) update(i << 1,l,mid,pos,qw,qsiz);
else update(i << 1|1,mid + 1,r,pos,qw,qsiz);
tree[i] = tree[i << 1] + tree[i << 1|1];
siz[i] = siz[i << 1] + siz[i << 1|1];
}
long long query(int i, int l, int r, long long k)
{
if(l > r) return 0;
if(k >= siz[i]) return tree[i];
if(l == r) return k * num[l - 1];
int mid = (l + r) >> 1;
if(k > siz[i << 1]) return tree[i << 1] + query(i << 1 | 1,mid + 1,r,k - siz[i << 1]);
return query(i << 1,l,mid,k);
}
void solve()
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
if(a[i] > 0) num.push_back(a[i]), cnt++;
else sum -= a[i];
}
for(int i = 1; i <= m; i++)
{
cin >> p[i] >> w[i];
if(w[i] > 0) num.push_back(w[i]);
}
sort(num.begin(),num.end());
num.erase(unique(num.begin(),num.end()) ,num.end());
for(int i = 1; i <= n; i++)
{
int pos = lower_bound(num.begin(),num.end(),a[i]) - num.begin() + 1;
update(1,1,num.size(),pos,a[i],1);
}
for(int i = 1; i <= m; i++)
{
if(a[p[i]] <= 0) sum += a[p[i]];
else
{
cnt--;
int pos = lower_bound(num.begin(),num.end(),a[p[i]]) - num.begin() + 1;
update(1,1,num.size(),pos,-a[p[i]],-1);
}
a[p[i]] = w[i];
if(w[i] <= 0) sum -= w[i];
else
{
cnt++;
int pos = lower_bound(num.begin(),num.end(),w[i]) - num.begin() + 1;
update(1,1,num.size(),pos,w[i],1);
}
int l = 1, r = cnt, p = 0;
while(l <= r)
{
int mid = (l + r) >> 1;
long long Qsum = query(1,1,num.size(),mid);
if(Qsum <= sum) p = mid,l = mid + 1;
else r = mid - 1;
}
cout << p + 1 << "\n";
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int tt = 1;
//cin >> tt;
while(tt--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9716kb
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: 9736kb
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: 9708kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 9772kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 9824kb
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: 1ms
memory: 9816kb
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: 11776kb
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'