QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#747043#9727. Barkley IIIGolem__#WA 0ms3612kbC++174.5kb2024-11-14 16:14:312024-11-14 16:14:31

Judging History

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

  • [2025-01-13 03:55:43]
  • hack成功,自动添加数据
  • (/hack/1447)
  • [2024-11-14 16:14:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-11-14 16:14:31]
  • 提交

answer

#include<bits/stdc++.h>
#define fcc(i, j, k) for(num (i)=(j); (i)<=(k); ++(i))
#define ccf(i, j, k) for(num (i)=(j); (i)>=(k); --(i))
using std::cin;
using std::cout;
using std::vector;
using num = int;
using Num = long long;
using unum = unsigned int;
using uNum = unsigned long long;
const char newl = '\n', *snewl = " \n";
inline Num read()
{
    Num ret = 0, s = 1, c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') s = -1;
    for(; isdigit(c); c = getchar()) ret = (ret << 1) + (ret << 3) + (c ^ 48);
    return s * ret;
}

template<typename info, typename tag>
class Segment_Tree
{
    public:
    num siz; vector<info> val; vector<tag> laz;
    Segment_Tree(num siz) : siz(siz), val(siz << 2 | 1), laz(siz << 2 | 1) { }
    num lc(num o) { return o << 1; }
    num rc(num o) { return o << 1 | 1; }
    void apply(num o, tag t) { val[o] = val[o] + t, laz[o] = laz[o] + t; }
    void pull(num o) { val[o] = val[lc(o)] + val[rc(o)]; }
    void push(num o) { apply(lc(o), laz[o]), apply(rc(o), laz[o]), laz[o] = tag(); }
    void modify(num o, num l, num r, num p, info v)
    {
        if(l == r) return val[o] = v, void();
        num m = l + r >> 1; push(o);
        if(p <= m) modify(lc(o), l, m, p, v);
        else modify(rc(o), m + 1, r, p, v);
        pull(o);
    }
    void modify(num o, num l, num r, num p, num q, tag t)
    {
        if(p <= l && r <= q) return apply(o, t);
        num m = l + r >> 1; push(o);
        if(p <= m) modify(lc(o), l, m, p, q, t);
        if(q > m) modify(rc(o), m + 1, r, p, q, t);
        pull(o);
    }
    info query(num o, num l, num r, num p, num q)
    {
        if(p <= l && r <= q) return val[o];
        num m = l + r >> 1; push(o);
        if(p <= m && q > m) return query(lc(o), l, m, p, q) + query(rc(o), m + 1, r, p, q);
        if(p <= m) return query(lc(o), l, m, p, q);
        else return query(rc(o), m + 1, r, p, q);
    }
    num query2(num o, num l, num r, num p, num q, uNum b)
    {
        if(l == r) return l;
        num m = l + r >> 1; push(o);
        if(p <= m && !(val[lc(o)].a & b)) return query2(lc(o), l, m, p, q, b);
        return query2(rc(o), m + 1, r, p, q, b);
    }
};
const uNum mas = (1ULL << 63) - 1;
class tag
{
    public:
    uNum a;
    tag(uNum a = mas) : a(a) { }
    tag operator + (tag t)
    {
        tag ret;
        ret.a = a & t.a;
        return ret;
    }
};
class info
{
    public:
    num l, r; uNum a, b;
    info(uNum a = mas, uNum b = mas, num l = 0, num r = 0) : a(a), b(b), l(l), r(r) { }
    info operator + (info v)
    {
        info ret;
        ret.l = l;
        ret.r = v.r;
        ret.a = a & v.a;
        ret.b = b & v.b & (a | v.a);
        return ret;
    }
    info operator + (tag t)
    {
        info ret;
        ret.l = l;
        ret.r = r;
        ret.a = a & t.a;
        ret.b = b;
        if(l < r) ret.b &= t.a;
        return ret;
    }
};
void solve()
{
    num N = read(), Q = read();
    vector<Num> A(N + 10);
    fcc(i, 1, N) A[i] = read();
    Segment_Tree<info, tag> tre(N + 10);
    fcc(i, 1, N) tre.modify(1, 1, N, i, info(A[i], mas, i, i));
    for(; Q --> 0;)
    {
        num opt = read(), l, r, s; Num x;
        if(opt == 1) l = read(), r = read(), x = read(),
            tre.modify(1, 1, N, l, r, tag(x));
        if(opt == 2) s = read(), x = read(),
            tre.modify(1, 1, N, s, info(x, mas, s, s));
        if(opt == 3)
        {
            l = read(), r = read();
            info seg = tre.query(1, 1, N, l, r);
            num pos = 0;
            ccf(i, 63, 1)
            {
                num b = 1ULL << i - 1;
                if(!(seg.a & b) && (seg.b & b))
                {
                    pos = i;
                    break;
                }
            }
            if(!pos) cout << seg.a << newl;
            else
            {
                pos = tre.query2(1, 1, N, l, r, 1ULL << pos - 1);
                if(pos == l) cout << tre.query(1, 1, N, pos + 1, r).a << newl;
                else if(pos == r) cout << tre.query(1, 1, N, l, pos - 1).a << newl;
                else cout << (tre.query(1, 1, N, l, pos - 1) +
                    tre.query(1, 1, N, pos + 1, r)).a << newl;
            }
        }
    }
}
num main()
{
    #ifndef ONLINE_JUDGE
    freopen("_.in", "r", stdin);
    freopen("_.out", "w", stdout);
    #endif
    std::ios::sync_with_stdio(0), cin.tie(0);

    for(num T = 1; T --> 0;) solve();
    return 0 ^ 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

5 9
7 7 7 6 7
3 1 5
2 1 3
3 1 5
3 1 3
1 1 2 3
3 1 3
2 2 8
3 1 3
3 1 2

output:

7
6
7
3
3
8

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

10 10
6760061359215711796 1568091718842717482 1568091718842717482 1568091718842717482 5232472783634052627 8795942500783873690 1568091718842717482 1568091718842717482 1568091718842717482 1568091718842717482
1 3 5 7587422031989082829
3 6 10
1 7 8 5197616143400216932
2 4 2518604563805514908
2 2 4533959...

output:

1568091718842717482
35184908959744
176025477579040
8795942500783873690

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3612kb

input:

100 100
4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 625967318191814868 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072...

output:

70368744185856
0
0
3612454262104133153
153122391625564161
4263579105072360993
70368744177664
77309673472
0
12952010752
562951027425280
1153488865559840256
3533641810948498945
67108864
576531718266945536
0
77309673472
1729382296723653632
0
1730020640668059136
3533641810948498945
0
0
17300206406680591...

result:

wrong answer 1st lines differ - expected: '576531121047601152', found: '70368744185856'