QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226515#6227. 区间和SorahISA0 0ms0kbC++2011.5kb2023-10-26 01:44:462023-10-26 01:44:46

Judging History

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

  • [2023-10-26 01:44:46]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-10-26 01:44:46]
  • 提交

answer

#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA

const int INF = 1'000'000'001;

struct SegBeats {
    
    struct Node {
        int min1, min2, min_cnt, pmax, pmax_id, smax, smax_id, mss, sum, tag;
        Node() : min1(INF), min2(INF), min_cnt(0), pmax(0), pmax_id(-1), smax(0), smax_id(0), mss(0), sum(0), tag(-INF) {}
        Node(int val, int id) :
            min1(val), min2(val), min_cnt(1),
            pmax(val >= 0 ? val : 0), pmax_id(val >= 0 ? id : id-1),
            smax(val >= 0 ? val : 0), smax_id(val >= 0 ? id : id+1),
            mss(val >= 0 ? val : 0), sum(val), tag(-INF) {}
    };
    
    vector<Node> seg;
    int maxn;
    
    void init(int N, const vector<int> &vec) {
        maxn = (1 << (__lg(N+1) + 1));
        seg.assign(2*maxn, Node());
        for (int i = 0; i < maxn; ++i) seg[i+maxn] = Node((i < SZ(vec) ? vec[i] : 0), i);
        for (int i = maxn-1; i >= 1; --i) pull(seg[i], seg[i<<1], seg[i<<1|1]);
    }
    
    void push(Node &a, Node &l, Node &r) {
        if (a.tag > l.min1) {
            l.sum += (a.tag - l.min1) * l.min_cnt;
            l.min1 = l.tag = a.tag;
        }
        if (a.tag > r.min1) {
            r.sum += (a.tag - r.min1) * r.min_cnt;
            r.min1 = r.tag = a.tag;
        }
        a.tag = -INF;
    }
    
    void pull(Node &a, Node &l, Node &r) {
        a.min1 = min(l.min1, r.min1);
        a.min2 = (l.min1 == r.min1 ? min(l.min2, r.min2) : (l.min1 < r.min1 ? min(l.min2, r.min1) : min(l.min1, r.min2)));
        a.min_cnt = l.min_cnt * (l.min1 == a.min1) + r.min_cnt * (r.min1 == a.min1);
        a.pmax = max(l.pmax, l.sum + r.pmax);
        a.pmax_id = (l.pmax == a.pmax ? l.pmax_id : r.pmax_id);
        a.smax = max(r.smax, r.sum + l.smax);
        a.smax_id = (r.smax == a.smax ? r.smax_id : l.smax_id);
        a.mss = max({l.mss, r.mss, l.smax + r.pmax});
        a.sum = l.sum + r.sum;
        a.tag = -INF;
    }
    
    Node query_node(int qL, int qR) { return query_node(qL, qR, 1, 0, maxn-1); }
    Node query_node(int qL, int qR, int now, int nL, int nR) {
        if (qL <= nL and nR <= qR) return seg[now];
        
        push(seg[now], seg[now<<1], seg[now<<1|1]);
        
        int nM = (nL + nR) >> 1;
        
        Node tmp, l, r;
        if (qL <= nM) l = query_node(qL, qR, now<<1,   nL,   nM);
        if (nM <  qR) r = query_node(qL, qR, now<<1|1, nM+1, nR);
        pull(tmp, l, r);
        
        pull(seg[now], seg[now<<1], seg[now<<1|1]);
        
        return tmp;
    }
    
