#include "oriand.h"

long long oriand(int n, int k, std::vector<long long> a)
{
    long long mask = (1ll << k) - 1;

    auto getOr = [&](int l, int r) -> long long
    {
        long long val = 0;
        for (int i = l; i <= r; i++)
        {
            val |= a[i];
        }
        return val;
    };

    auto getAnd = [&](int l, int r) -> long long
    {
        long long val = mask;
        for (int i = l; i <= r; i++)
        {
            val &= a[i];
        }
        return val;
    };

    long long ans = 0;
    for (int l = 0; l < n; l++)
    {
        int ml = l - 1;
        int mr = n;
        while (mr - ml > 1)
        {
            int mm = (ml + mr) / 2;
            if (getOr(l, mm) == mask) mr = mm;
            else ml = mm;
        }

        int m = mr;
        if (m == n) continue;

        int rl = m;
        int rr = n;
        while (rr - rl > 1)
        {
            int rm = (rl + rr) / 2;
            if (getAnd(m + 1, rm) == 0) rr = rm;
            else rl = rm;
        }

        int r = rr;
        if (r == n) continue;

        ans += n - r;
    }

    return ans;
}
