QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#296048#7685. Barkley IIAlphaMale06WA 53ms20184kbC++142.4kb2024-01-02 01:08:062024-01-02 01:08:06

Judging History

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

  • [2024-01-02 01:08:06]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:20184kb
  • [2024-01-02 01:08:06]
  • 提交

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){
	for(int i=ind; i<M; i+=i&-i)f[i]+=val;
}

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;
	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++){
		if(a[i]<index)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)q.pb({1, pos[i][0]-1, i});
		if(pos[i][sz-1]!=n)q.pb({pos[i][sz-1]+1, n, i});
		for(int j=1; j< sz-1; j++){
			if(pos[i][j-1]+1!=pos[i][j])
			q.pb({pos[i][j-1]+1, pos[i][j]-1, i});
		}
	}
	sort(all(q), cmp);
	for(int i=1; i< index; i++){
		if(cnt[i]!=pos[i].size()){
			Update(pos[i][0], 1);
			cnt[i]++;
		}
	}
	int done=1;
	for(qry qs : q){
		while(qs.l>done){
			int val=a[done-1];
			if(val<index){
				Update(val, -1);
				if(cnt[val]!=pos[val].size()){
					Update(pos[val][cnt[val]], 1);
					cnt[val]++;
				}
			}
			done++;
		}
		ans=max(ans, Get(qs.l, qs.r)-qs.mex);
	}
	cout << ans << '\n';
	for(int i=0; i<=index; i++){
		f[i]=0;
		pos[i].clear();
		cnt[i]=0;
	}
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 53ms
memory: 17912kb

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
3
2
4
6
7
4
4
4
4
3
8
6
6
7
7
7
7
5
5
6
10
6
8
7
6
5
5
7
5
4
5
4
16
9
8
7
19
17
20
6
26
15
13
11
16
12
16
6
6
13
7
11
4
31
14
6
6
6
15
7
32
6
33
3
16
17
17
6
7
15
3
32
41
4
40
41
42
6
6
45
5
5
9
45
45
7
46
47
5
2
47
5
6
6
8
49
50
49
5
5
47
7
48
49
2
46
52
54
49
49
54
50
6
50
55
56
49
7
54
57
7...

result:

wrong answer 4th numbers differ - expected: '4', found: '3'