QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#592266 | #7685. Barkley II | sazhi | WA | 41ms | 3704kb | C++20 | 2.0kb | 2024-09-26 21:40:00 | 2024-09-26 21:40:01 |
Judging History
answer
// author: jieda
// file: cpp
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
# define fi first
# define se second
# define all(x) x.begin(),x.end()
# define stst stringstream
# define pb push_back
# define pf push_front
# define pp push
# define lowbit(x) (x)&(-x)
# define fa(i,op,n) for (ll i = op; i <= n; i++)
# define fb(j,op,n) for (ll j = op; j >= n; j--)
# define fg(i,op,n) for (ll i = op; i != n; i = ne[i])
int dx[4] = {-1,0,1,0},dy[4] = {0,1,0,-1};
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const ll N = 5e5+10,M = 1e5+10,INF = 0x3f3f3f3f,mod = 1e9+7;
const ll MOD = 212370440130137957ll;//hash(hight)
const int base = 131;
const double eps = 1e-3;
const int seed=10086,mo=1e6+7; //hash(lower)
int prime = 233317;
struct qujian{
int l,r,mex;
};
void solve(){
int n,m;cin>>n>>m;
vector<int> sum(max(n,m)+10),a(n+10),pre(max(n,m)+10);
vector<qujian> st;
fa(i,1,n){
cin>>a[i];
}
auto update = [&](int x,int k)->void {
while(x<=n){
sum[x] += k;
x+= lowbit(x);
}
};
auto query = [&](int x) ->ll{
ll res = 0;
while(x){
res +=sum[x];
x -= lowbit(x);
}
return res;
};
fa(i,1,n){
if(a[i]+1<=n&&pre[a[i]]+1<i){
st.pb({pre[a[i]]+1,i-1,a[i]});
}
pre[a[i]] = i;
}
fa(i,1,n+1){
if(pre[a[i]]+1<=n){
st.pb({pre[a[i]]+1,n,a[i]});
}
}
sort(all(st),[&](qujian x,qujian y){
return x.r<y.r;
});
for(int i = 1;i<=n;i++){
pre[a[i]] = 0;
}
int now = 0;
ll ans = -1;
for(int i = 0;i<n;i++){
while(now<st[i].r){
now++;
if(pre[a[now]]){
update(now,-1);
}
pre[a[now]] = now;
update(now,1);
ans = max(ans,query(st[i].r)-query(st[i].l-1)-st[i].mex);
}
}
cout<<ans<<'\n';
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t = 1;
cin>>t;
while(t--){
solve();
}
return 0;
}
/**/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3704kb
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: 41ms
memory: 3620kb
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:
2 6 0 8 1 3 5 3 3 6 6 7 2 3 -1 7 1 3 7 8 6 3 -1 1 4 4 3 2 6 0 5 4 6 2 5 7 3 5 8 5 6 5 7 5 2 3 5 5 1 4 1 2 1 4 6 2 8 2 1 1 4 2 3 5 7 5 4 2 9 3 2 2 6 5 7 7 -1 6 1 3 3 7 7 6 1 1 4 2 3 5 7 1 0 4 1 2 1 4 7 3 7 2 1 3 4 4 6 -1 1 4 5 5 4 7 2 4 6 8 4 3 2 3 5 1 6 3 3 3 7 -1 3 6 -1 2 7 -1 5 0 4 4 5 2 4 7 7 3 -...
result:
wrong answer 1st numbers differ - expected: '6', found: '2'