QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#554780 | #8332. Two in One | hicgnliaw | WA | 0ms | 4424kb | C++14 | 2.0kb | 2024-09-09 15:44:14 | 2024-09-09 15:44:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
inline int read(){
int s = 0;char ch = getchar();
while(ch<'0'||ch>'9')ch = getchar();
while(ch>='0'&&ch<='9'){s = (s<<1)+(s<<3)+ch-'0';ch = getchar();}
return s;
}
int n,a[N],cnt[N],T,sum[N],r[N];
void solve1(){
int ans = 0,ansl,ansr;
int nk[105],ct;
for(int i = 1;i<=n;i++){
memset(cnt,0,sizeof(cnt));
memset(sum,0,sizeof(sum));
for(int j = i;j<=n;j++){
sum[cnt[a[j]]]--;
sum[++cnt[a[j]]]++;
ct = 0;
for(int k = 1;k<=n;k++){
if(sum[k])nk[++ct] = k;
}
for(int k = 1;k<=ct;k++){
if(ans<nk[k]){
ans = nk[k];
ansl = i,ansr = j;
}
for(int t = 1;t<k;t++){
if((nk[k]|nk[t])>ans){
ans = nk[k]|nk[t];
ansl = i,ansr = j;
}
}
}
}
}
// cout << ans << '\n';
memset(cnt,0,sizeof(cnt));
for(int i = ansl;i<=ansr;i++)cnt[a[i]]++;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=n;j++){
if((cnt[i]|cnt[j])==ans){
cout << ans << '\n' << ansl << ' ' << ansr << '\n'
<< i << ' ' << j << '\n';
return;
}
}
}
}
void solve2(){
int mx1 = 0,mx2 = 0;
memset(cnt,0,sizeof(cnt));
for(int i = 1;i<=n;i++){
r[a[i]] = i;
cnt[a[i]]++;
}
for(int i = 1;i<=n;i++){
if(cnt[i]>=cnt[mx1]){
mx2 = mx1;
mx1 = i;
}else if(cnt[i]>cnt[mx2])mx2 = i;
}
int c;
if(!cnt[mx2]){
cout << cnt[mx1] << '\n';
cout << 1 << ' ' << n << '\n';
cout << mx1 << ' ' << mx1 << '\n';
return;
}
for(c = 1<<20;c;c>>=1){
if((cnt[mx1]&c)&&(cnt[mx2]&c))break;
}
for(int i = n;i>=1;i--){
if(!(cnt[mx1]&c)||!(cnt[mx2]&c)){
cout << (cnt[mx1]|cnt[mx2]) << '\n';
cout << 1 << ' ' << i << '\n';
cout << mx1 << ' ' << mx2 << '\n';
return;
}
cnt[a[i]]--;
}
return;
}
int main(){
// freopen("ttheal.in","r",stdin);
// freopen("ttheal.out","w",stdout);
T = read();
while(T--){
n = read();
for(int i = 1;i<=n;i++)a[i] = read();
if(n<=100)solve1();
else solve2();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4424kb
input:
1 7 1 2 3 4 3 2 1
output:
3 1 5 1 3
result:
wrong answer Output contains longer sequence [length = 5], but answer contains 1 elements