답안 #229853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229853 2020-05-06T21:09:01 Z 534351 Intergalactic ship (IZhO19_xorsum) C++17
92 / 100
2000 ms 3968 KB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int MAXN = 1013;
const int MAXV = 129;
const int MAXQ = 100013;
const int INF = 1000000007;
const int HALF = (INF + 1) >> 1;

int add(int a, int b)
{
    a += b; if (a >= INF) a -= INF; return a;
}
int mul(int a, int b)
{
    return (ll) a * b % INF;
}
int sub(int a, int b)
{
    a -= b; if (a < 0) a += INF; return a;
}
int pwr(int a, int b)
{
    int res = 1;
    while(b > 0)
    {
        if (b & 1) res = mul(res, a);
        b >>= 1;
        a = mul(a, a);
    }
    return res;
}
int inv(int a)
{
    return pwr(a, INF - 2);
}
int dvd(int a, int b)
{
    return mul(a, inv(b));
}

int N, Q, V;
int arr[MAXN];
pair<pii, int> query[MAXQ];
vi st[MAXN], en[MAXN];
int lt[MAXV], rt[MAXV];
bitset<MAXV> both;
int lval, rval;
int ans;

int calc(int x, int y)
{
    lval = 0; rval = 0;
    vi mb;
    FORD(i, (1 << V), 0)
    {
        if (lt[i]) lval |= i;
        if (rt[i]) rval |= i;
    }
    int res = 0, w = 0;
    FOR(i, 0, (1 << V))
    {
        if (!both[i]) continue;
        w++;
        int el = 0, er = 0;
        FOR(j, 0, V)
        {
            if (lval & (1 << j))
            {
                el = add(el, mul(HALF, (1 << j)));
            }
            else
            {
                bool b = ((x ^ i) & (1 << j));
                if (b) el = add(el, (1 << j));
            }
            if (rval & (1 << j))
            {
                er = add(er, mul(HALF, (1 << j)));
            }
            else
            {
                bool b = ((y ^ i) & (1 << j));
                if (b) er = add(er, (1 << j));
            }
        }
        res = add(res, mul(el, er));
    }
    res = dvd(res, w);
    return res;
}
int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N;
    FOR(i, 0, N)
    {
        cin >> arr[i];
        ckmax(V, arr[i]);
    }
    cin >> Q;
    FOR(i, 0, Q)
    {
        int l, r, x;
        cin >> l >> r >> x; l--; r--;
        query[i] = {{l, r}, x};
        ckmax(V, x);
        st[l].PB(i);
        en[r].PB(i);
    }
    V = (32 - __builtin_clz(V));
    // cerr << "V = " << V << endl;
    //the last bit probably has smth to do w the fact that you only care about 7 vectors because basis blah blah blah crap.
    FOR(i, 0, N)
    {
        fill(lt, lt + (1 << V), 0);
        fill(rt, rt + (1 << V), 0);
        both.reset();
        both[0] = true;
        //for i...N + 1 you have some shit happening left only.
        //it affects left only, both
        FOR(j, 0, Q)
        {
            if (query[j].fi.fi <= i && query[j].fi.se >= i)
            {
                lt[query[j].se]++;
            }
        }
        FORD(j, N, i)
        {
            for (int q : en[j])
            {
                if (query[q].fi.fi <= i)
                {
                    lt[query[q].se]--;
                    if (!both[query[q].se])
                    {
                        FOR(k, 0, (1 << V))
                        {
                            if (both[k]) both[k ^ query[q].se] = true;
                        }
                    }
                }
                else
                {
                    rt[query[q].se]++;
                }
            }
            int co = mul(i + 1, N - j);
            if (i != j) co = add(co, co);
            // cerr << "solve " << i << ' ' << j << " co = " << co << endl;
            ans = add(ans, mul(co, calc(arr[i], arr[j])));
            for (int q : st[j])
            {
                rt[query[q].se]--;
            }
        }
    }
    // cerr << "ans == " << ans << endl;
    FOR(i, 0, Q)
    {
        ans = add(ans, ans);
    }
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 9 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 203 ms 2688 KB Output is correct
2 Correct 20 ms 640 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 307 ms 484 KB Output is correct
2 Correct 304 ms 384 KB Output is correct
3 Correct 296 ms 376 KB Output is correct
4 Correct 282 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 8 ms 512 KB Output is correct
5 Correct 8 ms 512 KB Output is correct
6 Correct 8 ms 512 KB Output is correct
7 Correct 9 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 9 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 33 ms 384 KB Output is correct
13 Correct 33 ms 384 KB Output is correct
14 Correct 10 ms 384 KB Output is correct
15 Correct 23 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 9 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 8 ms 512 KB Output is correct
13 Correct 8 ms 512 KB Output is correct
14 Correct 8 ms 512 KB Output is correct
15 Correct 9 ms 512 KB Output is correct
16 Correct 33 ms 384 KB Output is correct
17 Correct 33 ms 384 KB Output is correct
18 Correct 10 ms 384 KB Output is correct
19 Correct 23 ms 384 KB Output is correct
20 Correct 1979 ms 2936 KB Output is correct
21 Correct 921 ms 3704 KB Output is correct
22 Correct 1801 ms 3960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 9 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
9 Correct 203 ms 2688 KB Output is correct
10 Correct 20 ms 640 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 307 ms 484 KB Output is correct
14 Correct 304 ms 384 KB Output is correct
15 Correct 296 ms 376 KB Output is correct
16 Correct 282 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 8 ms 512 KB Output is correct
21 Correct 8 ms 512 KB Output is correct
22 Correct 8 ms 512 KB Output is correct
23 Correct 9 ms 512 KB Output is correct
24 Correct 33 ms 384 KB Output is correct
25 Correct 33 ms 384 KB Output is correct
26 Correct 10 ms 384 KB Output is correct
27 Correct 23 ms 384 KB Output is correct
28 Correct 1979 ms 2936 KB Output is correct
29 Correct 921 ms 3704 KB Output is correct
30 Correct 1801 ms 3960 KB Output is correct
31 Execution timed out 2081 ms 3968 KB Time limit exceeded
32 Halted 0 ms 0 KB -