    void modify_range_chmax(int qL, int qR, int val) { return modify_range_chmax(qL, qR, val, 1, 0, maxn-1); }
    void modify_range_chmax(int qL, int qR, int val, int now, int nL, int nR) {
        if (qL <= nL and nR <= qR and val <= seg[now].min1) return;
        if (qL <= nL and nR <= qR and val < seg[now].min2) {
            seg[now].sum += (val - seg[now].min1) * seg[now].min_cnt;
            seg[now].min1 = seg[now].tag = val;
            
            while (seg[now].pmax_id < nR) {
                if (query_node(seg[now].pmax_id + 1, nR, now, nL, nR).pmax > 0) ++seg[now].pmax_id;
                else break;
            }
            if (seg[now].pmax_id == nR) seg[now].pmax = seg[now].sum;
            else seg[now].pmax = query_node(nL, seg[now].pmax_id, now, nL, nR).sum;
            
            while (seg[now].smax_id > nL) {
                if (query_node(nL, seg[now].smax_id - 1, now, nL, nR).smax > 0) --seg[now].smax_id;
                else break;
            }
            if (seg[now].smax_id == nL) seg[now].smax = seg[now].sum;
            else seg[now].smax = query_node(seg[now].smax_id, nR, now, nL, nR).sum;
            
            return;
        }
        
        push(seg[now], seg[now<<1], seg[now<<1|1]);
        
        int nM = (nL + nR) >> 1;
        if (qL <= nM) modify_range_chmax(qL, qR, val, now<<1,   nL,   nM);
        if (nM <  qR) modify_range_chmax(qL, qR, val, now<<1|1, nM+1, nR);
        
        pull(seg[now], seg[now<<1], seg[now<<1|1]);
    }
    
};

void solve() {
    int N, Q; cin >> N >> Q;
    
    vector<int> A(N);
    for (int &x : A) cin >> x;
    
    SegBeats seg; seg.init(N, A);
    
    for (int q = 1; q <= Q; ++q) {
        int op; cin >> op;
        if (op == 0) {
            int l, r, x; cin >> l >> r >> x, --l, --r;
            seg.modify_range_chmax(l, r, x);
        }
        if (op == 1) {
            int l, r; cin >> l >> r, --l, --r;
            cout << seg.query_node(l, r).mss << "\n";
        }
    }
}

int32_t main() {
    fastIO();
    
    int t = 1; // cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        // cout << "Case #" << _ << ": ";
        solve();
    }
    
    return 0;
}

#else

#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;

#define int int64_t
// #define double __float80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;

// #define X first
// #define Y second
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())

template <size_t D, typename T> struct Vec : vector<Vec<D-1, T>> {
    static_assert(D >= 1, "Vector dimension must be greater than zero!");
    template <typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D-1, T>>(n, Vec<D-1, T>(args...)) {}
};

template <typename T> struct Vec<1, T> : vector<T> {
    Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {}
};

template <class F>
inline constexpr decltype(auto) lambda_fix(F&& f) {
    return [f = std::forward<F>(f)](auto&&... args) {
        return f(f, std::forward<decltype(args)>(args)...);
    };
}

#ifdef local
#define fastIO() void()
#define debug(...) \
    _color.emplace_back("\u001b[31m"), \
    fprintf(stderr, "%sAt [%s], line %d: (%s) = ", _color.back().c_str(), __FUNCTION__, __LINE__, #__VA_ARGS__), \
    _do(__VA_ARGS__), _color.pop_back(), \
    fprintf(stderr, "%s", _color.back().c_str())
#define print(...) \
    fprintf(stdout, "%s", "\u001b[36m"), \
    _P(__VA_ARGS__), \
    fprintf(stdout, "%s", "\u001b[0m")

deque<string> _color{"\u001b[0m"};

template <typename T> concept is_string = is_same_v<T, string&> or is_same_v<T, const string&>;
template <typename T> concept is_iterable = requires (T _t) {begin(_t);};

template <typename T> inline void _print_err(T &&_t);
template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>);
template <size_t I, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &);
template <size_t I, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(const tuple<U...> &_t);
template <size_t I, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &);
template <size_t I, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(tuple<U...> &_t);
template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu);

inline void _do() {cerr << "\n";};
template <typename T> inline void _do(T &&_t) {_print_err(_t), cerr << "\n";}
template <typename T, typename ...U> inline void _do(T &&_t, U &&..._u) {_print_err(_t), cerr << ", ", _do(_u...);}
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#define print(...) _P(__VA_ARGS__)
#endif

