QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#296049#7685. Barkley IIAlphaMale06WA 69ms15336kbC++142.4kb2024-01-02 01:25:552024-01-02 01:25:55

Judging History

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

  • [2024-01-02 01:25:55]
  • 评测
  • 测评结果:WA
  • 用时:69ms
  • 内存:15336kb
  • [2024-01-02 01:25:55]
  • 提交

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++){
		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(auto p = unq.begin(); p!=unq.end(); p++){
		int i=*p;
		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];
			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(; done<n; done++){
		int val=a[done-1];
		Update(val, -1);
	}
	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();
	}
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 69ms
memory: 15336kb

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
4
4
5
7
11
11
14
14
10
15
6
6
7
12
18
15
5
5
6
27
6
8
27
37
5
5
23
12
42
35
4
30
48
30
7
40
42
44
6
45
54
64
19
54
56
75
6
6
48
7
17
4
74
77
6
6
6
70
7
53
6
69
3
73
61
63
6
7
53
56
85
80
4
80
91
66
6
6
71
5
5
9
77
96
7
84
96
5
12
70
5
6
6
8
89
70
75
5
5
93
7
87
88
2
106
58
102
92
96
97
109
6...

result:

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