QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#724972 | #7787. Maximum Rating | Left0807 | WA | 1ms | 3836kb | C++20 | 2.1kb | 2024-11-08 15:45:28 | 2024-11-08 15:45:30 |
Judging History
answer
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
void solve(){
int n, q;
cin >> n >> q;
vector<int> a(n+1);
vector<pii> d;
for(int i = 1; i <= n; i++){
cin >> a[i];
d.emplace_back(a[i], i);
}
vector<pair<int, int> > upd(q);
for(auto& [x, v] : upd){
cin >> x >> v;
d.emplace_back(v, x);
}
d.emplace_back(0, 0);
sort(all(d));
d.erase(unique(all(d)), d.end());
auto find = [&](pii x)->int{
return lower_bound(all(d), x) - d.begin() + 1;
};
vector<int> sBIT(d.size() + 1);
vector<int> cBIT(d.size() + 1);
auto add = [&](vector<int>& BIT, int x, int val)->void{
for(int i = x; i <= d.size(); i += i&-i) BIT[i] += val;
};
auto qry = [&](vector<int>& BIT, int x){
int res = 0;
for(int i = x; i > 0; i -= i&-i) res += BIT[i];
return res;
};
for(int i = 1; i <= n; i++){
add(sBIT, find({a[i], i}), a[i]);
add(cBIT, find({a[i], i}), 1);
}
auto f = [&](int x)->bool{
int neg = qry(sBIT, find({0, 0}));
int xthpos = qry(sBIT, x);
int rmpos = qry(sBIT, d.size()) - xthpos;
xthpos -= neg;
return rmpos >= rmpos + neg + xthpos;
};
for(auto [x, v] : upd){
add(sBIT, find({a[x], x}), -a[x]);
add(cBIT, find({a[x], x}), -1);
a[x] = v;
add(sBIT, find({a[x], x}), a[x]);
add(cBIT, find({a[x], x}), 1);
int i = find({0, 0});
for(int j = d.size(); j > 0; j /= 2){
while(i+j <= d.size() && f(i+j)) i += j;
}
int min_k = qry(cBIT, d.size()) - qry(cBIT, i);
int max_k = qry(cBIT, d.size()) - qry(cBIT, find({0, 0}));
cout << max_k - min_k + 1 << '\n';
}
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
// cin >> tt;
while(tt--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 0ms
memory: 3768kb
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: 3836kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3700kb
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 2 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:
wrong answer 40th numbers differ - expected: '1', found: '2'