QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#665943 | #7787. Maximum Rating | KIRITO1211 | WA | 4ms | 3652kb | C++23 | 3.0kb | 2024-10-22 15:58:14 | 2024-10-22 15:58:15 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
//#define int long long
using ll = long long;
using i64 = long long;
const int mod = 1e9 + 7;
// #define DEBUG
struct Node {
ll l, r, val, lazy;
Node *left, *right;
Node(ll l, ll r): l(l), r(r), val(0), lazy(0), left(nullptr), right(nullptr) {}
void push_down() {
if (!left) {
ll m = (l + r) >> 1;
left = new Node(l, m);
right = new Node(m + 1, r);
}
if (lazy) {
left->val += lazy * (left->r - left->l + 1);
right->val += lazy * (right->r - right->l + 1);
left->lazy += lazy;
right->lazy += lazy;
lazy = 0;
}
}
void update(ll ql, ll qr, ll delta) {
if (ql > r || qr < l) return;
if (ql <= l && r <= qr) {
val += delta * (r - l + 1);
lazy += delta;
return;
}
push_down();
left->update(ql, qr, delta);
right->update(ql, qr, delta);
val = left->val + right->val;
}
ll query(ll ql, ll qr) {
if (ql > r || qr < l) return 0;
if (ql <= l && r <= qr) return val;
push_down();
return left->query(ql, qr) + right->query(ql, qr);
}
};
void solve() {
int n,q;std::cin>>n>>q;
std::vector<int> a(n + 2);
for(int i = 1;i <= n;i++) {
std::cin>>a[i];
}
Node tree(0,1e9 + 1),itree(0,1e9 + 1);
int sum = 0;
int cnt = 0;
for(int i = 1;i <= n;i++) {
if(a[i] >= 0)
tree.update(a[i],a[i],a[i]),cnt++, itree.update(a[i],a[i],1);
else sum += a[i];
}
//std::cerr<<tree.query(1,1e9)<<'\n';
while(q--){
int x,v;std::cin>>x>>v;
if(a[x] >= 0){
int val = a[x];
tree.update(val, val, -val), cnt--, itree.update(val,val,-1);
a[x] = v;
if (a[x] < 0) sum += a[x];
else tree.update(a[x], a[x], a[x]), cnt++,itree.update(a[x],a[x],1);
}
else{
int val = a[x];
sum -= a[x];
a[x] = v;
if(a[x] < 0)sum += a[x];
else tree.update(a[x], a[x], a[x]), cnt++, itree.update(a[x],a[x],1);
}
int res = 0;
int l = 0,r = 1e9;
while(l <= r){
int mid = (l + r) / 2;
if(tree.query(0,mid) < -sum) l = mid + 1;
else res = mid, r = mid - 1;
}
std::cout<<cnt - itree.query(r, 1e9) + 1<<'\n';
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout<<std::fixed<<std::setprecision(10);
int t = 1;
// int res = 0;
// for(int i = 1;i <= 1145;i++) res |= i;
// std::cerr<<res<<'\n';
//std::cin>>t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
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: 3648kb
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: 3652kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 4ms
memory: 3588kb
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'