QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#472132 | #4925. Adjacent Pairs | return0114514 | Compile Error | / | / | C++14 | 2.2kb | 2024-07-11 14:40:03 | 2024-07-11 14:40:03 |
Judging History
answer
#include<bits/stdc++.h>#include<bits/stdc++.h>
using namespace std;
typedef long long i64;
#define endl "\n"
const int N=2e5+5;
int n;
int a[N];
int c1[N],c2[N];
int id[N];
bool cmp(int x,int y)
{
return c2[x]>c2[y];
}
void skr(void)
{
cin>>n;
for(int i=1;i<=n+1;i++)
{
c1[i]=c2[i]=0;
id[i]=i;
}
for(int i=1;i<=n;i++)
{
cin>>a[i];
i&1?c1[a[i]]++:c2[a[i]]++;
}
sort(id+1,id+n+1,cmp);
map<pair<int,int>,int> mp;
for(int l=1,r;l<n;l=r)
{
r=l+1;
int x=a[l],y=a[r];
if(l%2==0)
{
swap(x,y);
}
while(r<n)
{
if((r+1)%2==1&&a[r+1]!=x)
{
break;
}
if((r+1)%2==0&&a[r+1]!=y)
{
break;
}
r++;
}
mp[{x,y}]+=r-l+1>>1;
}
int ans=0;
for(int i=1;i<n;i++)
{
int x=a[i],y=a[i+1];
if(i%2==0)
{
swap(x,y);
}
ans=max(ans,c1[y]+c2[x]-mp[{x,y}]);
}
for(int i=1;i<=n+1;i++)
{
int t=1;
while(mp[{id[i],i}]||i==id[t])
{
t++;
}
ans=max(ans,c1[i]+c2[id[t]]);
}
cout<<n-ans<<'\n';
}
int main(void)
{
ios::sync_with_stdio(0);
int t=1;
cin>>t;
while(t--)
{
skr();
}
return 0;
}
using namespace std;
#define endl "\n"
typedef long long i64;
const int N=2e5+5;
int t=1;
int n;
int a[N];
int c1[N],c2[N];
int id[N];
bool cmp(int x,int y)
{
return c2[x]>c2[y];
}
void skr(void)
{
cin>>n;
for(int i=1;i<=n+1;i++)
{
c1[i]=c2[i]=0;
id[i]=i;
}
for(int i=1;i<=n;i++)
{
cin>>a[i];
i&1?c1[a[i]]++:c2[a[i]]++;
}
sort(id+1,id+n+1,cmp);
map<pair<int,int>,int> mp;
for(int l=1,r;l<n;l=r)
{
r=l+1;
int x=a[l],y=a[r];
if(l%2==0)
{
swap(x,y);
}
while(r<n)
{
if((r+1)%2==1&&a[r+1]!=x)
{
break;
}
if((r+1)%2==0&&a[r+1]!=y)
{
break;
}
r++;
}
mp[{x,y}]+=r-l+1>>1;
}
int ans=0;
for(int i=1;i<n;i++)
{
int x=a[i],y=a[i+1];
if(i%2==0)
{
swap(x,y);
}
ans=max(ans,c1[y]+c2[x]-mp[{x,y}]);
}
for(int i=1;i<=n+1;i++)
{
int t=1;
while(mp[{id[i],i}]||i==id[t])
{
t++;
}
ans=max(ans,c1[i]+c2[id[t]]);
}
cout<<n-ans<<'\n';
}
int main(void)
{
ios::sync_with_stdio(0);
scanf("%d",&t);
while(t--)
{
skr();
}
return 0;
}
詳細信息
answer.code:1:24: warning: extra tokens at end of #include directive 1 | #include<bits/stdc++.h>#include<bits/stdc++.h> | ^ answer.code:87:11: error: redefinition of ‘const int N’ 87 | const int N=2e5+5; | ^ answer.code:5:11: note: ‘const int N’ previously defined here 5 | const int N=2e5+5; | ^ answer.code:89:5: error: redefinition of ‘int n’ 89 | int n; | ^ answer.code:7:5: note: ‘int n’ previously declared here 7 | int n; | ^ answer.code:90:5: error: redefinition of ‘int a [200005]’ 90 | int a[N]; | ^ answer.code:8:5: note: ‘int a [200005]’ previously declared here 8 | int a[N]; | ^ answer.code:91:5: error: redefinition of ‘int c1 [200005]’ 91 | int c1[N],c2[N]; | ^~ answer.code:9:5: note: ‘int c1 [200005]’ previously declared here 9 | int c1[N],c2[N]; | ^~ answer.code:91:11: error: redefinition of ‘int c2 [200005]’ 91 | int c1[N],c2[N]; | ^~ answer.code:9:11: note: ‘int c2 [200005]’ previously declared here 9 | int c1[N],c2[N]; | ^~ answer.code:92:5: error: redefinition of ‘int id [200005]’ 92 | int id[N]; | ^~ answer.code:10:5: note: ‘int id [200005]’ previously declared here 10 | int id[N]; | ^~ answer.code:93:6: error: redefinition of ‘bool cmp(int, int)’ 93 | bool cmp(int x,int y) | ^~~ answer.code:11:6: note: ‘bool cmp(int, int)’ previously defined here 11 | bool cmp(int x,int y) | ^~~ answer.code:97:6: error: redefinition of ‘void skr()’ 97 | void skr(void) | ^~~ answer.code:15:6: note: ‘void skr()’ previously defined here 15 | void skr(void) | ^~~ answer.code:155:5: error: redefinition of ‘int main()’ 155 | int main(void) | ^~~~ answer.code:73:5: note: ‘int main()’ previously defined here 73 | int main(void) | ^~~~ answer.code: In function ‘int main()’: answer.code:158:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 158 | scanf("%d",&t); | ~~~~~^~~~~~~~~