QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#680060 | #7685. Barkley II | Displace_# | WA | 79ms | 38916kb | C++14 | 2.5kb | 2024-10-26 19:40:46 | 2024-10-26 19:40:47 |
Judging History
answer
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dou;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mapa make_pair
typedef long double ld;
typedef unsigned long long ull;
#define ep emplace_back
template <typename T>inline void read(T &x){
x=0;char c=getchar();bool f=0;
for(;c<'0'||c>'9';c=getchar()) f|=(c=='-');
for(;c>='0'&&c<='9';c=getchar())
x=(x<<1)+(x<<3)+(c^48);
x=(f?-x:x);
}
const int N=5e5+10;
int Test, n, m;
int a[N];
int lst[N*2], pre[N];
int rt[N], tidx;
int tr[N*40], ls[N*40], rs[N*40];
inline void add(int &p, int l, int r, int x){
if(!p) p=++tidx, tr[p]=ls[p]=rs[p]=0;
++tr[p];
if(l==r) return ;
int mid=(l+r)>>1;
if(x<=mid) add(ls[p], l, mid, x);
else add(rs[p], mid+1, r, x);
}
inline void add(int x, int y){
++x;
for(; x<=n+1; x+=(x&-x)) add(rt[x], 1, n+1, y);
}
inline int get(int p, int l, int r, int L, int R){
if(L>R) return 0;
if(!p) return 0;
if(L<=l&&r<=R) return tr[p];
int mid=(l+r)>>1, ret=0;
if(L<=mid) ret+=get(ls[p], l, mid, L, R);
if(R>mid) ret+=get(rs[p], mid+1, r, L, R);
return ret;
}
inline int get(int l1, int r1, int l, int r){
if(l1>r1) return 0;
if(l>r) return 0;
int ret=0;
++r1;
for(; l1; l1-=(l1&-l1)) ret-=get(rt[l1], 1, n+1, l, r);
for(; r1; r1-=(r1&-r1)) ret+=get(rt[r1], 1, n+1, l, r);
return ret;
}
vector<int> vec[N*2];
int main(){
// freopen("D:\\nya\\acm\\A\\test.in","r",stdin);
// freopen("D:\\nya\\acm\\A\\test.out","w",stdout);
read(Test);
while(Test--){
read(n); read(m);
unordered_map<int, int> h;
int idx=n+2;
a[0]=0;
for(int i=1; i<=n; ++i) {
read(a[i]); a[0]=max(a[0], a[i]);
if(a[i]>=n+2){
if(h.find(a[i])==h.end()) h[a[i]]=idx, idx++;
a[i]=h[a[i]];
}
}
if(a[0]==1){
printf("-1\n");
continue ;
}
for(int i=1; i<=n+1; ++i) rt[i]=0;
tidx=0;
for(int i=1; i<=idx; ++i) lst[i]=0, vec[i].clear(), vec[i].ep(0);
for(int i=1; i<=n; ++i){
pre[i]=lst[a[i]]; lst[a[i]]=i;
add(pre[i], i);
vec[a[i]].ep(i);
}
int cnt=0;
for(int i=1; i<=idx; ++i) add(lst[i], n+1), cnt+=lst[i]!=0;
int ans=0;
for(int i=1; i<=n+1; ++i){
vec[i].ep(n+1);
if(vec[i].size()==2){
ans=max(ans, cnt-i);
continue;
}
for(int j=1, cur; j<(int)vec[i].size()-1; ++j){
cur=get(0, vec[i][j]-1, vec[i][j]+1, vec[i][j+1]-1)+get(vec[i][j-1]+1, vec[i][j]-1, vec[i][j+1], n+1)-i;
ans=max(ans, cur);
}
}
printf("%d\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 38916kb
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: 79ms
memory: 34288kb
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 6 2 4 3 7 5 4 4 5 3 3 6 6 7 5 7 6 5 5 6 2 6 8 7 3 5 5 6 2 4 3 4 5 4 3 7 3 4 6 6 2 5 5 3 3 3 8 6 6 5 7 4 4 6 4 6 6 6 6 7 3 6 3 3 7 7 6 6 7 4 3 5 5 4 6 3 4 6 6 5 5 5 9 4 5 7 5 4 5 2 2 5 6 6 8 5 3 4 5 5 5 7 7 4 2 6 6 3 5 4 5 5 6 6 6 6 7 7 5 5 7 4 7 4 7 6 6 6 5 4 3 5 4 2 3 6 5 3 6 5 5 5 4 5 6 6 6 ...
result:
wrong answer 4th numbers differ - expected: '4', found: '6'