QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140392#6521. Swapping OperationWilliamsWA 1ms3468kbC++143.4kb2023-08-15 20:55:472023-08-15 20:56:46

Judging History

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

  • [2023-08-15 20:56:46]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3468kb
  • [2023-08-15 20:55:47]
  • 提交

answer

#include <bits/stdc++.h>
#define for_(i,a,b) for (int i = (a); i < (b); i++)
#define rep_(i,a,b) for (int i = (a); i <= (b); i++)
#define per_(i,a,b) for (int i = (a); i >= (b); i--)
#define pii pair<int, int>
#define pll pair<ll, ll> 
#define fi first
#define se second
#define ll long long
#define sz(a) (int)a.size()
#define all(v) v.begin(), v.end()
#define clr(x) memset(x, 0, sizeof(x))
#define wls(v)   sort(all(v)); v.erase(unique(all(v)), v.end());
#define ull unsigned long long
#define pb push_back
#define D(x) cerr << #x << '=' << x << endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"]=";rep_(_x,(L),(R))cerr<<a[_x]<<" "; cerr<<endl; 
	#ifdef LOCAL
#define line cout << "--------------------------------" << endl;
#define CE cout << endl;
#define CO cout << "OK" << endl;
    #endif
#define endl '\n'
using namespace std;
bool be;clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const int maxn = 2e5 + 10, mod = 998244353;// mod = 1949777;
const double EPS = 1e-3;
template <typename Type>
void add(Type &x, Type y, Type Md) {
	x += y; while(x >= Md) x -= Md;
	while(x < 0) x += Md;
}
int n, m;
int t[maxn];
int st[maxn][24];
int Q(int x, int y) {
	if(x > y) return (1LL<<31)-1;
	int l = __lg(y - x + 1);
	return st[x][l]&st[y - (1<<l)+1][l];
}
int fuct(vector<int> &p) {
	int msk = (1LL<<31) - 1;
	vector<int> b, rb;
	rep_(i, 1, n) st[i][0] = p[i];
	int up = __lg(n);
	rep_(i, 1, up) {
		for (int j = 1; j + (1<<i) - 1 <= n; j++) {
			st[j][i] = st[j][i - 1] & st[j + (1<<i-1)][i-1];
		}
	} 
	
//	outarr(p, 1, n);
	t[0] = t[n + 1] = -1;
	rep_(i, 1, n) {
		msk &= p[i];
		t[i] = msk;
		if (t[i] != t[i - 1])  b.pb(i);
	}
	msk = (1LL<<31) - 1;
	per_(i, n, 1) {
		msk &= p[i];
		t[i] = msk;
		if (t[i] != t[i + 1]) rb.pb(i);
	}
	int ans = 0;
	rep_(i, 1, n - 1) ans = max(ans, Q(1, i) + Q(i + 1, n));
	
	rep_(i, 0, sz(b) - 1) {
		rep_(j, 0, sz(rb) - 1) {
			int x = b[i], y = rb[j];
			if (x >= y) break;
			ans = max(ans, (Q(1, x - 1) & p[y]) + (Q(x + 1, y - 1) & p[x] & Q(y + 1, n)));
			
			ans = max(ans, (Q(1, x - 1) & p[y] & Q(x + 1, y - 1)) + (p[x] & Q(y + 1, n)));
			rep_(k, x + 1, y - 1) {
				ans = max(ans, (Q(1, x - 1) & p[y] & Q(x + 1, k)) + (Q(k + 1, y - 1) & p[x] & Q(y + 1, n)));
			}
		}
	}
	
	
	
	rep_(i, 0, sz(b) - 1) {
		int x = b[i], k = Q(1, x - 1), lst = k;
		rep_(j, x + 1, n) {
			ans = max(ans, (Q(1, x - 1) & p[j]) + Q(x + 1, n));
			k &= p[j];
			ans = max(ans, k + (p[x] & Q(j + 1, n)));
			if (k != lst) {
				rep_(g, j + 1, n) ans = max(ans, (k & p[g]) + (p[x] & Q(j + 1, n)));
			}
			lst = k;
		}
	}
	return ans;
}
void solve() {
	cin >> n;
	vector<int> v(n + 1), rv(n + 1);
	rep_(i, 1, n) cin >> v[i], rv[n - i + 1] = v[i];
	cout << max(fuct(v), fuct(rv)) << endl;
}
signed main() {
	#ifdef LOCAL
		freopen("w.in", "r", stdin);
//		freopen("w.out", "w", stdout);
		startTime = clock();
//		time_t now_time = time(NULL); tm* TuT = localtime(&now_time); cout << asctime(TuT); cout << "CodeBegin:_______________________" << endl;
//		cout << "Memory footprint:" << ((&be - &ed) >> 20) <<"MB"<< endl;
//		line;
	#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
  int tt; cin >> tt; while(tt--) solve();
  	#ifdef LOCAL
  	cerr<<"\n\n-----------------------\nProgram done in "<<clock()-startTime<<" ms";
	#endif
 	return 0; 
}
//by whc
// check if over int , and open long long !!!
 
 

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3468kb

input:

3
6
6 5 4 3 5 6
6
1 2 1 1 2 2
5
1 1 2 2 2

output:

8
3
3

result:

wrong answer 1st numbers differ - expected: '7', found: '8'