QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#679498#7787. Maximum RatingheyuhaoWA 1ms7744kbC++204.5kb2024-10-26 17:44:382024-10-26 17:44:41

Judging History

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

  • [2024-10-26 17:44:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7744kb
  • [2024-10-26 17:44:38]
  • 提交

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 >> 1;
        if (query(1, 1, mid) <= sum)
            l = mid;
        else
            r = mid - 1;
    }
    if (r == 1 && query(1, 1, 1) > sum)
        r=0;
    int r1 = r+1;
    while (dquery(1, 1, 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);
        ans += left / x;
    }
    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: 100
Accepted
time: 1ms
memory: 7672kb

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: 1ms
memory: 7660kb

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: 1ms
memory: 7728kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7672kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 1ms
memory: 7744kb

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
1
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
4...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 1ms
memory: 7684kb

input:

1000 1000
1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000...

output:

500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
...

result:

ok 1000 numbers

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 7744kb

input:

1000 1000
-485078954 -474724347 -284958745 -99994191 -853392841 -796786314 -87134718 -861459498 -982809180 -184620712 -618476092 -244916830 -349486182 -751407510 -874417202 -419521829 -888338757 -735353446 -426330733 -715383449 -48093437 -359419189 -474876639 -887614191 -157085227 -51186523 -4851821...

output:

2
3
4
5
6
7
8
9
10
11
12
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
51
52
53
54
55
56
57
58
59
60
60
61
62
63
64
65
65
66
67
68
69
70
71
72
73
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
88
89
90
91
92
92
93
94
95
96...

result:

wrong answer 746th numbers differ - expected: '505', found: '506'