QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#600850#7685. Barkley IIFoedere0WA 75ms5568kbC++202.5kb2024-09-29 19:39:532024-09-29 19:39:55

Judging History

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

  • [2024-09-29 19:39:55]
  • 评测
  • 测评结果:WA
  • 用时:75ms
  • 内存:5568kb
  • [2024-09-29 19:39:53]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1000010;
typedef pair<int, int> PII;
int a[N];
int d[N * 4];
unordered_map<int, int> mp;
int n, m;
struct node
{
    int l, r, x;
};
bool cmp(node x, node y)
{
    return x.r < y.r;
}
void updown(int p)
{
    d[p] = d[p * 2] + d[p * 2 + 1];
}
void build(int s, int t, int p)
{
    if (s == t)
    {
        d[p] = 0;
        return;
    }
    int mid = (s + t) / 2;
    build(s, mid, p * 2), build(mid + 1, t, p * 2 + 1);
    return;
}
void chenge(int l, int c, int s, int t, int p)
{
    if (s == t)
    {
        d[p] = c;
        return;
    }
    int mid = (s + t) / 2;
    if (l <= mid)
    {
        chenge(l, c, s, mid, p * 2);
    }
    else
        chenge(l, c, mid + 1, t, p * 2 + 1);
    updown(p);
}
int cnt = 0;
int getsum(int l, int r, int s, int t, int p)
{
    if (s >= l && t <= r)
    {
        return d[p];
    }
    int mid = (s + t) / 2;
    int sum = 0;
    if (l <= mid)
    {
        sum += getsum(l, r, s, mid, p * 2);
    }
    if (r > mid)
    {
        sum += getsum(l, r, mid + 1, t, p * 2 + 1);
    }
    return sum;
}
void solve()
{
    cin >> n >> m;
    build(1, n, 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    vector<node> q;
    q.push_back({0, -1, 0});
    for (int i = 1; i <= n; i++)
    {
        if (a[i] <= n + 1 && mp[a[i]] + 1 < i)
        {
            q.push_back({mp[a[i]] + 1, i - 1, a[i]});
        }
        mp[a[i]] = i;
    }
    for (int i = 1; i <= n; i++)
    {
        if (mp[a[i]] + 1 <= n)
        {
            q.push_back({mp[a[i]] + 1, n, i});
        }
        mp[a[i]] = i;
    }
    sort(q.begin(), q.end(), cmp);
    int now = 1;
    int ans = -1e18;
    for (int i = 1; i <= q.size()-1; i++)
    {
        for (int j = now; j <= q[i].r; j++)
        {
            if (mp[a[j]])
            {
                // cout << a[j] << " " << mp[a[j]] << endl;
                chenge(mp[a[j]], 0, 1, n, 1);
            }
            chenge(j, 1, 1, n, 1);
            mp[a[j]] = j;
        }
        now = q[i].r + 1;
        // cout << now << endl;
        ans = max(ans, getsum(q[i].l, q[i].r, 1, n, 1) - q[i].x);
        // cout << res[q[i].id] << endl;
    }
    cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5552kb

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: 75ms
memory: 5568kb

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:

5
3
2
6
3
4
3
5
5
4
3
4
3
3
5
5
6
5
7
6
4
2
4
2
5
7
7
2
3
4
5
2
4
2
1
4
4
2
6
1
4
6
5
2
4
5
2
3
2
8
5
3
4
6
3
3
6
5
5
5
5
5
6
2
5
1
1
7
6
5
5
6
3
2
4
5
1
5
3
3
5
4
5
3
4
8
4
4
6
5
4
4
2
1
3
4
4
7
5
2
5
3
2
5
6
7
4
1
5
6
3
6
4
4
5
5
6
4
6
7
6
4
5
6
2
5
3
6
5
5
5
4
2
3
5
3
2
2
5
4
3
4
5
5
4
4
4
6
6
5
...

result:

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