QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#588029 | #7787. Maximum Rating | E7k | WA | 1ms | 5892kb | C++20 | 1.9kb | 2024-09-24 23:45:23 | 2024-09-24 23:45:23 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define gcd __gcd
using namespace std;
typedef pair<int,int> pii;
const int INF = 9e18;
const int inf = 2e9;
const int N = 4e5 + 10;
int tr[N],cn[N];
int n,q,nn;
int lowbit(int x)
{
return x & -x;
};
array<int,2> query(int x)
{
int res = 0;
int cnt = 0;
for(int i = x; i >= 1; i -= lowbit(i))
{
res += tr[i];
cnt += cn[i];
}
return {res,cnt};
}
void update(int x,int v,int k)
{
for(int i = x; i <= nn; i += lowbit(i))
{
cn[i] += k;
tr[i] += v;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
vector<int> a(n + 1);
for(int i = 1; i <= n; i ++) cin >> a[i];
vector<int> b;
vector<array<int,2>> e(q + 1);
for(int i = 1; i <= q; i ++)
{
int x,v;
cin >> x >> v;
e[i] = {x,v};
if(v > 0) b.push_back(v);
}
auto id = [&](int x)-> int
{
return lower_bound(b.begin(),b.end(),x) - b.begin() + 1;
};
int sum = 0,tot = 0;
for(int i = 1; i <= n; i ++)
{
if(a[i] > 0)
{
b.push_back(a[i]);
}
}
sort(b.begin(),b.end());
b.erase(unique(b.begin(),b.end()),b.end());
nn = b.size();
auto del =[&](int x) -> void
{
if(x == 0);
else if(x > 0)
{
tot --;
update(id(x),-x,-1);
}
else sum += x;
};
auto add =[&](int x) -> void
{
if(x == 0);
else if(x > 0)
{
tot ++;
update(id(x),x,1);
}
else sum += -x;
};
for(int i = 1; i <= n; i ++)
{
add(a[i]);
}
for(int i = 1; i <= q; i ++)
{
int x = e[i][0],v = e[i][1];
del(a[x]);
a[x] = v;
add(a[x]);
auto check = [&](int mid) -> bool
{
auto x = query(mid);
if(x[0] <= sum) return 1;
return 0;
};
int l = 0,r = nn;
while(l < r)
{
int mid = l + r + 1 >> 1;
if(check(mid)) l = mid;
else r = mid - 1;
}
auto t = query(l);
cout << t[1] + 1 << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5596kb
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: 5600kb
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: 5892kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 5704kb
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'