QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#488522#7685. Barkley IIlyccWA 96ms13976kbC++202.6kb2024-07-24 09:31:352024-07-24 09:31:36

Judging History

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

  • [2024-07-24 09:31:36]
  • 评测
  • 测评结果:WA
  • 用时:96ms
  • 内存:13976kb
  • [2024-07-24 09:31:35]
  • 提交

answer

// Author: lycc
//
// NOIp 2024 rp++
// 
// 2024 Grand Master

#include<bits/stdc++.h>
#define int long long
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define pb emplace_back
#define For(i, x, y) for (int i = (x); i <= (y); i++)
#define rep(i, x, y) for (int i = (x); i >= (y); i--)
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define ull unsigned long long
#define uint unsigned int
#define ls (p << 1)
#define rs (p << 1 | 1)
#define mp make_pair
#define i128 __int128
#define db long double
#define vi vector<int>
using namespace std;
mt19937_64 rnd(time(0));
void cmin(int &x, int y) { x = min(x, y); return; }
void cmax(int &x, int y) { x = max(x, y); return; }
int ksm(int x, int y, int p) {
    int v = 1; x %= p;
    while (y) v = 1ll * v * ((y & 1) ? x : 1) % p, x = 1ll * x * x % p, y >>= 1;
    return (v % p + p) % p;
}
bool MemoryST;
const int N = 1e6 + 30;
const int mod = 998244353;
const long long INF = 1e15;
int n, m, a[N];
int fst[N], nex[N], lst[N], pre[N];
vector< pii > q[N];
int c[N];
void add(int x, int v) {
	if (!x) return;
	while (x <= m) c[x] += v, x += x & -x;
	return;
}
int query(int x) {
	int res = 0;
	while (x) res += c[x], x -= x & -x;
	return res;
}
int query(int x, int y) {
	return query(y) - query(x - 1);
}
void solve() {
	int _, ans = 0;
	cin >> n >> _;
	m = 2 * n + 10;
	int tot = n + 1;
	map< int, int > f;
	For (i, 1, m) pre[i] = nex[i] = lst[i] = fst[i] = 0;
	For (i, 1, n) {
		cin >> a[i];
		if (a[i] >= n + 2) {
			if (f.count(a[i])) a[i] = f[a[i]];
			else f[a[i]] = ++tot, a[i] = tot;
		} 
		if (!fst[a[i]]) fst[a[i]] = i;
		pre[i] = lst[a[i]];
		nex[lst[a[i]]] = i; lst[a[i]] = i;
	}
	For (i, 1, n) q[i].clear();
	For (i, 1, n + 1) {
		if (!fst[i]) q[n].pb(1, i);
		else {
			int now = fst[i];
			if (now != 1) q[now - 1].pb(1, i);
			while (nex[now]) {
				if (now + 1 <= nex[now] - 1) q[nex[now] - 1].pb(now + 1, i);
				now = nex[now];
			}
			if (now < n) q[n].pb(now + 1, i);
		}
	}
	For (i, 1, m) c[i] = 0;
	For (r, 1, n) {
		add(pre[r], -1);
		add(r, 1);
		for (auto [l, i] : q[r]) cmax(ans, query(l, r) - i);
	}
	cout << ans << endl;
    return;
}
bool MemoryED;
signed main() {
    ios::sync_with_stdio(0);
    //cin.tie(0), cout.tie(0);
    //cerr << fixed << setprecision(6) << (&MemoryST - &MemoryED) / 1048576.0 << "MB\n";
    int TESTCNT = 1;
    cin >> TESTCNT;
    while (TESTCNT--) solve();
    //cerr << endl << 1e3 * clock() / CLOCKS_PER_SEC << "ms"; 
    return 0;
}

詳細信息

Test #1:

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

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: 0
Accepted
time: 48ms
memory: 13936kb

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:

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

result:

ok 50000 numbers

Test #3:

score: -100
Wrong Answer
time: 96ms
memory: 13976kb

input:

100000
5 4
4 3 1 3 1
5 4
2 2 1 3 4
5 9
7 8 7 1 3
5 3
3 2 2 3 1
5 7
1 4 2 4 7
5 4
4 4 4 2 3
5 3
2 1 2 2 2
5 5
2 1 2 5 4
5 9
1 8 4 4 7
5 6
2 6 4 6 2
5 5
1 2 4 4 4
5 3
2 1 1 1 3
5 5
5 4 5 2 5
5 4
3 3 3 2 1
5 3
3 1 3 2 3
5 7
1 5 2 2 7
5 6
2 2 6 5 6
5 10
6 3 3 1 7
5 8
1 6 8 4 3
5 4
1 2 1 3 3
5 7
2 2 4 3 ...

output:

1
1
2
1
2
2
0
2
2
2
1
0
2
1
1
2
2
2
3
0
3
1
2
2
3
3
1
3
0
0
3
2
2
0
2
2
1
0
2
2
3
3
3
1
3
2
2
3
2
3
2
1
2
3
1
3
3
1
2
3
1
1
2
2
2
2
0
1
0
1
0
2
1
3
0
2
2
3
2
2
1
3
1
3
1
1
1
3
1
1
4
0
1
3
2
2
2
0
3
2
4
3
3
2
1
0
4
4
3
2
1
2
1
2
3
2
3
4
4
3
0
0
1
4
1
3
3
2
3
1
3
4
3
1
2
2
3
2
3
2
3
3
1
3
1
1
4
1
1
3
...

result:

wrong answer 2377th numbers differ - expected: '-1', found: '0'