Submission #72580808


Source Code Expand

#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;
typedef pair<int, ll> pii;

#define mid ((t[p].l + t[p].r) >> 1)
#define l(p) (p << 1)
#define r(p) (l(p) | 1)

const int N = 2e5 + 9;
int n, q;

struct tree{
    int l, r, len;
    int cnt;
    ll mx;
    pii tag;
}t[N << 2];

void build(int p, int l, int r){
    t[p].l = l, t[p].r = r;
    t[p].cnt = t[p].len = r - l + 1;
    if(l == r) return;
    build(l(p), l, mid);
    build(r(p), mid + 1, r);
}

void adds(int p, pii x){
    if(x.first){
        t[p].tag.first += x.first;
        t[p].tag.second = x.second;

        if(x.first % 2){
            t[p].cnt = t[p].len - t[p].cnt;
        }
        t[p].mx = x.second * (t[p].cnt > 0);
    }
    else{
        t[p].tag.second += x.second;
        t[p].mx += x.second * (t[p].cnt > 0);
    }
}

void pushdown(int p){
    adds(l(p), t[p].tag);
    adds(r(p), t[p].tag);
    t[p].tag = make_pair(0, 0);
}

void pushup(int p){
    t[p].cnt = t[l(p)].cnt + t[r(p)].cnt;
    t[p].mx = max(t[l(p)].mx, t[r(p)].mx);
}

void modify(int p, int l, int r, pii x){
    if(l <= t[p].l && r >= t[p].r){
        adds(p, x);
        return;
    }

    pushdown(p);
    if(l <= mid) modify(l(p), l, r, x);
    if(r > mid) modify(r(p), l, r, x);
    pushup(p);
}

ll query(int p, int l, int r){
    if(l <= t[p].l && r >= t[p].r){
        return t[p].mx;
    }

    pushdown(p);
    ll ret = 0;
    if(l <= mid) ret = max(ret, query(l(p), l, r));
    if(r > mid) ret = max(ret, query(r(p), l, r));
    pushup(p);
    return ret;
}

int main(){
    /* freopen("a.in", "r", stdin);
    freopen("a.out", "w", stdout); */

    scanf("%d %d", &n, &q);
    build(1, 1, n);

    int op, l, r, x;
    for(int i = 1; i <= q; ++ i ){
        scanf("%d %d %d", &op, &l, &r);
        if(op == 1){
            scanf("%d", &x);
            modify(1, l, r, make_pair(0, x));
        }
        else if(op == 2){
            modify(1, l, r, make_pair(1, 0));
        }
        else{
            printf("%lld\n", query(1, l, r));
        }
    }
    return 0;
}

Submission Info

Submission Time
Task G - Takoyaki and Flip
User wandery
Language C++23 (GCC 15.2.0)
Score 575
Code Size 2170 Byte
Status AC
Exec Time 200 ms
Memory 35168 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 575 / 575
Status
AC × 3
AC × 65
Set Name Test Cases
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 12 ms 35072 KiB
00_sample_01.txt AC 12 ms 34996 KiB
00_sample_02.txt AC 12 ms 35100 KiB
01_random_03.txt AC 193 ms 35032 KiB
01_random_04.txt AC 194 ms 35052 KiB
01_random_05.txt AC 195 ms 35032 KiB
01_random_06.txt AC 197 ms 34972 KiB
01_random_07.txt AC 195 ms 34888 KiB
01_random_08.txt AC 195 ms 35032 KiB
01_random_09.txt AC 197 ms 35052 KiB
01_random_10.txt AC 195 ms 34940 KiB
01_random_11.txt AC 200 ms 35100 KiB
01_random_12.txt AC 197 ms 35064 KiB
01_random_13.txt AC 199 ms 35004 KiB
01_random_14.txt AC 197 ms 35072 KiB
01_random_15.txt AC 199 ms 34956 KiB
01_random_16.txt AC 53 ms 35004 KiB
01_random_17.txt AC 129 ms 34932 KiB
01_random_18.txt AC 88 ms 35168 KiB
01_random_19.txt AC 116 ms 35064 KiB
01_random_20.txt AC 118 ms 35032 KiB
01_random_21.txt AC 142 ms 35032 KiB
01_random_22.txt AC 20 ms 35044 KiB
01_random_23.txt AC 25 ms 34908 KiB
01_random_24.txt AC 185 ms 35072 KiB
01_random_25.txt AC 187 ms 35072 KiB
01_random_26.txt AC 186 ms 35040 KiB
01_random_27.txt AC 186 ms 35168 KiB
01_random_28.txt AC 186 ms 35032 KiB
01_random_29.txt AC 187 ms 35024 KiB
01_random_30.txt AC 185 ms 35044 KiB
01_random_31.txt AC 185 ms 35032 KiB
01_random_32.txt AC 63 ms 35040 KiB
01_random_33.txt AC 104 ms 35072 KiB
01_random_34.txt AC 115 ms 34940 KiB
01_random_35.txt AC 77 ms 34908 KiB
01_random_36.txt AC 109 ms 34956 KiB
01_random_37.txt AC 172 ms 35024 KiB
01_random_38.txt AC 169 ms 35028 KiB
01_random_39.txt AC 169 ms 35168 KiB
01_random_40.txt AC 170 ms 35072 KiB
01_random_41.txt AC 169 ms 34972 KiB
01_random_42.txt AC 170 ms 35072 KiB
01_random_43.txt AC 169 ms 35072 KiB
01_random_44.txt AC 170 ms 35072 KiB
01_random_45.txt AC 76 ms 35072 KiB
01_random_46.txt AC 63 ms 34972 KiB
01_random_47.txt AC 85 ms 35072 KiB
01_random_48.txt AC 132 ms 35168 KiB
01_random_49.txt AC 55 ms 35032 KiB
01_random_50.txt AC 44 ms 35072 KiB
01_random_51.txt AC 43 ms 34996 KiB
01_random_52.txt AC 44 ms 34940 KiB
01_random_53.txt AC 190 ms 35072 KiB
01_random_54.txt AC 188 ms 35100 KiB
01_random_55.txt AC 188 ms 35024 KiB
01_random_56.txt AC 190 ms 34956 KiB
01_random_57.txt AC 196 ms 35032 KiB
01_random_58.txt AC 96 ms 35064 KiB
01_random_59.txt AC 93 ms 35044 KiB
01_random_60.txt AC 81 ms 35064 KiB
01_random_61.txt AC 182 ms 35072 KiB
01_random_62.txt AC 179 ms 35072 KiB
01_random_63.txt AC 183 ms 35072 KiB
01_random_64.txt AC 40 ms 35168 KiB