QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#670800#7685. Barkley IISredWA 0ms3712kbC++171003b2024-10-24 01:41:542024-10-24 01:41:54

Judging History

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

  • [2024-10-24 01:41:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3712kb
  • [2024-10-24 01:41:54]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e6 + 5;
const int inf = 2e6;
int f[maxn],a[maxn];
int n,m;
int lowbit(int k){
	 return k&(-k);
}
void add(int i,int k){
	for(;i <= m*2;i += lowbit(i)) f[i] += k;
}
int find(int i){
	int ans = 0;
	for(;i >= 1; i-= lowbit(i)) ans += f[i];
	return ans;
	
}
map<int,int> mp; 
void solve(){
	
	
	cin >> n >> m;
	int ans = -2;
 	for(int i = 1 ;i <= n ;i ++) {
 		cin >> a[i];
 		ans = max(a[i] - 1,ans);
 	}
	for(int i = 1;i <= n ;i ++){
		
		ans = max(ans,find(i) - find(mp[a[i]]) - a[i]);
		if(mp[a[i]]) add(mp[a[i]],-1);
		add(i,1);
		mp[a[i]] = i;
		
	}
	for(int i = 1;i <= n ;i ++){
		    ans = max(ans,find(n) - find(mp[a[i]]) - a[i]); 
	}
	for(int i = 1;i <= n;i ++){
		 if(mp[a[i]]){
            add(i,-1);
        }
		 mp[a[i]] = 0;
	}
	cout << ans <<endl;
} 
signed main() {
    int t = 1;
   cin >> t;
    while (t--) {
       solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3712kb

input:

2
5 4
1 2 2 3 4
5 10000
5 2 3 4 1

output:

3
4

result:

wrong answer 1st numbers differ - expected: '2', found: '3'