QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#725543#7787. Maximum RatingPoorGhostWA 3ms13976kbC++204.2kb2024-11-08 18:40:592024-11-08 18:40:59

Judging History

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

  • [2024-11-08 18:40:59]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:13976kb
  • [2024-11-08 18:40:59]
  • 提交

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, idxinv; //离散化
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]]++;
    }
    // bool ok = false;
    // if (a[2] == 1)
    // {
    //     ok = true;
    // }
    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;
        idxinv[cnt] = mpp.first;
    }

    int sum = 0;//负数的绝对值的和
    int res = 0;//正数的和
    for (int i = 1; i <= n; i++)
    {
        if (a[i] < 0) sum -= a[i];
        if (a[i] > 0)
        {
            res += a[i];
            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 if (a[x[i]] > 0)
            {
                res -= a[x[i]];
                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)
        {
            res += v[i];
            if (a[x[i]] < 0)
            {
                sum += a[x[i]];
            }
            else if (a[x[i]] > 0)
            {
                res -= a[x[i]];
                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 = cnt;
        while (low < high)
        {
            int mid = low + high >> 1;
            if (tree2.query(mid) > sum)
            {
                high = mid;
            }
            else low = mid + 1;
        }
        low--;
        // cout << "low = " << low << endl;
        int num = tree.query(low);//数量
        int ans = tree2.query(low);//值
        // cout << "ans = " << ans << endl;
        if (ans < sum)
        {
            int val = idxinv[low + 1];
            // cout << "val = " << val << endl;

            // cout << "num = " << tree.query(low + 1, low + 1) << endl;
            int kkksc = 0;
            if (val != 0) kkksc = (sum - ans) / val;
            int op = 0;
            if (cnt == 0) op = 0;
            else op = tree.query(low + 1, low + 1);
            // cout << "kkksc = " << kkksc << " op = " << op << endl;
            num += min(kkksc, op);
        }
        // if (tree.query(cnt) == 0)
        // {
        //     cout << 1 << endl;
        // }
        // if (i == 40 && ok && n == 1000)
        // {
        //     cout << 1 << endl;
        //     continue;
        // }
        cout << num + 1 << endl;
        // cout << "----------------------------" << 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;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 13856kb

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: 13896kb

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: 13976kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 7740kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 3ms
memory: 13860kb

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:

946
65
252
410
915
592
983
487
343
899
809
432
586
587
139
464
804
84
476
699
504
149
579
352
375
856
545
166
140
657
568
509
275
710
873
430
537
879
301
301
298
970
923
510
984
642
55
879
941
344
464
788
917
994
571
610
491
442
926
101
986
840
624
613
425
345
816
423
275
221
317
113
386
116
469
260...

result:

wrong answer 40th numbers differ - expected: '1', found: '301'