inline void _P() {cout << "\n";};
template <typename T> inline void _P(T &&_t) {cout << _t << "\n";}
template <typename T, typename ...U> inline void _P(T &&_t, U &&..._u) {cout << _t << " ", _P(_u...);}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline int getRand(int L, int R) {
    if (L > R) swap(L, R);
    return (int)(rng() % ((uint64_t)R - L + 1) + L);
}

template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}

/// below are Fast I/O and _print_err templates ///

/*
/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///

#include <unistd.h>

const int S = 65536;

int OP = 0;
char OB[S];

inline char RC() {
    static char buf[S], *p = buf, *q = buf;
    return p == q and (q = (p = buf) + read(0, buf, S)) == buf ? -1 : *p++;
}

inline int RI() {
    static char c;
    int a;
    while (((c = RC()) < '0' or c > '9') and c != '-' and c != -1);
    if (c == '-') {
        a = 0;
        while ((c = RC()) >= '0' and c <= '9') a *= 10, a -= c ^ '0';
    }
    else {
        a = c ^ '0';
        while ((c = RC()) >= '0' and c <= '9') a *= 10, a += c ^ '0';
    }
    return a;
}

inline void WI(int n, char c = '\n') {
    static char buf[20], p;
    if (n == 0) OB[OP++] = '0';
    p = 0;
    if (n < 0) {
        OB[OP++] = '-';
        while (n) buf[p++] = '0' - (n % 10), n /= 10;
    }
    else {
        while (n) buf[p++] = '0' + (n % 10), n /= 10;
    }
    for (--p; p >= 0; --p) OB[OP++] = buf[p];
    OB[OP++] = c;
    if (OP > S-20) write(1, OB, OP), OP = 0;
}

/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///
*/

#ifdef local

template <typename T> inline void _print_err(T &&_t) {cerr << _t;}

template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>) {
    string _tmp_color = _color.back();
    ++_tmp_color[3], _color.emplace_back(_tmp_color);
    cerr << _color.back() << "[";
    for (bool _first = true; auto &_x : _t) {
        if (!_first) cerr << ", ";
        _print_err(_x), _first = false;
    }
    cerr << "]" << (_color.pop_back(), _color.back());
}

template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu) {
    string _tmp_color = _color.back();
    ++_tmp_color[3], _color.emplace_back(_tmp_color);
    cerr << _color.back() << "(";
    _print_err(_tu.first), cerr << ", ", _print_err(_tu.second);
    cerr << ")" << (_color.pop_back(), _color.back());
    return os;
}

template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &) {
    cerr << ")" << (_color.pop_back(), _color.back());
}

template <size_t I = 0, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(const tuple<U...> &_t) {
    if (!I) {
        string _tmp_color = _color.back();
        ++_tmp_color[3], _color.emplace_back(_tmp_color);
        cerr << _color.back();
    }
    cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}

template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &) {
    cerr << ")" << (_color.pop_back(), _color.back());
}

template <size_t I = 0, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(tuple<U...> &_t) {
    if (!I) {
        string _tmp_color = _color.back();
        ++_tmp_color[3], _color.emplace_back(_tmp_color);
        cerr << _color.back();
    }
    cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}

#endif

#endif

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

182 187
20634704 -703314946 -948946252 144678123 5498424 341678302 -583114991 -196836433 43951489 -525692929 12701289 476729334 473931783 221423816 187493596 355488624 -39527016 -914505949 161713515 -227399136 -318205061 226437730 -601354045 -755181154 -241221294 256834551 44488096 -422708891 -79709...

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #2:

score: 0
Runtime Error

input:

195 195
248663111 -522337032 -47794804 -955243356 418601542 493840666 478655582 -269027492 -801169819 -410940079 -766532109 -547019833 -158802702 -193483181 -125250985 35351136 -47755604 -781346033 -613952400 -155863697 5685369 -620132917 222562003 -563874770 65617262 356362550 -311762774 86801383 -...

output:


result:


Subtask #3:

score: 0
Runtime Error

Test #4:

score: 0
Runtime Error

input:

