QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#608315#5278. Mex and Cardswdbl857WA 1ms9884kbC++204.8kb2024-10-03 20:38:272024-10-03 20:38:28

Judging History

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

  • [2024-10-03 20:38:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9884kb
  • [2024-10-03 20:38:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define xx first
#define yy second
#define endl "\n"
#define pb push_back
#define int long long
#define ll long long
#define lowbit(x) x & (-x)
typedef pair<int, int> pii;
#define LF(x) fixed << setprecision(x)
#define Yshanqian ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
const int N = 3e5 + 10, M = 1010, inf = 0x3f3f3f3f, mod = 1e9 + 7, P = 13331;
int n;
int a[N], b[N];
multiset<int> st;
struct node
{
    int l, r;
    int mn, lazy;
} tr[N << 2];
void pushup(int u)
{
    tr[u].mn = min(tr[u << 1].mn, tr[u << 1 | 1].mn);
}
void build(int u, int l, int r)
{
    tr[u] = {l, r, 0, 0};
    if (l == r)
        return;
    int mid = l + r >> 1;
    build(u << 1, l, mid);
    build(u << 1 | 1, mid + 1, r);
}
void change(int u, int x)
{
    tr[u].mn += x;
    tr[u].lazy += x;
}
void pushdown(int u)
{
    if (tr[u].lazy)
    {
        change(u << 1, tr[u].lazy);
        change(u << 1 | 1, tr[u].lazy);
        tr[u].lazy = 0;
    }
}
void modify(int u, int l, int r, int x)
{
    if (tr[u].l >= l && tr[u].r <= r)
    {
        change(u, x);
        return;
    }
    pushdown(u);
    int mid = tr[u].l + tr[u].r >> 1;
    if (l <= mid)
        modify(u << 1, l, r, x);
    if (r > mid)
        modify(u << 1 | 1, l, r, x);
    pushup(u);
}
int ask(int u, int l, int r)
{
    if (tr[u].l >= l && tr[u].r <= r)
        return tr[u].mn;
    pushdown(u);
    int mid = tr[u].l + tr[u].r >> 1;
    int ans = inf;
    if (l <= mid)
        ans = min(ans, ask(u << 1, l, r));
    if (r > mid)
        ans = min(ans, ask(u << 1 | 1, l, r));
    return ans;
}
int c[N];
void solve()
{
    int ans = 0;
    cin >> n;
    build(1, 1, n + 10);
    int mn = inf;
    b[0] = inf;
    int lst = -1;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        b[i] = min(b[i - 1], a[i]);
        if (b[i] != 0)
            lst = i;
    }

    int s = 0;
    for (int i = lst; i >= 1; i--)
    {
        if (b[i] > s)
        {
            ans += i * (b[i] - s);
            for (int j = s; j < b[i]; j++)
                st.insert(i);
        }
        if (a[i] - b[i] > 0)
            modify(1, i, i, a[i] - b[i]);
        s = b[i];
    }

    for (int i = lst + 1; i <= n; i++)
    {
        if (a[i])
            modify(1, i, i, a[i]);
    }
    cout << ans << endl;
    int q;
    cin >> q;
    while (q--)
    {
        int op, x;
        cin >> op >> x;
        x++;
        if (op == 1)
        {
            if (x == 1)
            {
                if (ask(1, 2, 2) == 0)
                {
                    ans++;
                    st.insert(1);
                }
                else
                {
                    int l = 0, r = 2e5 + 10;
                    while (l < r)
                    {
                        int mid = l + r + 1 >> 1;
                        if (ask(1, x + 1, x + mid + 1))
                            l = mid;
                        else
                            r = mid - 1;
                    }
                    ans += r + 2;
                    modify(1, x + 1, x + 1 + r, -1);
                    st.insert(x + r + 1);
                }
            }
            else
            {
                if (st.find(x - 1) != st.end())
                {
                    int l = 0, r = 2e5 + 10;
                    while (l < r)
                    {
                        int mid = l + r + 1 >> 1;
                        if (ask(1, x + 1, x + 1 + mid))
                            l = mid;
                        else
                            r = mid - 1;
                    }
                    // cout << "---" << ask(1, 4, 5) << endl;
                    //  cout << "---" << l << endl;
                    if (ask(1, x + 1, x + 1))
                    {
                        ans += r + 2;
                        modify(1, x + 1, x + 1 + r, -1);
                        st.erase(st.find(x - 1));
                        st.insert(x + r);
                    }
                }
                else
                    modify(1, x, x, 1);
            }
        }
        else
        {
            if (ask(1, x, x))
            {
                modify(1, x, x, -1);
            }
            else
            {
                auto it = st.lower_bound(x);
                if (it != st.end())
                    st.erase(it);
                int now = *it;
                ans -= now - x + 2;
                modify(1, x + 1, now, 1);
            }
        }
        cout << ans << endl;
    }
}
signed main()
{
    Yshanqian;
    int T;
    T = 1;
    // cin >> T;
    for (int cases = 1; cases <= T; ++cases)
    {
        // cout<<"Case #"<<cases<<": ";
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
2 1 3 0 2
6
1 0
1 1
2 4
1 3
2 1
2 1

output:

4
5
7
7
9
7
3

result:

ok 7 numbers

Test #2:

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

input:

1
0
0

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

10
3 8 1 4 10 3 10 9 7 10
20
2 5
1 4
1 2
1 4
1 3
1 3
1 0
2 8
1 5
1 4
1 0
1 3
1 8
1 6
1 4
1 1
1 5
1 9
1 6
2 7

output:

14
14
14
22
22
22
22
24
24
24
24
26
26
26
26
26
26
26
26
26
26

result:

ok 21 numbers

Test #4:

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

input:

10
9 8 7 5 5 4 3 2 1 1
20
2 4
1 8
2 6
1 2
1 2
2 5
2 2
1 0
1 6
1 6
2 9
1 2
2 7
2 8
2 3
1 9
1 7
1 4
2 6
1 7

output:

45
43
43
41
41
41
39
37
38
38
38
36
36
34
37
35
35
35
35
35
35

result:

wrong answer 2nd numbers differ - expected: '44', found: '43'