QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#609645 | #7787. Maximum Rating | snow_miku | WA | 1ms | 7744kb | C++14 | 3.2kb | 2024-10-04 13:38:19 | 2024-10-04 13:38:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL N = 4e5 + 5;
map<LL, LL> mp;
// LL root[N];
// LL a[N];
// struct seg_tree{
// LL val;
// LL lson;
// LL rson;
// }tree[n<<5];
// LL tot = 1;
// LL clone(LL node){
// tot++;
// tree[tot] = tree[node];
// return tot;
// };
// LL update(LL u, LL v, LL x, LL l, LL r){
// u = ++tot;
// tree[u] = tree[v];
// tree[u].val++;
// if(l == r){
// return u;
// }
// LL mid = (l + r) / 2;
// if(x <= mid){tree[u].lson = update(tree[u].lson, tree[v].lson, x, l, mid);}
// else tree[u].rson = upodate(tree[u].rson, tree[v].rson, x, mid + 1, r);
// return u;
// }
// LL query()
LL c[N], z[N];
LL lowbit(LL x){
return x & -x;
}
LL zsum(LL x){
LL ans = 0;
while(x > 0){
ans += z[x];
x -= lowbit(x);
}
return ans;
}
LL qsum(LL x){
LL ans = 0;
while(x > 0){
ans += c[x];
x -= lowbit(x);
}
return ans;
}
void addz(LL k, LL x){
while(x < N){
z[x] += k;
x += lowbit(x);
}
}
void add(LL k, LL x){
while(x < N){
c[x] += k;
x += lowbit(x);
}
}
void solve(){
LL n, q;
cin >> n >> q;
vector<LL> a(n + 1);
vector<pair<LL,LL>> qq(q + 1);
vector<LL> temp;
// temp.push_back(0);
LL sum = 0;
// multiset<LL> s;
LL num = 0;
for(LL i = 1; i <= n; i++){
cin >> a[i];
if(a[i] <= 0){sum -= a[i];}
else{temp.push_back(a[i]);}
}
for(LL i = 1; i <= q; i++){
LL x, v;
cin >> qq[i].first >> qq[i].second;
if(qq[i].second > 0){temp.push_back(qq[i].second);}
}
sort(temp.begin(), temp.end());
temp.erase(unique(temp.begin(), temp.end()), temp.end());
for(LL i = 0; i < temp.size(); i++){
mp[temp[i]] = i + 1;
}
for(LL i = 1; i <= n; i++){
if(a[i] > 0) {
addz(1, mp[a[i]]);
add(a[i], mp[a[i]]);
num++;
}
}
for(LL i= 1; i <= q; i++){
auto [x, v] = qq[i];
if(v > 0){
if(a[x] > 0){
addz(-1, mp[a[x]]);
add(-1LL * a[x], mp[a[x]]);
num--;
}
else{
sum += a[x];//a[x] < 0
}
addz(1, mp[v]);
a[x] = v;
add(v, mp[v]);
num++;
}
else{
if(a[x] > 0) {
num--;
addz(-1LL, mp[a[x]]);
add(-1LL * a[x], mp[a[x]]);
}
else{
sum += a[x];
}
a[x] = v;
sum -= v;
}
LL l = 1;
LL r = N - 3;
LL ans = 0;
while(l <= r) {
LL mid = (l + r) / 2;
if(qsum(mid) > sum) {r = mid - 1;}
else {ans = mid; l = mid + 1;}
}
cout << zsum(r) + 1 << '\n';
// cout << l << ' ' << r << ' ' << ans << endl;
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
// LL t; cin >> t;
// while (t--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7744kb
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: 7652kb
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: 7664kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 7732kb
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'