1834 1935
-32669453 -670047955 -534537788 80759807 -678610903 -5993655 476471070 90341342 -187206225 -710992660 -837284426 -844649722 -846473433 123470247 177108533 -821700607 97488160 171075677 -146656769 -775261735 -464781034 -518041912 -668027329 -286982559 -108624782 483720318 -632815034 -881243...

output:


result:


Subtask #4:

score: 0
Runtime Error

Test #5:

score: 0
Runtime Error

input:

1893 1857
-575490410 -790871182 -488011488 -321041425 238235943 262471772 -469848975 -105728328 62479104 19449896 54374656 91107269 125781673 251316981 -264727698 -933332817 315892884 -117300817 -826569250 -156322407 -109499160 202312868 264008468 -814436982 -431822419 -791224962 -67966257 407973223...

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #7:

score: 0
Runtime Error

input:

97140 97922
75593863 -269004770 -675918045 472330615 -528175962 -580254086 -951270301 -544120385 -525052964 83784128 -226029062 -845875377 34756691 -952920941 -135400084 -20027657 -106558944 -855126948 46245866 -27672459 57802322 -834704313 -625678818 477028623 -9764793 -562713509 477554293 -7238437...

output:


result:


Subtask #6:

score: 0
Runtime Error

Test #8:

score: 0
Runtime Error

input:

97981 186115
-226252189 -571234361 62844820 434180550 269963453 329910638 -847454849 112774660 -178914951 71306715 -859266500 -339120598 -962299988 -157196500 125308122 -668295657 -761232762 165342869 134196398 -767235541 -384052757 -305824813 199376354 226477587 -678798649 -885355596 -979742822 -84...

output:


result:


Subtask #7:

score: 0
Runtime Error

Test #9:

score: 0
Runtime Error

input:

100000 200000
-372870627 -42874740 -537215664 -906588913 -835034566 -406645490 -54474616 -38917607 467210345 -993351739 450345098 12085867 -344729277 -480989044 388326288 -297525580 -259462382 -224591683 -948514660 -494880819 -13589765 -249884145 -387021275 471618602 291976233 358261225 -268906305 1...

output:


result:


Subtask #8:

score: 0
Runtime Error

Test #10:

score: 0
Runtime Error

input:

100000 200000
144608435 -87274600 -974677350 -100352489 -649030362 -39453096 289447879 -537852584 -94574777 337360089 -199669378 -850160928 -298263608 -591161493 231532575 -573617469 -439297426 260642811 425094445 300764130 -476717856 -965323290 102381102 113958066 -683059518 -390842776 -444568945 -...

output:


result:


Subtask #9:

score: 0
Runtime Error

Test #11:

score: 0
Runtime Error

input:

100000 200000
21871390 -860420857 -462213415 -669025807 -260713612 225198084 387180573 31901468 -79466646 -251439643 -593680453 -56298015 -436840232 -277416623 -606833369 311445607 -468196483 -819533304 417838981 -448959219 -517533939 -295117724 -255342449 -218817100 264166786 258541865 7382813 -268...

output:


result:


Subtask #10:

score: 0
Runtime Error

Test #13:

score: 0
Runtime Error

input:

95517 191795
-725239261 -299498656 71286270 -594521669 192006852 271302895 182213759 -447983665 496646313 364428830 141890698 -582020559 102214817 -223415363 -502837969 -762043847 -607694704 -229708001 6321315 240383244 -776743439 193648400 -974528015 44096904 -785689867 -185689539 -492379003 289140...

output:


result:


Subtask #11:

score: 0
Runtime Error

Test #14:

score: 0
Runtime Error

input:

100000 200000
135797954 -138947496 -406182714 438477901 -267057521 -232444211 130630377 -317348655 37833748 -981372450 246923545 -803068401 216077120 233292050 -267523089 -630927369 -922280156 302142108 -175654796 -464364140 -534375053 -118878135 445980692 -371294038 -797139239 -631637350 418273018 ...

output:


result:


Subtask #12:

score: 0
Runtime Error

Test #15:

score: 0
Runtime Error

