Submission #71854688


Source Code Expand

#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 A
{
public:
    long long mxx=-1e18,mnx=1e18,mxy=-1e18,mny=1e18;
    A operator+(A that)
    {
        A ans;
        ans.mxx = max(mxx, that.mxx);
        ans.mxy = max(mxy, that.mxy);
        ans.mnx = min(mnx, that.mnx);
        ans.mny = min(mny, that.mny);
        return ans;
    }
};
class SegmentTree
{
public:
    long long   mxx[4 * maxn],mnx[4*maxn],mxy[4*maxn],mny[4*maxn];
    void push_up(int rt) //向上更新
    {
        mxx[rt] = max(mxx[rt * 2], mxx[rt * 2 + 1]);
        mxy[rt] = max(mxy[rt * 2], mxy[rt * 2 + 1]);
        mnx[rt] = min(mnx[rt * 2], mnx[rt * 2 + 1]);
        mny[rt] = min(mny[rt * 2], mny[rt * 2 + 1]);
    }

    void build(int l, int r, int rt) //从l到r建立线段树
    {
        if (l == r)
        {
            long long x,y;
            cin>>x>>y;
            mxx[rt]=mnx[rt]=x+y;
            mxy[rt]=mny[rt]=x-y;
            return;
        }
        int mid = (l + r) >> 1;
        build(l, mid, rt * 2);
        build(mid + 1, r, rt * 2 + 1);
        push_up(rt);
    }

    void updata1(int x, pair<long long,long long> k, int l, int r, int rt) //线段树区间为从l到r,把区间x到y每个数+k
    {
        if (l==r)
        {
            mxx[rt]=mnx[rt]=k.first+k.second;
            mxy[rt]=mny[rt]=k.first-k.second;
            return;
        }
        int mid = (l + r) >> 1;
        if (x <= mid)
            updata1(x,  k, l, mid, rt * 2);
        else
            updata1(x,  k, mid + 1, r, rt * 2 + 1);
        push_up(rt);
    }

    A query(int x, int y, int l, int r, int rt) //线段树区间为从l到r,询问区间x到y的和
    {
        if (x <= l && y >= r)
            return {mxx[rt],mnx[rt],mxy[rt],mny[rt]};
        int mid = (l + r) >> 1;
        A ans;
        if (x <= mid)
            ans = query(x, y, l, mid, rt * 2);
        if (y > mid)
            ans=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;
        cin>>op;
        if (op==1)
        {
            int loc;
            pair<long long,long long> k;
            cin>>loc>>k.first>>k.second;
            st.updata1(loc,k,1,n,1);
        }
        else
        {
            long long l,r,x,y;
            cin>>l>>r>>x>>y;
            auto now=st.query(l,r,1,n,1);
            long long ans=0;
            long long xx=x+y,yy=x-y;
            x=xx;
            y=yy;
            if (now.mxx>x)
                ans=max(ans,now.mxx-x);
            if (now.mnx<x)
                ans=max(ans,x-now.mnx);
            if (now.mxy>y)
                ans=max(ans,now.mxy-y);
            if (now.mny<y)
                ans=max(ans,y-now.mny);
            cout<<ans<<'\n';
        }
    }
}

Submission Info

Submission Time
Task F - Manhattan Christmas Tree 2
User Alliy666
Language C++23 (GCC 15.2.0)
Score 500
Code Size 3118 Byte
Status AC
Exec Time 130 ms
Memory 20128 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 24
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_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
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3528 KiB
00_sample_01.txt AC 1 ms 3648 KiB
01_random_00.txt AC 118 ms 20044 KiB
01_random_01.txt AC 123 ms 20036 KiB
01_random_02.txt AC 128 ms 20060 KiB
01_random_03.txt AC 127 ms 20128 KiB
01_random_04.txt AC 127 ms 20032 KiB
01_random_05.txt AC 126 ms 20060 KiB
01_random_06.txt AC 130 ms 20032 KiB
01_random_07.txt AC 129 ms 20108 KiB
01_random_08.txt AC 130 ms 20044 KiB
01_random_09.txt AC 128 ms 20068 KiB
01_random_10.txt AC 92 ms 20128 KiB
01_random_11.txt AC 93 ms 20060 KiB
01_random_12.txt AC 92 ms 20072 KiB
01_random_13.txt AC 92 ms 19956 KiB
01_random_14.txt AC 93 ms 20032 KiB
01_random_15.txt AC 36 ms 3656 KiB
01_random_16.txt AC 63 ms 20056 KiB
01_random_17.txt AC 100 ms 20060 KiB
01_random_18.txt AC 100 ms 19944 KiB
01_random_19.txt AC 100 ms 20124 KiB
01_random_20.txt AC 100 ms 19924 KiB
01_random_21.txt AC 98 ms 20004 KiB