QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#296052#7685. Barkley IIAlphaMale06WA 81ms15316kbC++142.6kb2024-01-02 01:39:462024-01-02 01:39:48

Judging History

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

  • [2024-01-02 01:39:48]
  • 评测
  • 测评结果:WA
  • 用时:81ms
  • 内存:15316kb
  • [2024-01-02 01:39:46]
  • 提交

answer

#include <bits/stdc++.h>

/*
	Oce nas,
	koji si na nebesima,
	da se sveti ime Tvoje,
	da dodje carstvo Tvoje,
	da bude volja Tvoja,
	i na zemlji, kao i na nebu.
	
	Hleb nas nasusni daj nam danas,
	i oprosti nam dugove nase,
	kao sto i mi oprastamo duznicima svojim,
	i ne uvedi nas u iskusenje,
	no izbavi nas od zloga.
	
	Jer je Tvoje Carstvo,
	i sila, i slava,
	u vekove vekova.
	
	Amin.
*/

using namespace std;
typedef vector<int> vc;
typedef vector<vector<int>> vvc;
using ll = long long;
using ld = long double;
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define int long long

const int M = 5e5+3;

int f[M];
vector<int> pos[M];
int cnt[M];

struct qry{
	int l, r, mex;
};

bool cmp(qry a, qry b){
	return a.l < b.l;
}


void Update(int ind, int val, vector<int> & reset){
	for(int i=ind; i<M; i+=i&-i){
		f[i]+=val;
		reset.pb(i);
	}
}

int Get(int ind){
	int ret=0;
	for(int i=ind; i>0; i-=i&-i)ret+=f[i];
	return ret;
}

int Get(int l, int r){
	return Get(r)-Get(l-1);
}

void solve(){
	int n, m;
	cin >> n >> m;
	int a[n];
	set<int> unq;
	vector<int> reset;
	for(int i=0; i< n; i++){
		cin >> a[i];
		unq.insert(a[i]);
	}
	int ans=-1;
	int index=1;
	for(auto p =unq.begin(); p!=unq.end(); p++){
		if(*p!=index)break;
		index++;
	}
	ans=max(ans, (int)unq.size()-index);
	for(int i=0; i< n; i++){
		pos[a[i]].pb(i+1);
	}	
	vector<qry> q;
	for(int i=1; i< index; i++){
		int sz=pos[i].size();
		if(pos[i][0]!=1){
			if(pos[i][0]-1-i>ans)
				q.pb({1, pos[i][0]-1, i});
		}
		if(pos[i][sz-1]!=n){
			if(n-pos[i][sz-1]-i>ans)
				q.pb({pos[i][sz-1]+1, n, i});
		}
		for(int j=1; j< sz; j++){
			if(pos[i][j-1]+1!=pos[i][j] && pos[i][j]-pos[i][j-1]-1-i>ans)
				q.pb({pos[i][j-1]+1, pos[i][j]-1, i});
		}
	}
	sort(all(q), cmp);
	for(auto p = unq.begin(); p!=unq.end(); p++){
		int i=*p;
		if(cnt[i]!=pos[i].size()){
			Update(pos[i][0], 1, reset);
			cnt[i]++;
		}
	}
	int done=1;
	for(qry qs : q){
		while(qs.l>done){
			int val=a[done-1];
			Update(val, -1, reset);
			if(cnt[val]!=pos[val].size()){
				Update(pos[val][cnt[val]], 1, reset);
				cnt[val]++;
			}
			done++;
		}
		ans=max(ans, Get(qs.l, qs.r)-qs.mex);
	}
	cout << ans << '\n';
	for(int e : reset){
		f[e]=0;
	}
	for(auto p =unq.begin(); p!=unq.end(); p++){
		cnt[*p]=0;
		pos[*p].clear();
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	cin >> t;
	while(t--){
		solve();
	}
	
}

详细

Test #1:

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

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: 81ms
memory: 15220kb

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
5
2
2
3
4
5
3
3
7
3
2
5
6
1
2
5
3
2
3
8
6
6
5
7
4
4
5
4
6
6
6
3
7
3
6
3
3
7
6
6
6
7
4
3
3
3
4
6
2
4
6
6
3
5
5
9
4
4
7
5
3
5
2
1
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 31st numbers differ - expected: '6', found: '5'