Skip to content

Commit 2403980

Browse files
authored
Create Div2E.cpp
1 parent 46f844c commit 2403980

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#include <algorithm>
2+
#include <bitset>
3+
#include <cassert>
4+
#include <chrono>
5+
#include <cmath>
6+
#include <complex>
7+
#include <cstdio>
8+
#include <cstring>
9+
#include <ctime>
10+
#include <functional>
11+
#include <iomanip>
12+
#include <iostream>
13+
#include <iterator>
14+
#include <limits>
15+
#include <map>
16+
#include <numeric>
17+
#include <queue>
18+
#include <random>
19+
#include <set>
20+
#include <stack>
21+
#include <string>
22+
#include <tuple>
23+
#include <utility>
24+
#include <vector>
25+
26+
// #define int long long
27+
#define double long double
28+
#define ff first
29+
#define ss second
30+
#define endl '\n'
31+
#define ii pair<int, int>
32+
#define mp make_pair
33+
#define mt make_tuple
34+
#define DESYNC \
35+
ios_base::sync_with_stdio(false); \
36+
cin.tie(0); \
37+
cout.tie(0)
38+
#define pb push_back
39+
#define vi vector<int>
40+
#define vii vector<ii>
41+
#define all(x) x.begin(), x.end()
42+
#define EPS 1e-9
43+
#define INF 1e18
44+
#define ROOT 1
45+
#define curtime chrono::steady_clock::now().time_since_epoch().count
46+
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
47+
using ll = long long;
48+
using namespace std;
49+
const double PI = acos(-1);
50+
const int M = 1000000007;
51+
// const int M = 998244353;
52+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
53+
inline int mod(int n, int m = M) {
54+
int ret = n % m;
55+
if (ret < 0) ret += m;
56+
return ret;
57+
}
58+
59+
int exp(int n, int k, int m = M) {
60+
if (k == 0) return 1;
61+
if (k == 1) return n;
62+
int ax = exp(n, k / 2, m);
63+
ax = mod(ax * ax, m);
64+
if (k % 2) ax = mod(ax * n, m);
65+
return ax;
66+
}
67+
68+
int gcd(int a, int b) {
69+
if (a == 0)
70+
return b;
71+
else
72+
return gcd(b % a, a);
73+
}
74+
75+
/* LIBRARY INCLUDES */
76+
77+
/* END OF LIBRARY INCLUDES */
78+
79+
/* TEMPLATE DEFINES */
80+
// #define FILE_INPUT
81+
// #define PRINT_TEST_CASE
82+
// #define MULTIPLE_TEST_CASE
83+
84+
/* SOLUTION CODE */
85+
int pos[2][3123456];
86+
void solution(int testcase) {
87+
#ifdef PRINT_TEST_CASE
88+
cout << "Case #" << testcase << ": ";
89+
#endif
90+
// Code starts here
91+
int n;
92+
cin >> n;
93+
int v[n + 1];
94+
vi vx(n + 1, 0);
95+
for (int i = 1; i <= n; i++) cin >> v[i];
96+
97+
int ans = 0;
98+
for (int b = 22; b >= 0; b--) {
99+
// cout << "b = " << b << endl;
100+
for (int i = 0; i < 3123456; i++) {
101+
pos[0][i] = pos[1][i] = -1;
102+
}
103+
104+
// cout << "solving for " << b << endl;
105+
int px[n + 1];
106+
px[0] = 0;
107+
pos[0][0] = 0;
108+
int minl = 0;
109+
for (int r = 1; r <= n; r++) {
110+
px[r] = px[r - 1] ^ vx[r];
111+
if (((1 << b) & v[r]) == 0) {
112+
minl = r;
113+
pos[r % 2][px[r]] = r;
114+
continue;
115+
}
116+
// cout << "r = " << r << " " << px[r] << endl;
117+
if (pos[r % 2][px[r]] >= minl) {
118+
// cout << pos[r % 2][px[r]] << "-----" << r << endl;
119+
ans = max(ans, r - pos[r % 2][px[r]]);
120+
}
121+
if (pos[r % 2][px[r]] < minl) pos[r % 2][px[r]] = r;
122+
}
123+
for (int i = 1; i <= n; i++) {
124+
vx[i] |= ((1 << b) & v[i]);
125+
}
126+
}
127+
cout << ans << endl;
128+
}
129+
130+
#ifdef FILE_INPUT
131+
freopen("equal.in", "r", stdin);
132+
freopen("equal.out", "w", stdout);
133+
#endif
134+
135+
int32_t main() {
136+
// DESYNC;
137+
int t = 1;
138+
#ifdef MULTIPLE_TEST_CASE
139+
cin >> t;
140+
#endif
141+
for (int _testcase = 1; _testcase <= t; _testcase++) solution(_testcase);
142+
}

0 commit comments

Comments
 (0)