提出 #72561318


ソースコード 拡げる

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn = 2e5 + 5;

class SegmentTree
{
public:
    long long a[200 * maxn], add[200 * maxn];
    bitset<200*maxn> f0;
    int cnt = 1, ls[200 * maxn], rs[200 * maxn], root[200 * maxn]; //ls左儿子,ls右儿子,root为根

    inline void push_up(int rt) //向上更新
    {
        a[rt] = max(a[ls[rt]], a[rs[rt]]);
    }
    void build(int l,int r,int &rt)
    {
        if (!rt)
        {
            rt=cnt;
            cnt++;
        }
        if (l==r)
            return;
        int mid=l+r>>1;
        build(l,mid,ls[rt]);
        build(mid+1,r,rs[rt]);
    }
    inline void push_down(int rt, int l, int r) //向下更新
    {
        if (f0[rt])
        {
            if (ls[rt])
            {
                a[ls[rt]] = 0;
                add[ls[rt]]= 0;
                f0[ls[rt]]=1;
            }
            if (rs[rt])
            {
                a[rs[rt]] = 0;
                add[rs[rt]] =0;
                f0[rs[rt]]=1;
            }
            f0[rt]=0;
        }
        if (add[rt] != 0)
        {
            if (ls[rt])
            {
                add[ls[rt]] += add[rt];
                a[ls[rt]] += add[rt];
            }
            if (rs[rt])
            {
                add[rs[rt]] += add[rt];
                a[rs[rt]] += add[rt];
            }

            add[rt] = 0;
        }
    }

    void updata1(int x, int y, long long k, int l, int r, int &rt) //线段树区间为从l到r,把区间x到y每个数+k
    {
        if (!rt)
            return;
        if (x <= l && y >= r)
        {
            a[rt] += k;
            add[rt] += k;
            return;
        }
        push_down(rt, l, r);
        int mid = (l + r) / 2;
        if (x <= mid)
            updata1(x, y, k, l, mid, ls[rt]);
        if (y > mid)
            updata1(x, y, k, mid + 1, r, rs[rt]);
        push_up(rt);
    }

    void updata2(int x, int y, int l, int r, int &rt) //线段树区间为从l到r,把区间x到y每个数+k
    {
        if (!rt)
            return;
        if (x <= l && y >= r)
        {
            a[rt] =0;
            add[rt] =0;
            f0[rt]=1;
            return;
        }
        push_down(rt, l, r);
        int mid = (l + r) / 2;
        if (x <= mid)
            updata2(x, y, l, mid, ls[rt]);
        if (y > mid)
            updata2(x, y, mid + 1, r, rs[rt]);
        push_up(rt);
    }

    long long query(int x, int y, int l, int r, int rt) //线段树区间为从l到r,询问区间x到y的和
    {
        if (!rt)
            return 0;
        if (x <= l && y >= r)
            return a[rt];
        push_down(rt, l, r);
        int mid = (l + r) / 2;
        long long ans = 0;
        if (x <= mid)
            ans = query(x, y, l, mid, ls[rt]);
        if (y > mid)
            ans = max(ans, query(x, y, mid + 1, r, rs[rt]));
        return ans;
    }


    void split(int &p, int &q, int x, int y, int l, int r) //将p中x到y的区间分裂给q
    {
        if (!p)
            return;
        if (x <= l && r <= y)
        {
            q = p;
            p = 0;
            return;
        }
        if (!q)
        {
            q = cnt;
            cnt++;
        }
        push_down(p,l,r);
        push_down(q,l,r);
        int mid = l + r >> 1;
        if (x <= mid)
            split(ls[p], ls[q], x, y, l, mid);
        if (y > mid)
            split(rs[p], rs[q], x, y, mid + 1, r);
        push_up(p);
        push_up(q);
    }
} st;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, q;
    cin >> n >> q;
    st.build(1,n,st.root[1]);

    while (q--)
    {
        int op, l, r;
        cin >> op >> l >> r;
        if (op == 1)
        {
            long long x;
            cin >> x;
            st.updata1(l,r,x,1,n,st.root[1]);
        }
        else if (op==2)
        {
            st.updata2(l,r,1,n,st.root[1]);
            st.split(st.root[1],st.root[3],l,r,1,n);
            st.split(st.root[2],st.root[1],l,r,1,n);
            st.split(st.root[3],st.root[2],l,r,1,n);
        }
        else
        {
            print("{}\n",st.query(l,r,1,n,st.root[1]));
        }

    }
}

提出情報

提出日時
問題 G - Takoyaki and Flip
ユーザ Alliy666
言語 C++23 (GCC 15.2.0)
得点 0
コード長 4458 Byte
結果 WA
実行時間 326 ms
メモリ 60900 KiB

コンパイルエラー

