QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#680002 | #7685. Barkley II | Displace_# | WA | 82ms | 41012kb | C++14 | 2.4kb | 2024-10-26 19:31:13 | 2024-10-26 19:31:16 |
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+2, 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+2, l, r);
for(; r1; r1-=(r1&-r1)) ret+=get(rt[r1], 1, n+2, 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);
}
for(int i=1; i<=idx; ++i) add(lst[i], n+2);
int ans=0;
for(int i=1; i<=n+1; ++i){
vec[i].ep(n+1);
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]+1, n+2)-i;
ans=max(ans, cur);
}
}
printf("%d\n", ans);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 39728kb
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: 82ms
memory: 41012kb
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:
5 2 2 6 2 4 3 5 5 4 4 5 3 3 0 4 3 4 7 6 3 3 2 2 4 6 7 3 3 1 6 1 4 3 2 5 4 3 5 3 4 6 4 2 5 5 2 3 2 8 4 3 5 4 3 2 6 4 2 3 4 6 3 3 2 3 0 7 7 6 3 3 4 3 5 5 0 6 3 4 4 4 5 2 2 5 4 5 5 5 4 2 1 2 1 4 4 6 5 3 4 3 2 5 5 7 4 0 5 6 3 5 4 5 5 4 6 6 6 7 5 5 5 4 4 5 4 4 4 0 4 3 1 3 5 1 2 1 6 5 3 2 5 5 5 4 0 6 6 3 ...
result:
wrong answer 1st numbers differ - expected: '6', found: '5'