Submission #337295

# Submission time Handle Problem Language Result Execution time Memory
337295 2020-12-19T13:24:22 Z ryangohca Progression (NOI20_progression) C++17
100 / 100
2278 ms 86092 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define tpip tuple<pii, int, pii>
using namespace std;
struct node{
    int s, e, m, sum, maxcos, lazyset, lazyadd;
    bool lazyseton;
    pii pref, suff;
    node *l, *r;
    node(int _s, int _e): s(_s), e(_e), m((_s+_e)/2), maxcos(0), lazyset(-1), lazyadd(0), sum(0), lazyseton(false){
        if (s != e){
            l = new node(s, m);
            r = new node(m+1, e);
        }
    }
    void value(){
        if (lazyseton){
            pref = suff = pii(lazyset+lazyadd, e-s+1);
            sum = (lazyset + lazyadd) * (e-s+1);
            if (s!=e){
                l->lazyset = r->lazyset = lazyset;
                l->lazyadd = r->lazyadd = lazyadd;
                l->lazyseton = r->lazyseton = true;
            }
            lazyadd = 0;
            lazyset = -1;
            lazyseton = false;
            maxcos = e - s + 1;
        } else {
            pref.first += lazyadd;
            suff.first += lazyadd;
            sum += lazyadd * (e-s+1);
            if (s != e){
                l->lazyadd += lazyadd;
                r->lazyadd += lazyadd;
            }
            lazyadd = 0;
        }
    }
    tpip merge_child(tpip lft, tpip rgt, int lftlen, int rgtlen, bool upd = true){
        if (s==e) return tpip(pref, maxcos, suff);
        pii pref, suff;
        int maxcos = 1;
        auto [lpref, lmaxcos, lsuff] = lft;
        auto [rpref, rmaxcos, rsuff] = rgt;
        if (lpref == lsuff && lpref.first == rpref.first && lpref.second == lftlen){
            pref = pii(lpref.first, lpref.second + rpref.second);
        } else {
            pref = lpref;
        }
        if (rpref == rsuff && lsuff.first == rpref.first && rsuff.second == rgtlen){
            suff = pii(lsuff.first, lsuff.second + rpref.second);
        } else {
            suff = rsuff;
        }
        if (lsuff.first == rpref.first){
            maxcos = lsuff.second + rpref.second;
        }
        maxcos = max({maxcos, pref.second, suff.second, lmaxcos, rmaxcos});
        if (upd){
            this->pref = pref;
            this->suff = suff;
            this->maxcos = maxcos;
        }
        return tpip(pref, maxcos, suff);
    }
    void add(int x, int y, int val){
        value();
        if (s==x && e==y){
            lazyadd += val;
            value();
            return;
        }
        if (y <= m) l->add(x, y, val);
        else if (x > m) r->add(x, y, val);
        else l->add(x, m, val), r->add(m+1, y, val);
        l->value(); r->value();
        tpip lft = tpip(l->pref, l->maxcos, l->suff);
        tpip rgt = tpip(r->pref, r->maxcos, r->suff);
        merge_child(lft, rgt, l->e - l->s + 1, r->e - r->s + 1);
        sum = l->sum + r->sum;
    }
    void set(int x, int y, int val){
        value();
        if (s==x && e==y){
            lazyset = val;
            lazyseton = true;
            value();
            return;
        }
        if (y <= m) l->set(x, y, val);
        else if (x > m) r->set(x, y, val);
        else l->set(x, m, val), r->set(m+1, y, val);
        l->value(); r->value();
        tpip lft = tpip(l->pref, l->maxcos, l->suff);
        tpip rgt = tpip(r->pref, r->maxcos, r->suff);
        merge_child(lft, rgt, l->e - l->s + 1, r->e - r->s + 1);
        sum = l->sum + r->sum;
    }
    tpip query(int x, int y){
        value();
        if (s==x && e==y){
            return tpip(pref, maxcos, suff);
        }
        if (y <= m) return l->query(x, y);
        else if (x > m) return r->query(x, y);
        else {
            tpip lft = l->query(x, m);
            tpip rgt = r->query(m+1, y);
            tpip ans = merge_child(lft, rgt, m-x+1, y-(m+1)+1, false);
            return ans;
        }
    }
    int maxplayable(int x, int y){
        tpip ans = query(x, y);
        return get<1>(ans);
    }
    int range_sum(int x, int y){
        value();
        if (s==x && e==y) return sum;
        else if (y <= m) return l->range_sum(x, y);
        else if (x > m) return r->range_sum(x, y);
        else return l->range_sum(x, m) + r->range_sum(m+1, y);
    }
} *root;
main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, q; cin >> n >> q;
    int st; cin >> st;
    int pref = st;
    if (n != 1) root = new node(0, n-2);
    for (int i = 0; i < n - 1; i++){
        int g; cin >> g;
        root->set(i, i, g-pref);
        pref = g;
    }
    for (int i = 0; i < q; i++){
        int t; cin >> t;
        if (t==3){
            int a, b; cin >> a >> b; a--; b--;
            if (a == b) cout << "1\n";
            else cout << root->maxplayable(a, b-1) + 1 << '\n';
        } else if (t==2){
            int l, r, s, c; cin >> l >> r >> s >> c;
            if (n==1) continue;
            l--; r--;
            int prev = -1, aft = -1;
            bool prevset = false, aftset = false;
            if (l != 0){
                if (l==1) prev = st, prevset = true;
                else prev = st + root->range_sum(0, l-2), prevset = true;
            }
            if (r!=n-1) aft = st + root->range_sum(0, r), aftset = true;
            int e = s + (r-l) * c;
            if (prevset) root->set(l-1, l-1, s-prev);
            if (aftset) root->set(r, r, aft-e);
            if (l != r) root->set(l, r-1, c);
            if (l==0) st = s;
        } else {
            int l, r, s, c; cin >> l >> r >> s >> c;
            if (n==1) continue;
            l--; r--;
            if (l != 0) root->add(l-1, l-1, s);
            if (r != n-1) root->add(r, r, -(s + (r-l)*c));
            if (l != r) root->add(l, r-1, c);
            if (l == 0) st += s;
        }
    }
}

Compilation message

Progression.cpp: In constructor 'node::node(long long int, long long int)':
Progression.cpp:7:40: warning: 'node::lazyadd' will be initialized after [-Wreorder]
    7 |     int s, e, m, sum, maxcos, lazyset, lazyadd;
      |                                        ^~~~~~~
Progression.cpp:7:18: warning:   'long long int node::sum' [-Wreorder]
    7 |     int s, e, m, sum, maxcos, lazyset, lazyadd;
      |                  ^~~
Progression.cpp:11:5: warning:   when initialized here [-Wreorder]
   11 |     node(int _s, int _e): s(_s), e(_e), m((_s+_e)/2), maxcos(0), lazyset(-1), lazyadd(0), sum(0), lazyseton(false){
      |     ^~~~
Progression.cpp: At global scope:
Progression.cpp:127:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  127 | main(){
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 447 ms 84116 KB Output is correct
2 Correct 100 ms 3564 KB Output is correct
3 Correct 105 ms 3712 KB Output is correct
4 Correct 101 ms 3564 KB Output is correct
5 Correct 99 ms 3640 KB Output is correct
6 Correct 100 ms 3692 KB Output is correct
7 Correct 101 ms 3692 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 446 ms 84100 KB Output is correct
12 Correct 451 ms 84076 KB Output is correct
13 Correct 450 ms 84460 KB Output is correct
14 Correct 442 ms 84460 KB Output is correct
15 Correct 451 ms 84332 KB Output is correct
16 Correct 454 ms 84204 KB Output is correct
17 Correct 455 ms 84076 KB Output is correct
18 Correct 459 ms 84076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 620 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 5 ms 620 KB Output is correct
10 Correct 3 ms 620 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 3 ms 620 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 711 ms 82768 KB Output is correct
2 Correct 112 ms 3052 KB Output is correct
3 Correct 100 ms 3052 KB Output is correct
4 Correct 89 ms 3328 KB Output is correct
5 Correct 102 ms 3208 KB Output is correct
6 Correct 100 ms 3180 KB Output is correct
7 Correct 101 ms 3180 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 842 ms 81260 KB Output is correct
12 Correct 713 ms 82540 KB Output is correct
13 Correct 841 ms 81260 KB Output is correct
14 Correct 835 ms 81260 KB Output is correct
15 Correct 709 ms 82540 KB Output is correct
16 Correct 830 ms 83284 KB Output is correct
17 Correct 818 ms 83180 KB Output is correct
18 Correct 828 ms 83308 KB Output is correct
19 Correct 696 ms 82796 KB Output is correct
20 Correct 694 ms 82540 KB Output is correct
21 Correct 691 ms 82668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1447 ms 85668 KB Output is correct
2 Correct 187 ms 3692 KB Output is correct
3 Correct 192 ms 3676 KB Output is correct
4 Correct 188 ms 3740 KB Output is correct
5 Correct 195 ms 3704 KB Output is correct
6 Correct 195 ms 3820 KB Output is correct
7 Correct 194 ms 3716 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1444 ms 82180 KB Output is correct
12 Correct 1401 ms 85576 KB Output is correct
13 Correct 1461 ms 82412 KB Output is correct
14 Correct 1473 ms 82296 KB Output is correct
15 Correct 1317 ms 85356 KB Output is correct
16 Correct 1501 ms 85612 KB Output is correct
17 Correct 1475 ms 85460 KB Output is correct
18 Correct 1445 ms 85636 KB Output is correct
19 Correct 1359 ms 85380 KB Output is correct
20 Correct 1368 ms 85612 KB Output is correct
21 Correct 1363 ms 85508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 711 ms 82768 KB Output is correct
2 Correct 112 ms 3052 KB Output is correct
3 Correct 100 ms 3052 KB Output is correct
4 Correct 89 ms 3328 KB Output is correct
5 Correct 102 ms 3208 KB Output is correct
6 Correct 100 ms 3180 KB Output is correct
7 Correct 101 ms 3180 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 842 ms 81260 KB Output is correct
12 Correct 713 ms 82540 KB Output is correct
13 Correct 841 ms 81260 KB Output is correct
14 Correct 835 ms 81260 KB Output is correct
15 Correct 709 ms 82540 KB Output is correct
16 Correct 830 ms 83284 KB Output is correct
17 Correct 818 ms 83180 KB Output is correct
18 Correct 828 ms 83308 KB Output is correct
19 Correct 696 ms 82796 KB Output is correct
20 Correct 694 ms 82540 KB Output is correct
21 Correct 691 ms 82668 KB Output is correct
22 Correct 1804 ms 84972 KB Output is correct
23 Correct 192 ms 3564 KB Output is correct
24 Correct 190 ms 3692 KB Output is correct
25 Correct 185 ms 3564 KB Output is correct
26 Correct 196 ms 3564 KB Output is correct
27 Correct 195 ms 3596 KB Output is correct
28 Correct 192 ms 3564 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1896 ms 82180 KB Output is correct
33 Correct 1766 ms 84972 KB Output is correct
34 Correct 1855 ms 82412 KB Output is correct
35 Correct 1852 ms 82220 KB Output is correct
36 Correct 1462 ms 82028 KB Output is correct
37 Correct 1465 ms 82216 KB Output is correct
38 Correct 1463 ms 81920 KB Output is correct
39 Correct 1811 ms 85100 KB Output is correct
40 Correct 1876 ms 85064 KB Output is correct
41 Correct 1873 ms 85100 KB Output is correct
42 Correct 1866 ms 84996 KB Output is correct
43 Correct 1775 ms 84812 KB Output is correct
44 Correct 1775 ms 85076 KB Output is correct
45 Correct 1759 ms 84972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 447 ms 84116 KB Output is correct
2 Correct 100 ms 3564 KB Output is correct
3 Correct 105 ms 3712 KB Output is correct
4 Correct 101 ms 3564 KB Output is correct
5 Correct 99 ms 3640 KB Output is correct
6 Correct 100 ms 3692 KB Output is correct
7 Correct 101 ms 3692 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 446 ms 84100 KB Output is correct
12 Correct 451 ms 84076 KB Output is correct
13 Correct 450 ms 84460 KB Output is correct
14 Correct 442 ms 84460 KB Output is correct
15 Correct 451 ms 84332 KB Output is correct
16 Correct 454 ms 84204 KB Output is correct
17 Correct 455 ms 84076 KB Output is correct
18 Correct 459 ms 84076 KB Output is correct
19 Correct 3 ms 620 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 3 ms 620 KB Output is correct
27 Correct 5 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 3 ms 620 KB Output is correct
30 Correct 3 ms 620 KB Output is correct
31 Correct 3 ms 492 KB Output is correct
32 Correct 3 ms 620 KB Output is correct
33 Correct 3 ms 620 KB Output is correct
34 Correct 3 ms 640 KB Output is correct
35 Correct 3 ms 620 KB Output is correct
36 Correct 3 ms 620 KB Output is correct
37 Correct 2 ms 364 KB Output is correct
38 Correct 2 ms 364 KB Output is correct
39 Correct 2 ms 364 KB Output is correct
40 Correct 711 ms 82768 KB Output is correct
41 Correct 112 ms 3052 KB Output is correct
42 Correct 100 ms 3052 KB Output is correct
43 Correct 89 ms 3328 KB Output is correct
44 Correct 102 ms 3208 KB Output is correct
45 Correct 100 ms 3180 KB Output is correct
46 Correct 101 ms 3180 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 842 ms 81260 KB Output is correct
51 Correct 713 ms 82540 KB Output is correct
52 Correct 841 ms 81260 KB Output is correct
53 Correct 835 ms 81260 KB Output is correct
54 Correct 709 ms 82540 KB Output is correct
55 Correct 830 ms 83284 KB Output is correct
56 Correct 818 ms 83180 KB Output is correct
57 Correct 828 ms 83308 KB Output is correct
58 Correct 696 ms 82796 KB Output is correct
59 Correct 694 ms 82540 KB Output is correct
60 Correct 691 ms 82668 KB Output is correct
61 Correct 1447 ms 85668 KB Output is correct
62 Correct 187 ms 3692 KB Output is correct
63 Correct 192 ms 3676 KB Output is correct
64 Correct 188 ms 3740 KB Output is correct
65 Correct 195 ms 3704 KB Output is correct
66 Correct 195 ms 3820 KB Output is correct
67 Correct 194 ms 3716 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1444 ms 82180 KB Output is correct
72 Correct 1401 ms 85576 KB Output is correct
73 Correct 1461 ms 82412 KB Output is correct
74 Correct 1473 ms 82296 KB Output is correct
75 Correct 1317 ms 85356 KB Output is correct
76 Correct 1501 ms 85612 KB Output is correct
77 Correct 1475 ms 85460 KB Output is correct
78 Correct 1445 ms 85636 KB Output is correct
79 Correct 1359 ms 85380 KB Output is correct
80 Correct 1368 ms 85612 KB Output is correct
81 Correct 1363 ms 85508 KB Output is correct
82 Correct 1804 ms 84972 KB Output is correct
83 Correct 192 ms 3564 KB Output is correct
84 Correct 190 ms 3692 KB Output is correct
85 Correct 185 ms 3564 KB Output is correct
86 Correct 196 ms 3564 KB Output is correct
87 Correct 195 ms 3596 KB Output is correct
88 Correct 192 ms 3564 KB Output is correct
89 Correct 1 ms 364 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 1896 ms 82180 KB Output is correct
93 Correct 1766 ms 84972 KB Output is correct
94 Correct 1855 ms 82412 KB Output is correct
95 Correct 1852 ms 82220 KB Output is correct
96 Correct 1462 ms 82028 KB Output is correct
97 Correct 1465 ms 82216 KB Output is correct
98 Correct 1463 ms 81920 KB Output is correct
99 Correct 1811 ms 85100 KB Output is correct
100 Correct 1876 ms 85064 KB Output is correct
101 Correct 1873 ms 85100 KB Output is correct
102 Correct 1866 ms 84996 KB Output is correct
103 Correct 1775 ms 84812 KB Output is correct
104 Correct 1775 ms 85076 KB Output is correct
105 Correct 1759 ms 84972 KB Output is correct
106 Correct 2239 ms 85988 KB Output is correct
107 Correct 271 ms 3820 KB Output is correct
108 Correct 267 ms 3820 KB Output is correct
109 Correct 266 ms 3820 KB Output is correct
110 Correct 1 ms 364 KB Output is correct
111 Correct 1 ms 364 KB Output is correct
112 Correct 1 ms 364 KB Output is correct
113 Correct 1887 ms 84972 KB Output is correct
114 Correct 1860 ms 85076 KB Output is correct
115 Correct 1872 ms 84812 KB Output is correct
116 Correct 1761 ms 84972 KB Output is correct
117 Correct 2262 ms 85868 KB Output is correct
118 Correct 1762 ms 85104 KB Output is correct
119 Correct 1747 ms 84892 KB Output is correct
120 Correct 807 ms 83588 KB Output is correct
121 Correct 803 ms 83436 KB Output is correct
122 Correct 809 ms 83472 KB Output is correct
123 Correct 694 ms 82820 KB Output is correct
124 Correct 692 ms 82668 KB Output is correct
125 Correct 690 ms 82540 KB Output is correct
126 Correct 2276 ms 82768 KB Output is correct
127 Correct 2245 ms 82668 KB Output is correct
128 Correct 2255 ms 85996 KB Output is correct
129 Correct 2248 ms 82596 KB Output is correct
130 Correct 1649 ms 82668 KB Output is correct
131 Correct 1636 ms 82540 KB Output is correct
132 Correct 1618 ms 82728 KB Output is correct
133 Correct 2268 ms 85880 KB Output is correct
134 Correct 2234 ms 85796 KB Output is correct
135 Correct 2278 ms 86092 KB Output is correct
136 Correct 266 ms 3820 KB Output is correct
137 Correct 268 ms 3820 KB Output is correct
138 Correct 266 ms 3820 KB Output is correct