QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#267231 | #7685. Barkley II | urosk | WA | 0ms | 32264kb | C++11 | 2.1kb | 2023-11-27 02:31:28 | 2023-11-27 02:31:29 |
Judging History
answer
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define eb emplace_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define si(a) (ll)(a.size())
using namespace std;
#define maxn 500005
ll n,m;
ll a[maxn];
vector<ll> v[maxn];
ll bit[maxn];
ll sum(ll r) {
ll ret = 0;
for (; r >= 0; r = (r & (r + 1)) - 1)
ret += bit[r];
return ret;
}
ll sum(ll l,ll r) {
return sum(r) - sum(l - 1);
}
void add(ll idx,ll delta) {
for (; idx < maxn; idx = idx | (idx + 1))
bit[idx] += delta;
}
vector<pll> ask[maxn];
ll id[maxn];
void tc(){
cin >> n >> m;
for(ll i = 1;i<=n;i++) cin >> a[i];
for(ll i = 1;i<=n;i++) v[a[i]].pb(i);
for(ll i = 1;i<=m;i++){
ll last = 0;
for(ll x : v[i]){
if(x-1<=last+1) ask[x-1].pb({last+1,i});
last = x;
}
if(n<=last+1) ask[n].pb({last+1,i});
}
ll ans = -llinf;
for(ll i = 1;i<=n;i++){
ll x = a[i];
if(id[x]!=0) add(id[x],-1);
id[x] = i;
add(id[x],1);
for(pll p : ask[i]){
ans = max(ans,sum(p.fi,i)-p.sc);
}
}
cout<<ans<<endl;
for(ll i = 1;i<=m;i++) v[i].clear();
for(ll i = 1;i<=n;i++) ask[i].clear();
for(ll i = 1;i<=m;i++){
if(id[i]!=0) add(id[i],-1);
id[i] = 0;
}
}
int main(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
int t; t = 1;
cin >> t;
while(t--){
tc();
}
return (0-0);
}
/**
2
5 2
1 2 3 4 5
3 1
4 2
7 3
4 3 1 10 3 8 6
4 9
3 8
4 5
**/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 32264kb
input:
2 5 4 1 2 2 3 4 5 10000 5 2 3 4 1
output:
-1 -1
result:
wrong answer 1st numbers differ - expected: '2', found: '-1'