QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#609241#7787. Maximum RatingdownfallRE 0ms0kbC++173.3kb2024-10-04 11:25:482024-10-04 11:25:49

Judging History

你现在查看的是最新测评结果

  • [2024-10-04 11:25:49]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-04 11:25:48]
  • 提交

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)
    {
        int w = tr[i].sum / tr[i].cnt;
        return (abs(sum) + w - 1) / w;
    }
    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: 0
Runtime Error

input:

3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1

output:


result: