QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#724811 | #7787. Maximum Rating | PoorGhost | WA | 3ms | 15972kb | C++20 | 3.0kb | 2024-11-08 15:10:00 | 2024-11-08 15:10:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int N = 2e5 + 5, M = 1e4 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
int n, q;
int a[N], x[N], v[N];
map<int, int>mp, idx; //离散化
struct BIT
{
const static int maxnum = 5e5 + 10;
int tree[maxnum];
int lowbit(int x)
{
return (x) & (-x);
}
void add(int idx, int x)
{
for (int pos = idx; pos < maxnum; pos += lowbit(pos))
{
tree[pos] += x;
}
}
int query(int n)
{
int ans = 0;
for (int pos = n; pos; pos -= lowbit(pos))
{
ans += tree[pos];
}
return ans;
}
int query(int a, int b)
{
return query(b) - query(a - 1);
}
void init(int n)
{
for (int i = 0; i <= n + 2; i++)
tree[i] = 0;
}
} tree, tree2;
void solve()
{
cin >> n >> q;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] > 0) mp[a[i]]++;
}
for (int i = 1; i <= q; i++)
{
cin >> x[i] >> v[i];
if (v[i] > 0) mp[v[i]]++;
}
int cnt = 0;
for (auto mpp : mp)
{
cnt++;
idx[mpp.first] = cnt;
}
int sum = 0;//负数的绝对值的和
for (int i = 1; i <= n; i++)
{
if (a[i] < 0) sum -= a[i];
if (a[i] > 0)
{
int val = idx[a[i]];
tree.add(val, 1);
tree2.add(val, a[i]);
}
}
for (int i = 1; i <= q; i++)
{
if (v[i] < 0)
{
sum -= v[i];
if (a[x[i]] < 0)
{
sum += a[x[i]];
}
else
{
int val = idx[a[x[i]]];
tree.add(val, -1);
tree2.add(val, -a[x[i]]);
}
a[x[i]] = v[i];
}
else if (v[i] > 0)
{
if (a[x[i]] < 0)
{
sum += a[x[i]];
}
else
{
int val = idx[a[x[i]]];
tree.add(val, -1);
tree2.add(val, -a[x[i]]);
}
tree.add(idx[v[i]], 1);
tree2.add(idx[v[i]], v[i]);
a[x[i]] = v[i];
}
// cout << "sum = " << sum << endl;
int low = 1, high = 4e5 + 1;
while (low < high)
{
int mid = low + high >> 1;
if (tree2.query(mid) > sum)
{
high = mid;
}
else low = mid + 1;
}
low--;
int ans = 0;
if (low == 0) ans = 0;
else ans = tree.query(low);
cout << ans + 1 << endl;
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int test = 1;
// cin >> test;
for (int i = 1; i <= test; i++)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 13936kb
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: 2ms
memory: 15972kb
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: 13844kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7680kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 3ms
memory: 13912kb
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'