./Main.cpp: In member function 'void SegmentTree::build(int, int, int&)':
./Main.cpp:28:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |         int mid=l+r>>1;
      |                 ~^~
./Main.cpp: In member function 'void SegmentTree::push_down(int, int, int)':
./Main.cpp:32:39: warning: unused parameter 'l' [-Wunused-parameter]
   32 |     inline void push_down(int rt, int l, int r) //向下更新
      |                                   ~~~~^
./Main.cpp:32:46: warning: unused parameter 'r' [-Wunused-parameter]
   32 |     inline void push_down(int rt, int l, int r) //向下更新
      |                                          ~~~~^
./Main.cpp: In member function 'void SegmentTree::split(int&, int&, int, int, int, int)':
./Main.cpp:140:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  140 |         int mid = l + r >> 1;
      |                   ~~^~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 575
結果
AC × 3
AC × 22
WA × 43
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt, 01_random_56.txt, 01_random_57.txt, 01_random_58.txt, 01_random_59.txt, 01_random_60.txt, 01_random_61.txt, 01_random_62.txt, 01_random_63.txt, 01_random_64.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 5 ms 11368 KiB
00_sample_01.txt AC 5 ms 11368 KiB
00_sample_02.txt AC 5 ms 11364 KiB
01_random_03.txt WA 321 ms 60272 KiB
01_random_04.txt WA 314 ms 60532 KiB
01_random_05.txt AC 326 ms 60388 KiB
01_random_06.txt WA 313 ms 60540 KiB
01_random_07.txt WA 311 ms 60484 KiB
01_random_08.txt AC 320 ms 60516 KiB
01_random_09.txt WA 322 ms 60644 KiB
01_random_10.txt AC 320 ms 60404 KiB
01_random_11.txt WA 316 ms 60548 KiB
01_random_12.txt WA 325 ms 60212 KiB
01_random_13.txt WA 317 ms 60620 KiB
01_random_14.txt WA 312 ms 60388 KiB
01_random_15.txt WA 323 ms 60340 KiB
01_random_16.txt AC 69 ms 23628 KiB
01_random_17.txt WA 192 ms 38756 KiB
01_random_18.txt AC 124 ms 33104 KiB
01_random_19.txt WA 172 ms 37532 KiB
01_random_20.txt WA 179 ms 38504 KiB
01_random_21.txt WA 214 ms 41092 KiB
01_random_22.txt AC 19 ms 20532 KiB
01_random_23.txt WA 24 ms 16004 KiB
01_random_24.txt WA 304 ms 60596 KiB
01_random_25.txt WA 304 ms 60540 KiB
01_random_26.txt WA 305 ms 60548 KiB
01_random_27.txt WA 306 ms 60532 KiB
01_random_28.txt WA 301 ms 60572 KiB
01_random_29.txt WA 298 ms 60648 KiB
01_random_30.txt WA 300 ms 60316 KiB
01_random_31.txt WA 299 ms 60312 KiB
01_random_32.txt WA 84 ms 27724 KiB
01_random_33.txt WA 152 ms 39144 KiB
01_random_34.txt WA 165 ms 33788 KiB
01_random_35.txt WA 104 ms 28724 KiB
01_random_36.txt WA 162 ms 40708 KiB
01_random_37.txt WA 260 ms 47184 KiB
01_random_38.txt WA 260 ms 47204 KiB
01_random_39.txt WA 260 ms 47072 KiB
01_random_40.txt WA 260 ms 46900 KiB
01_random_41.txt WA 259 ms 46940 KiB
01_random_42.txt WA 258 ms 47004 KiB
01_random_43.txt WA 258 ms 47156 KiB
01_random_44.txt WA 269 ms 47080 KiB
01_random_45.txt WA 104 ms 28008 KiB
01_random_46.txt WA 82 ms 23884 KiB
01_random_47.txt WA 121 ms 29852 KiB
01_random_48.txt WA 179 ms 28272 KiB
01_random_49.txt WA 71 ms 21796 KiB
01_random_50.txt AC 29 ms 14500 KiB
01_random_51.txt AC 29 ms 14564 KiB
01_random_52.txt AC 29 ms 14544 KiB
01_random_53.txt AC 310 ms 60900 KiB
01_random_54.txt AC 302 ms 60852 KiB
01_random_55.txt WA 300 ms 60648 KiB
01_random_56.txt AC 307 ms 60572 KiB
01_random_57.txt WA 306 ms 60552 KiB
01_random_58.txt AC 140 ms 34288 KiB
01_random_59.txt AC 136 ms 36092 KiB
01_random_60.txt AC 115 ms 36080 KiB
01_random_61.txt AC 139 ms 20960 KiB
01_random_62.txt AC 140 ms 20848 KiB
01_random_63.txt AC 139 ms 20816 KiB
01_random_64.txt AC 24 ms 11316 KiB