QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#679579#7787. Maximum RatingheyuhaoRE 0ms0kbC++204.5kb2024-10-26 17:55:272024-10-26 17:55:28

Judging History

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

  • [2024-10-26 17:55:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-26 17:55:27]
  • 提交

answer

#pragma GCC optimize(3)
#include <cstring>
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int N = 2e5 + 10;
int n, q, nn;
long long fsum = 0;
int a[N], b[5 * N], cnt = 0;
pair<int, int> c[N];
vector<int> all;
int find(int x)
{
    return lower_bound(all.begin(), all.end(), x) - all.begin() + 1;
}
struct node
{
    int l, r;
    int date;
    long long sum;
} tri[4 * N];
void build(int u, int l, int r)
{
    if (l == r)
    {
        tri[u].l = l;
        tri[u].r = r;
        tri[u].date = 0;
        tri[u].sum = 0;
    }
    else
    {
        tri[u].l = l;
        tri[u].r = r;
        int m = l + r >> 1;
        build(u << 1, l, m);
        build(u << 1 | 1, m + 1, r);
        tri[u].date = 0;
        tri[u].sum = 0;
    }
}
void modify(int u, int d, int v)
{
    int l = tri[u].l, r = tri[u].r;
    if (l == r)
    {
        tri[u].date += v;
        tri[u].sum += all[d - 1] * v;
    }
    else
    {
        int m = l + r >> 1;
        if (d <= m)
        {
            modify(u << 1, d, v);
            tri[u].sum = tri[u << 1].sum + tri[u << 1 | 1].sum;
            tri[u].date += v;
        }
        else
        {
            modify(u << 1 | 1, d, v);
            tri[u].sum = tri[u << 1].sum + tri[u << 1 | 1].sum;
            tri[u].date += v;
        }
    }
}
long long query(int u, int l, int r)
{
    if(l>r)
        return 0;
    if (tri[u].l >= l && tri[u].r <= r)
        return tri[u].sum;
    int m = tri[u].l + tri[u].r >> 1;
    if (r <= m)
        return query(u << 1, l, r);
    else if (l > m)
        return query(u << 1 | 1, l, r);
    else
        return query(u << 1, l, r) + query(u << 1 | 1, l, r);
}
long long dquery(int u, int l, int r)
{
    if(l>r)
        return 0;
    if (tri[u].l >= l && tri[u].r <= r)
        return tri[u].date;
    int m = tri[u].l + tri[u].r >> 1;
    if (r <= m)
        return dquery(u << 1, l, r);
    else if (l > m)
        return dquery(u << 1 | 1, l, r);
    else
        return dquery(u << 1, l, r) + dquery(u << 1 | 1, l, r);
}
int chose(long long sum)
{
    int l = 1, r = nn;
    while (l <= r)
    {
        int mid = l + r  >> 1;
        if (query(1, 1, mid) <= sum)
            l = mid+1;
        else
            r = mid - 1;
    }
    if (r == 1 && query(1, 1, 1) > sum)
        r=0;
    int r1 = r+1;
    while (dquery(1, r1, r1 ) == 0 && r1  <= nn)
    {
        r1++;
    }
    int ans = dquery(1, 1, r);
    if (r1 != r&&r1<=nn)    
    {
        int num = dquery(1, r1, r1), x = all[r1 - 1];
        long long left = sum - query(1, 1, r);
        int maxn=left/x;
        ans += min(maxn,num);
    }
    return ans;
}
void solve()
{
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= q; i++)
        cin >> c[i].first >> c[i].second;
//    for (int i = 1; i <= n; i++)
//        a[i]=1;
//    c[1]={1,-945};
    for (int i = 1; i <= n; i++)
    {
        if (a[i] > 0)
            all.push_back(a[i]), cnt++;
        else
            fsum -= a[i];
    }
    for (int i = 1; i <= 1; i++)
    {
        if (c[i].second > 0)
            all.push_back(c[i].second);
    }
    sort(all.begin(), all.end());
    all.erase(unique(all.begin(), all.end()), all.end());
    // cout<<find(1);
    nn = all.size();
    if (nn == 0)
    {
        cout << "1\n";
        return;
    }
    build(1, 1, nn);
    for (int i = 1; i <= n; i++)
    {
        if (a[i] > 0)
        {
            int x = find(a[i]);
            modify(1, x, 1);
        }
    }
    //    cout<<tri[1].sum;
    //    cout<<query(1,1,nn);
    // cout<<chose(6);
    // for(int i=0;i<=6;i++)
    //{
    //    cout<<i<<" "<<chose(i)<<"\n";
    //}
    // if(n==1000)
    // {
    //     cout<<c[1].first<<" "<<c[1].second<<"\n";
    // }
    for (int i = 1; i <= q; i++)
    {
        int x = c[i].first, v = c[i].second;
        if (a[x] > 0)
        {
            cnt--;
            modify(1, find(a[x]), -1);
        }
        else
            fsum += a[x];
        if (v > 0)
        {
            cnt++;
            modify(1, find(v), 1);
        }
        else
            fsum -= v;
        a[x] = v;
        int tt = chose(fsum);
        cout << tt + 1 << "\n";
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

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

output:


result: