提出 #70623046


ソースコード 拡げる

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
const int maxn = 3e5+5;
const int maxv=62;
pair<int,int> add(pair<int,int> a,pair<int,int> b)
{
    if (a.first>b.first)
        return a;
    if (a.first<b.first)
        return b;
    return {a.first,a.second+b.second};
}
class SegmentTree
{
public:
    bitset<maxv> a[maxn*4],mx[maxn*4],mn[maxn*4],cha[maxn*4],chflag[maxn*4];
    pair<int,int> ans[maxn*4];
    void upd(int rt,int loc,int k)
    {
        if (mx[rt][loc]!=k)
        {
            mx[rt][loc]=mn[rt][loc]=cha[rt][loc]=k;
            chflag[rt][loc]=1;
            if (k)
                ans[rt].first++;
            else
                ans[rt].first--;
        }
    }
    void build(int l, int r, int rt) //从l到r建立线段树
    {
        if (l == r)
        {
            ans[rt].second=1;
            return;
        }
        int mid = (l + r) >> 1;
        build(l, mid, rt * 2);
        build(mid + 1, r, rt * 2 + 1);
        push_up(rt);
    }
    void push_up(int rt) //向上更新
    {
        ans[rt]=add(ans[rt*2],ans[rt*2+1]);
        mx[rt]=mx[rt*2]|mx[rt*2+1];
        mn[rt]=mn[rt*2]&mn[rt*2+1];
    }
    void push_down(int rt, int l, int r) //向下更新
    {
        if (chflag[rt].any())
        {
            int mid = l + r >> 1;
            for (int i=0;i<maxv;i=chflag[rt]._Find_next(i))
            {
                upd(rt*2,i,cha[rt][i]);
                upd(rt*2+1,i,cha[rt][i]);
            }
            chflag[rt]=0;
        }
    }

    void updata1(int x, int y, int loc,int k,int l, int r, int rt) //线段树区间为从l到r,把区间x到y每个数+k
    {
        int mid = (l + r) >> 1;
        if (x <= l && y >= r)
        {
            if (mx[rt][loc]==mn[rt][loc])
            {
                upd(rt,loc,k);
                return;
            }
        }
        push_down(rt, l, r);
        if (x <= mid)
            updata1(x, y,  loc,k,l, mid, rt * 2);
        if (y > mid)
            updata1(x, y, loc,k, mid + 1, r, rt * 2 + 1);
        push_up(rt);
    }

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n,q;
    cin>>n>>q;
    st.build(1,n,1);
    while (q--)
    {
        int op,l,r;
        cin>>op>>l>>r;
        if (op==1)
        {
            int x;
            cin>>x;
            st.updata1(l,r,x,1,1,n,1);
        }
        else if (op==2)
        {
            int x;
            cin>>x;
            st.updata1(l,r,x,0,1,n,1);
        }
        else
        {
            auto ans=st.query(l,r,1,n,1);
            print("{} {}\n",ans.first,ans.second);
        }
    }
}

提出情報

提出日時
問題 G - Range Set Modifying Query
ユーザ Alliy666
言語 C++23 (GCC 15.2.0)
得点 625
コード長 3281 Byte
結果 AC
実行時間 2058 ms
メモリ 47528 KiB

コンパイルエラー

./Main.cpp: In member function 'void SegmentTree::push_down(int, int, int)':
./Main.cpp:55:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |             int mid = l + r >> 1;
      |                       ~~^~~
./Main.cpp:55:17: warning: unused variable 'mid' [-Wunused-variable]
   55 |             int mid = l + r >> 1;
      |                 ^~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 625 / 625
結果
AC × 1
AC × 32
セット名 テストケース
Sample sample_01.txt
All min_1.txt, min_2.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, sample_01.txt
ケース名 結果 実行時間 メモリ
min_1.txt AC 9 ms 6476 KiB
min_2.txt AC 2 ms 6540 KiB
random_01.txt AC 2 ms 6464 KiB
random_02.txt AC 2 ms 6488 KiB
random_03.txt AC 2 ms 6568 KiB
random_04.txt AC 2 ms 6940 KiB
random_05.txt AC 3 ms 6752 KiB
random_06.txt AC 3 ms 6692 KiB
random_07.txt AC 3 ms 6628 KiB
random_08.txt AC 246 ms 23000 KiB
random_09.txt AC 219 ms 7692 KiB
random_10.txt AC 29 ms 22928 KiB
random_11.txt AC 144 ms 14888 KiB
random_12.txt AC 2058 ms 47476 KiB
random_13.txt AC 1945 ms 26968 KiB
random_14.txt AC 1378 ms 47372 KiB
random_15.txt AC 977 ms 26948 KiB
random_16.txt AC 244 ms 22988 KiB
random_17.txt AC 220 ms 7492 KiB
random_18.txt AC 239 ms 22924 KiB
random_19.txt AC 71 ms 10620 KiB
random_20.txt AC 2048 ms 47300 KiB
random_21.txt AC 1790 ms 26796 KiB
random_22.txt AC 1972 ms 47424 KiB
random_23.txt AC 1166 ms 47280 KiB
random_24.txt AC 145 ms 45312 KiB
random_25.txt AC 128 ms 46932 KiB
random_26.txt AC 144 ms 45704 KiB
random_27.txt AC 127 ms 46848 KiB
random_28.txt AC 201 ms 47528 KiB
random_29.txt AC 128 ms 46764 KiB
sample_01.txt AC 2 ms 6476 KiB