Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #include <ext/rope>
- #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
- #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
- #define mod 998244353
- #define xx first
- #define yy second
- #define all(a) (a).begin(), (a).end()
- #define pb push_back
- #define ll long long
- #define pii pair<int,int>
- #define maxn 500005
- using namespace std;
- using namespace __gnu_pbds;
- typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
- mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
- int n,k;
- int niz[maxn];
- bool check(int x){
- int pref = 0;
- for(int l=0; l<=n; l++){
- if(l != 0){
- int staripref = pref;
- pref |= niz[l];
- if(pref == staripref)continue;
- }
- int ks = pref;
- int r = n;
- bool ima = 0;
- for(;r>=l+1; r--){
- ks |= niz[r];
- if( (ks - x) == (ks^x)){
- ima = 1;
- break;
- }
- }
- if(!ima)continue;
- ks = 0;
- int pomk = k;
- pomk--;
- for(int i=l+1; i<=r-1; i++){
- ks |= niz[i];
- if( (ks - x) == (ks^x)){
- pomk--;
- if(pomk == 0)return 1;
- ks = 0;
- }
- }
- }
- return 0;
- }
- int main()
- {
- ios_base::sync_with_stdio(false); cin.tie(0);
- cin >> n >> k;
- ff(i,1,n)cin >> niz[i];
- if(k == 1){
- int sta = 0;
- ff(i,1,n)sta |= niz[i];
- cout << sta << endl;
- return 0;
- }
- int pref = 0;
- fb(i,29,0){
- bool sta = check(pref | (1<<i));
- if(sta)pref |= (1<<i);
- }
- cout << pref << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement