QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#609245 | #7787. Maximum Rating | downfall | WA | 2ms | 11980kb | C++17 | 3.4kb | 2024-10-04 11:26:57 | 2024-10-04 11:26:59 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define frep(i, l, r) for (int i = l; i >= r; i--)
#define eb emplace_back
#define pb push_back
#define endl "\n"
#define int long long
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int N = 2e5 + 3;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
int a[N], b[N], d[N];
int n, q;
int num1; // 正数个数
int num2; // 负数个数'
int num3; // 0个数
struct opt
{
int pos, val;
} c[N];
struct SegmentTree
{
int l, r;
int sum, cnt;
} tr[N << 2];
#define ls (i << 1)
#define rs (i << 1 | 1)
void pushup(int i)
{
tr[i].sum = tr[ls].sum + tr[rs].sum;
tr[i].cnt = tr[ls].cnt + tr[rs].cnt;
}
void build(int i, int l, int r)
{
if (l == r)
{
return;
}
tr[i] = {l, r, 0, 0};
int mid = (l + r) >> 1;
build(ls, l, mid), build(rs, mid + 1, r);
pushup(i);
}
void insert(int i, int p, int x)
{
if (tr[i].l == tr[i].r)
{
tr[i].sum += a[p] * x;
tr[i].cnt += x;
return;
}
int mid = (tr[i].l + tr[i].r) >> 1;
if (b[p] <= mid)
insert(ls, p, x);
else
insert(rs, p, x);
pushup(i);
}
int query(int i, int sum)
{
if (tr[i].l == tr[i].r)
{
if (tr[i].cnt)
{
int w = tr[i].sum / tr[i].cnt;
return (abs(sum) + w - 1) / w;
}
else
return 0;
}
int mid = (tr[i].l + tr[i].r) >> 1;
if (sum + tr[ls].sum >= 0)
return query(ls, sum);
else
return tr[ls].cnt + query(rs, sum + tr[ls].sum);
}
void solve()
{
vector<int> ve;
cin >> n >> q;
rep(i, 1, n)
{
cin >> a[i];
ve.pb(a[i]);
if (a[i] > 0)
num1++;
else if (a[i] < 0)
num2++;
else
num3++;
}
rep(i, 1, q)
{
int x, y;
cin >> x >> y;
c[i] = (opt){x, y};
ve.push_back(y);
}
sort(ve.begin(), ve.end());
ve.erase(unique(ve.begin(), ve.end()), ve.end());
rep(i, 1, n) b[i] = lower_bound(ve.begin(), ve.end(), a[i]) - ve.begin() + 1;
rep(i, 1, q) d[i] = lower_bound(ve.begin(), ve.end(), c[i].val) - ve.begin() + 1;
int p = ve.size();
build(1, 1, p);
rep(i, 1, n) insert(1, i, 1);
rep(i, 1, q)
{
int x = c[i].pos, y = c[i].val;
if (a[x] > 0)
num1--;
else if (a[x] < 0)
num2--;
else
num3--;
if (y > 0)
num1++;
else if (y < 0)
num2++;
else
num3++;
insert(1, x, -1);
a[x] = y, b[x] = d[i];
insert(1, x, 1);
if (tr[1].sum < 0)
{
cout << num1 + 1 << endl;
}
else
{
int t = query(1, 0);
if (t == 0)
cout << 1 << endl;
else
{
// cerr << t << " " << tr[1].sum << endl;
int w = t - 1 - num2 - num3;
cout << w + 1 << endl;
}
}
}
}
signed main()
{
IOS;
int T = 1;
// cin >> T;
while (T--)
solve();
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11724kb
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: 11980kb
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: 2ms
memory: 9680kb
input:
1 1 1000000000 1 1000000000
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 9972kb
input:
1 1 -1000000000 1 -1000000000
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 2ms
memory: 9788kb
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:
945 1 1 1 914 591 982 1 1 898 808 1 585 586 1 1 803 1 1 698 503 1 578 1 1 855 544 1 1 656 567 508 1 709 872 1 536 878 1 1 1 969 922 509 983 641 1 878 940 1 1 787 916 993 570 609 490 1 925 1 985 839 623 612 1 1 815 1 1 1 1 1 1 1 1 1 497 928 510 587 1 607 677 1 969 910 1 578 1 1 917 1 1 1 1 967 1 1 1 ...
result:
wrong answer 1st numbers differ - expected: '946', found: '945'