QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#680073#7685. Barkley IIDisplace_#WA 85ms35396kbC++142.4kb2024-10-26 19:42:562024-10-26 19:42:59

Judging History

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

  • [2024-10-26 19:42:59]
  • 评测
  • 测评结果:WA
  • 用时:85ms
  • 内存:35396kb
  • [2024-10-26 19:42:56]
  • 提交

answer

#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dou;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mapa make_pair
typedef long double ld;
typedef unsigned long long ull;
#define ep emplace_back
template <typename T>inline void read(T &x){
	x=0;char c=getchar();bool f=0;
	for(;c<'0'||c>'9';c=getchar()) f|=(c=='-');
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+(c^48);
	x=(f?-x:x);
}
const int N=5e5+10;
int Test, n, m;
int a[N];
int lst[N*2], pre[N];
int rt[N], tidx;
int tr[N*40], ls[N*40], rs[N*40];
inline void add(int &p, int l, int r, int x){
	if(!p) p=++tidx, tr[p]=ls[p]=rs[p]=0;
	++tr[p];
	if(l==r) return ;
	int mid=(l+r)>>1;
	if(x<=mid) add(ls[p], l, mid, x);
	else add(rs[p], mid+1, r, x);
}
inline void add(int x, int y){
	++x;
	for(; x<=n+1; x+=(x&-x)) add(rt[x], 1, n+1, y);
}
inline int get(int p, int l, int r, int L, int R){
	if(L>R) return 0; 
	if(!p) return 0;
	if(L<=l&&r<=R) return tr[p];
	int mid=(l+r)>>1, ret=0;
	if(L<=mid) ret+=get(ls[p], l, mid, L, R);
	if(R>mid) ret+=get(rs[p], mid+1, r, L, R);
	return ret;
}
inline int get(int l1, int r1, int l, int r){
	if(l1>r1) return 0;
	if(l>r) return 0;
	int ret=0;
	++r1;
	for(; l1; l1-=(l1&-l1)) ret-=get(rt[l1], 1, n+1, l, r);
	for(; r1; r1-=(r1&-r1)) ret+=get(rt[r1], 1, n+1, l, r);
	return ret;
}
vector<int> vec[N*2];
int main(){
	// freopen("D:\\nya\\acm\\A\\test.in","r",stdin);
	// freopen("D:\\nya\\acm\\A\\test.out","w",stdout);
	read(Test);
	while(Test--){
		read(n); read(m);
		unordered_map<int, int> h;
		int idx=n+2;
		a[0]=0;
		for(int i=1; i<=n; ++i) {
			read(a[i]); a[0]=max(a[0], a[i]);
			if(a[i]>=n+2){
				if(h.find(a[i])==h.end()) h[a[i]]=idx, idx++;
				a[i]=h[a[i]];
			}
		}
		if(a[0]==1){
			printf("-1\n");
			continue ;
		}
		for(int i=1; i<=n+1; ++i) rt[i]=0;
		tidx=0;
		for(int i=1; i<=idx; ++i) lst[i]=0, vec[i].clear(), vec[i].ep(0);
		for(int i=1; i<=n; ++i){
			pre[i]=lst[a[i]]; lst[a[i]]=i;
			add(pre[i], i);
			vec[a[i]].ep(i);
		}
		for(int i=1; i<=idx; ++i) add(lst[i], n+1);
		int ans=0;
		for(int i=1; i<=n+1; ++i){
			vec[i].ep(n+1);
			ans=max(ans, get(1, vec[i][1]-1, vec[i][2], n+1)-i);
			for(int j=1, cur; j<(int)vec[i].size()-1; ++j){
				cur=get(0, vec[i][j]-1, vec[i][j]+1, vec[i][j+1]-1)-i;
				ans=max(ans, cur);
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 35396kb

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: 85ms
memory: 27456kb

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:

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

result:

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