QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#639363#7685. Barkley IIyimgWA 118ms4220kbC++202.1kb2024-10-13 19:10:222024-10-13 19:10:23

Judging History

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

  • [2024-10-13 19:10:23]
  • 评测
  • 测评结果:WA
  • 用时:118ms
  • 内存:4220kb
  • [2024-10-13 19:10:22]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
using i64 = long long;
struct node {
	int l, r;
	i64 dat;
};

struct HisSeg {

	int n, idx;
	vector<int> root;
	vector<node> tr;
	HisSeg(int _n, int m) {
		n = _n;
		idx = 0;
		tr.resize(n * 4 + (__lg(n) + 2) * (m), {});
		root.resize(m + 1);
		root[0] = build(0, n);
	}
	int build(int l, int r) {
		int p = ++idx;
		if(r - l == 1) {
			return p;
		}
		int m = l + r >> 1;
		tr[p].l = build(l, m);
		tr[p].r = build(m, r);
		return p;
	}
	void pull(int p){
		tr[p].dat = tr[tr[p].l].dat + tr[tr[p].r].dat;
	}
	int insert(int nv, int v, int x, int val) {
		return root[nv] = insert(root[v], 0, n, x, val);
	}
	int insert(int p, int l, int r, int x, int val) {
		int q = ++idx;
		tr[q] = tr[p];
		if(r - l == 1) {
			tr[q].dat += val;
			return q;
		}
		int m = l + r >> 1;
		if(x < m) tr[q].l = insert(tr[p].l, l, m, x, val);
		else tr[q].r = insert(tr[p].r, m, r, x, val);
		pull(q);
		return q; 
	}
	int query(int l, int vr){
		return query(root[vr], 0, n, l);
	}
	int query(int p, int l, int r, int x){
		if(r - l == 1){
			return tr[p].dat;
		}
		int m = l + r >> 1;
		if(x < m) return query(tr[p].l, l, m, x) + tr[tr[p].r].dat;
		else return query(tr[p].r, m, r, x);
	}
};

void work()
{
	int n, m;
	cin >> n >> m;
	int ans = -1;
	HisSeg his(m + 1, (n + 1) * 2);
	map<int, int> mp;
	bool flag = false;
	vector<int> a(n + 1), lst(m + 1);
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
		mp[a[i]] = 1;
		if(!lst[a[i]]){
			his.insert(i, i - 1, i, 1);
		}
		else{
			his.insert(n + i, i - 1, lst[a[i]], -1);
			his.insert(i, n + i, i, 1);
		}
		ans = max(ans, his.query(lst[a[i]], i) - a[i] - 1);
//		cout << "PPP " << a[i] << " " << his.query(lst[a[i]] , i) << "\n";
		lst[a[i]] = i;
	}
	for(int i = 1; i <= n + 1; ++i){
//		if(lst[i] < n)
		{
			ans = max(ans, his.query(lst[i], n) - i - mp[i]);
//			cout << "HHH : " << i << " " << lst[i] << " " << his.query(lst[i] , n) << "\n";
		}
	}
	cout << ans << "\n";
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	cin >> t;
	while(t--){
		work();
	}
} 

详细

Test #1:

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

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: 118ms
memory: 3644kb

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
2
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:

wrong answer 44th numbers differ - expected: '1', found: '2'