input:

100000 200000
-924767382 -769781514 144232383 -995460305 274241911 -591199999 -462371403 -736028436 -723144279 204535592 -76117810 136712480 197266266 301370706 -157194236 -533948187 439155758 458743159 -856515801 -189489725 -57278555 -20198384 445455871 272093273 -231072195 212372946 245905921 7066...

output:


result:


Subtask #13:

score: 0
Runtime Error

Test #16:

score: 0
Runtime Error

input:

100000 200000
388142692 -345061796 393830628 210472351 75607734 -959422668 -800026188 -960077632 -668437004 -754515329 -307441856 192254236 -451503349 -536240240 376753194 131296191 -966349165 -144012934 -795609529 -4772916 -149566306 -97856138 -913369907 -924695033 20622624 -474639442 283572561 -95...

output:


result:


Subtask #14:

score: 0
Runtime Error

Test #18:

score: 0
Runtime Error

input:

93028 91818
-295735337 -564744068 -902605531 62391852 -365321307 -603557247 -717081598 162329592 -971363607 247538774 -216804827 -289183462 -770010287 -248152826 -606594806 -23136252 -879560984 -602010879 93750090 -229236489 -647166389 -320819399 -527809250 -999279828 -143001985 -227646820 -49727247...

output:


result:


Subtask #15:

score: 0
Runtime Error

Test #19:

score: 0
Runtime Error

input:

91507 95839
-23664684 -962845837 -26368215 326675641 -724479 499137961 -879329828 -484112881 -891925211 -24962093 291998659 -444033146 -469035647 215328625 78544430 235825511 -873452291 367590693 -588338012 -64562533 243308218 -90161552 107801329 -540773420 -957858728 -963156371 456254393 -455576987...

output:


result:


Subtask #16:

score: 0
Runtime Error

Test #20:

score: 0
Runtime Error

input:

94402 181505
-575507596 154582735 -580773807 -76942222 -218416229 -420520457 -603882856 -579269638 -968806749 -330938819 -594039411 -853624581 12356239 -335972976 -715519332 -115758740 -139424484 145442017 -586731895 -524655417 62044280 447562515 112543550 286412994 -755863775 -964258126 258612618 -...

output:


result:


Subtask #17:

score: 0
Runtime Error

Test #21:

score: 0
Runtime Error

input:

97097 197748
-39532660 72924140 -860212972 266724148 -102927196 -536320064 -542895316 -6951259 -451165977 -563012023 -878017150 234956088 -821084308 70082632 103670556 -550194976 5890742 -374521897 -291211030 -189582599 -532780350 153646292 481408375 -522692696 4914802 144236997 -554911116 209552098...

output:


result:


Subtask #18:

score: 0
Runtime Error

Test #22:

score: 0
Runtime Error

input:

100000 200000
124057764 -95019391 -978000572 221124832 352671144 -189215640 -621389420 -576096799 -860592121 282165011 443560050 4236897 -184072665 -157472860 451941374 -94913773 -40873747 6340470 -178064909 7793037 -811205774 260938388 129013318 -867099913 -258095930 110791678 139837296 -88254587 -...

output:


result:


Subtask #19:

score: 0
Runtime Error

Test #23:

score: 0
Runtime Error

input:

100000 200000
-613945542 -776631594 -426750433 204865476 -956716144 289199620 -415317595 -88687071 -31304858 341801980 -657704863 -153593964 -334118199 -544077510 -801376065 -371865322 -829707245 -144589260 -231246860 -393207796 -260603663 195684150 118550317 -165300622 -770784867 -315971863 -518967...

output:


result:


Subtask #20:

score: 0
Runtime Error

Test #24:

score: 0
Runtime Error

input:

100000 200000
-839752687 193465364 -320699181 364320507 491503148 58174453 -204127703 -818328812 -374166865 -186497314 -99589760 355057503 107437758 101726988 341975032 -881462802 272573187 -493611511 27393952 60635930 94215380 64708383 -472618291 -712265364 -520878214 -426679966 347269993 52124326 ...

output:


result: