QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#267206#7685. Barkley IIsofija6WA 67ms5456kbC++142.0kb2023-11-27 02:03:212023-11-27 02:03:21

Judging History

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

  • [2023-11-27 02:03:21]
  • 评测
  • 测评结果:WA
  • 用时:67ms
  • 内存:5456kb
  • [2023-11-27 02:03:21]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define MAXN 500010
using namespace std;
ll n,m,sz,last[MAXN],a[MAXN];
struct seg_tree
{
    vector<ll> st;
    void Init()
    {
        sz=1;
        while (sz<n)
            sz <<= 1;
        st.resize(2*sz+2);
        fill(st.begin(),st.end(),0ll);
    }
    void Add(ll pos,ll val,ll x,ll lx,ll rx)
    {
        if (lx==rx)
        {
            st[x]=val;
            return;
        }
        ll mid=(lx+rx)/2;
        if (pos<=mid)
            Add(pos,val,2*x,lx,mid);
        else
            Add(pos,val,2*x+1,mid+1,rx);
        st[x]=st[2*x]+st[2*x+1];
    }
    ll Calc(ll l,ll r,ll x,ll lx,ll rx)
    {
        if (lx>r || rx<l)
            return 0;
        if (lx>=l && rx<=r)
            return st[x];
        ll mid=(lx+rx)/2;
        return Calc(l,r,2*x,lx,mid)+Calc(l,r,2*x+1,mid+1,rx);
    }
};
seg_tree S;
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll t;
    cin >> t;
    while (t--)
    {
        cin >> n >> m;
        S.Init();
        for (ll i=1;i<=n;i++)
            cin >> a[i];
        set<ll> s;
        ll ans=LLONG_MIN;
        for (ll i=1;i<=n;i++)
        {
            if (!s.count(a[i]))
            {
                if (i>1)
                    ans=max(ans,S.Calc(1,i-1,1,1,sz)-a[i]);
                s.insert(a[i]);
                last[a[i]]=i;
                S.Add(i,1,1,1,sz);
                continue;
            }
            if (last[a[i]]+1<i)
                ans=max(ans,S.Calc(last[a[i]]+1,i-1,1,1,sz)-a[i]);
            S.Add(last[a[i]],0,1,1,sz);
            last[a[i]]=i;
            S.Add(i,1,1,1,sz);
        }
        for (auto i : s)
        {
            if (last[i]!=n)
                ans=max(ans,S.Calc(last[i]+1,n,1,1,sz)-i);
        }
        ll cur=1;
        while (cur<=m && s.count(cur))
            cur++;
        if (cur<=m)
            ans=max(ans,(ll)s.size()-m);
        cout << ans << "\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
5 4
1 2 2 3 4
5 10000
5 2 3 4 1

output:

2
3

result:

ok 2 number(s): "2 3"

Test #2:

score: -100
Wrong Answer
time: 67ms
memory: 5440kb

input:

50000
10 19
12 6 1 12 11 15 4 1 13 18
10 8
8 7 6 7 6 2 2 3 4 8
10 6
3 2 6 6 5 2 3 4 5 6
10 11
6 3 7 9 2 1 2 10 10 4
10 6
6 1 2 6 1 1 3 4 2 1
10 9
8 5 3 9 1 7 5 5 1 1
10 5
1 4 3 2 5 4 5 3 5 2
10 14
3 8 12 10 4 2 3 13 7 3
10 14
5 5 12 2 8 1 13 9 8 5
10 7
5 5 6 6 1 5 3 7 3 4
10 7
5 1 4 6 1 6 4 3 7 5
10...

output:

3
1
2
4
2
3
3
3
3
3
4
5
2
3
-1
3
1
3
7
6
3
3
-1
2
4
4
6
2
3
0
6
1
2
2
2
5
3
3
3
3
2
5
2
1
3
3
2
3
1
4
2
2
4
4
2
2
5
3
2
1
4
3
3
3
2
3
0
4
7
6
2
2
4
3
3
4
-2
6
3
3
3
3
4
0
1
1
4
5
4
5
3
1
1
2
1
3
3
4
4
3
4
2
1
3
4
4
3
-1
3
4
3
5
4
4
2
4
6
4
4
5
3
4
5
1
4
3
3
3
3
-2
3
2
1
2
5
1
2
1
4
4
2
2
4
5
4
3
-4
...

result:

wrong answer 1st numbers differ - expected: '6', found: '3'