QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#670800 | #7685. Barkley II | Sred | WA | 0ms | 3712kb | C++17 | 1003b | 2024-10-24 01:41:54 | 2024-10-24 01:41:54 |
Judging History
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'