QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153618 | #6521. Swapping Operation | 275307894a | WA | 35ms | 5884kb | C++14 | 1.7kb | 2023-08-30 14:12:13 | 2023-08-30 14:12:13 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e5+5,M=N*40+5,K=600+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,A[N],suf[N],pre[N],ans,st[N][20];
int qry(int x,int y){if(x>y) return (1<<30)-1;int d=__lg(y-x+1);return st[x][d]&st[y-(1<<d)+1][d];}
void calc(int x,int k,int y){ans=max(ans,(qry(1,x-1)&A[y]&qry(x+1,k))+(qry(k+1,y-1)&A[x]&qry(y+1,n)));}
void Solve(){
int i,j,h;scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d",&A[i]);
ans=0;
pre[0]=(1<<30)-1;for(i=1;i<=n;i++) pre[i]=pre[i-1]&A[i];
suf[n+1]=(1<<30)-1;for(i=n;i;i--) suf[i]=suf[i+1]&A[i];
for(i=1;i<n;i++) ans=max(ans,pre[i]+suf[i+1]);
for(i=n;i;i--){
for(st[i][0]=A[i],j=1;i+(1<<j)-1<=n;j++) st[i][j]=st[i][j-1]&st[i+(1<<j-1)][j-1];
}
vector<int> a,b;
for(i=1;i<=n;i++) if(pre[i]^pre[i-1]) a.emplace_back(i);
for(i=n;i;i--) if(suf[i]^suf[i+1]) b.emplace_back(i);
for(i=1;i<n;i++){
for(int j:a) if(j<=i) for(int h:b) if(h>i) calc(j,i,h);
}
for(int i:a) {
for(int j:b) if(i<=j+1&&j<n){
for(h=j+2;h<=n;h++) calc(i,j+1,h);
}
}
for(int i:b){
for(int j:a) if(j-1<i&&j>1){
for(h=1;h<j;h++) calc(h,j-1,i);
}
}
printf("%d\n",ans);
}
int main(){
int t;
scanf("%d",&t);
// t=1;
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5884kb
input:
3 6 6 5 4 3 5 6 6 1 2 1 1 2 2 5 1 1 2 2 2
output:
7 3 3
result:
ok 3 number(s): "7 3 3"
Test #2:
score: -100
Wrong Answer
time: 35ms
memory: 3964kb
input:
1000 100 803046221 177233942 164782937 53823867 383853667 250036100 888743479 576687945 737272231 801579441 647643785 393059353 401516062 663466861 308544510 825328494 162739603 501761995 570908380 655227403 444493122 844535039 208303132 493226172 421479971 634680694 396627047 787471115 335787136 16...
output:
890299519 923642535 960163633 963497255 906186590 923065154 979836345 771417883 973791353 897446548 920223968 969979000 494498965 917264022 981686922 827513928 988685740 989181315 729655322 863912714 968789214 934333526 924124296 964130484 971937793 918136308 977368039 980800625 551789116 973760189 ...
result:
wrong answer 1st numbers differ - expected: '999397418', found: '890299519'