QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#678617#7787. Maximum Ratingyumingsk#WA 0ms3784kbC++203.2kb2024-10-26 15:33:142024-10-26 15:33:14

Judging History

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

  • [2024-10-26 15:33:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3784kb
  • [2024-10-26 15:33:14]
  • 提交

answer

#pragma GCC optimize(3, "Ofast", "inline")
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define L_INF 0x7f3f3f3f3f3f3f3f
#define db cout << "debug\n";

using namespace std;
const int Mod = 998244353;
using ll = long long;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1, 0);
    vector<int> b(n + 1, 0);
    ll sum_fu = 0;
    ll sum_zh = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] > 0)
            sum_zh += a[i];
        else if (a[i] < 0)
            sum_fu += -a[i];
    }
    set<pair<int, int>> sepre;
    set<pair<int, int>> sesuf;
    ll sum_pre = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] > 0)
            sesuf.insert({a[i], i});
    }
    while (sum_pre <= sum_fu && sesuf.size())
    {
        sepre.insert(*sesuf.begin());
        b[(*sesuf.begin()).second] = 1;
        sum_pre += (*sesuf.begin()).first;
        sesuf.erase(*sesuf.begin());
    }
    // cout << sesuf.size() << '\n';
    // for (auto v : sesuf)
    // {
    //     cout << v.first << ' ' << v.second << '\n';
    // }
    while (m--)
    {
        int p, v;
        cin >> p >> v;
        // cout << "a[p]" << a[p] << ' ' << b[p] << '\n';
        if (b[p] == 1)
        {
            // if (sepre.size())
            // for (auto v : sepre)
            // {
            //     cout << v.first << ' ' << v.second << '\n';
            // }

            sepre.erase(sepre.find({a[p], p}));
            b[p] = 0;
            sum_pre -= a[p];
            // cout << "siz" << ' ' << sepre.size() << '\n';
        }
        else
        {
            if (a[p] > 0)
            {
                // cout << a[p] << ' ' << p << '\n';
                sesuf.erase(sesuf.find({a[p], p}));
                sum_zh -= a[p];
            }
            else
            {
                sum_fu -= -a[p];
            }
        }
        if (v > 0)
        {
            sum_zh += v;
            sesuf.insert({v, p});
        }
        else
        {
            sum_fu += -v;
        }
        while (sum_pre <= sum_fu && sesuf.size())
        {
            sepre.insert(*sesuf.begin());
            b[(*sesuf.begin()).second] = 1;
            sum_pre += (*sesuf.begin()).first;
            sesuf.erase(*sesuf.begin());
        }
        a[p] = v;
        // cout << m << " ";
        // for (auto v : sepre)
        // {
        //     cout << v.first << ' ' << v.second << '\n';
        // }
        // cout << sum_pre << ' ' << ' ' << sum_fu << '\n';
        // cout << sepre.size() << " " << sesuf.size() << '\n';
        cout << sepre.size() + sesuf.size() - (sum_pre <= sum_fu ? 0 : sesuf.size() + 1) + 1 << '\n';
    }
}
int main()
{
    // IOS;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#ifndef ONLINE_JUDGE
    clock_t start_time = clock();
#endif
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
#ifndef ONLINE_JUDGE
    cout << "Used " << (double)(clock() - start_time) << " ms" << endl;
#endif
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3784kb

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: -100
Wrong Answer
time: 0ms
memory: 3524kb

input:

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

output:

1
2
1
2
2

result:

wrong answer 5th numbers differ - expected: '1', found: '2'