QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#155005#6521. Swapping OperationInsert_Username_HereTL 1ms5492kbC++201.1kb2023-09-01 05:52:132023-09-01 05:52:14

Judging History

你现在查看的是最新测评结果

  • [2023-09-01 05:52:14]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5492kb
  • [2023-09-01 05:52:13]
  • 提交

answer

#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
// Cope Counter = at least 127

ll arr[100001], kms[18][100001];

ll qry(ll l, ll r) {
  for(ll i = 17; i >= 0; i--) {
    if(r - l + 1 >= (1 << i)) return kms[i][l] & kms[i][r - (1 << i) + 1];
  }
  return (1 << 30) - 1;
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll t;
  cin >> t;
  while(t--) {
    ll n;
    cin >> n;
    for(ll i = 0; i < n; i++) {
      cin >> arr[i];
      kms[0][i] = arr[i];
    }
    for(ll i = 0; i < 17; i++) {
      for(ll j = 0; j + (1 << i) < n; j++) {
        kms[i + 1][j] = kms[i][j] & kms[i][j + (1 << i)];
      }
    }
    ll smax = 0;
    for(ll i = 1; i < n; i++) smax = max(smax, qry(0, i - 1) + qry(i, n - 1));
    for(ll k = 1; k < n; k++) {
      for(ll i = 0; i < k; i++) {
        for(ll j = k; j < n; j++) {
          smax = max(smax, (qry(0, i - 1) & arr[j] & qry(i + 1, k - 1)) + (qry(k, j - 1) & arr[i] & qry(j + 1, n - 1)));
        }
      }
    }
    cout << smax << "\n";
  }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5492kb

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
Time Limit Exceeded

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:


result: