Submission #284282

# Submission time Handle Problem Language Result Execution time Memory
284282 2020-08-27T07:06:30 Z 문홍윤(#5761) Progression (NOI20_progression) C++17
100 / 100
1462 ms 69640 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL llinf=2e18;

struct SEGMENT_TREE{
    struct NODE{
        bool setz;
        LL lzy, l, r, sum;
        int nl, nr, ans;
    }tree[1200000];
    struct QUERY_NODE{
        LL l, r;
        int nl, nr, ans, len;
    };
    void prop(int point, int s, int e){
        if(tree[point].setz){
            if(s!=e){
                tree[point*2].setz=true;
                tree[point*2+1].setz=true;
                tree[point*2].lzy=tree[point].lzy;
                tree[point*2+1].lzy=tree[point].lzy;
            }
            else{
                tree[point].l=tree[point].lzy;
                tree[point].r=tree[point].lzy;
                tree[point].sum=tree[point].l;
            }
        }
        else{
            if(s!=e){
                tree[point*2].lzy+=tree[point].lzy;
                tree[point*2+1].lzy+=tree[point].lzy;
            }
            else{
                tree[point].l+=tree[point].lzy;
                tree[point].r+=tree[point].lzy;
                tree[point].sum+=tree[point].lzy;
            }
        }
        tree[point].lzy=0;
        tree[point].setz=false;
    }
    void eat(int point, int s, int e){
        if(s==e)return;
        LL ll, lr, rl, rr, sl, sr;
        int nll, nlr, nrl, nrr, al, ar;
        int mid=(s+e)/2;
        if(tree[point*2].setz){
            ll=lr=tree[point*2].lzy;
            sl=tree[point*2].lzy*(mid-s+1);
            nll=nlr=al=mid-s+1;
        }
        else{
            ll=tree[point*2].l+tree[point*2].lzy;
            lr=tree[point*2].r+tree[point*2].lzy;
            sl=tree[point*2].sum+tree[point*2].lzy*(mid-s+1);
            nll=tree[point*2].nl;
            nlr=tree[point*2].nr;
            al=tree[point*2].ans;
        }
        if(tree[point*2+1].setz){
            rl=rr=tree[point*2+1].lzy;
            sr=tree[point*2+1].lzy*(e-mid);
            nrl=nrr=ar=e-mid;
        }
        else{
            rl=tree[point*2+1].l+tree[point*2+1].lzy;
            rr=tree[point*2+1].r+tree[point*2+1].lzy;
            sr=tree[point*2+1].sum+tree[point*2+1].lzy*(e-mid);
            nrl=tree[point*2+1].nl;
            nrr=tree[point*2+1].nr;
            ar=tree[point*2+1].ans;
        }
        tree[point].ans=max(al, ar);
        tree[point].nl=nll;
        tree[point].nr=nrr;
        tree[point].sum=sl+sr;
        tree[point].l=ll;
        tree[point].r=rr;
        if(lr==rl){
            tree[point].ans=max(tree[point].ans, nlr+nrl);
            if(nll==mid-s+1)tree[point].nl=nll+nrl;
            if(nrr==e-mid)tree[point].nr=nrr+nlr;
        }
    }
    void init(int point, int s, int e){
        tree[point].ans=tree[point].nl=tree[point].nr=e-s+1;
        if(s==e)return;
        init(point*2, s, (s+e)/2);
        init(point*2+1, (s+e)/2+1, e);
    }
    void upd(int point, int s, int e, int a, int b, LL val, bool str){
        if(e<a||s>b)return;
        if(a<=s&&e<=b){
            if(str){
                tree[point].setz=true;
                tree[point].lzy=val;
            }
            else tree[point].lzy+=val;
            return;
        }
        prop(point, s, e);
        upd(point*2, s, (s+e)/2, a, b, val, str);
        upd(point*2+1, (s+e)/2+1, e, a, b, val, str);
        eat(point, s, e);
    }
    QUERY_NODE calc(QUERY_NODE a, QUERY_NODE b){
        QUERY_NODE ret;
        ret.len=a.len+b.len;
        ret.ans=max(a.ans, b.ans);
        ret.l=a.l, ret.r=b.r;
        ret.nl=a.nl, ret.nr=b.nr;
        if(a.r==b.l){
            if(a.nl==a.len)ret.nl=a.nl+b.nl;
            if(b.nr==b.len)ret.nr=b.nr+a.nr;
            ret.ans=max(ret.ans, a.nr+b.nl);
        }
        return ret;
    }
    QUERY_NODE query2(int point, int s, int e, int a, int b){
        if(e<a||s>b)return {llinf, llinf, -1, -1, -1, 0};
        prop(point, s, e);
        if(a<=s&&e<=b){
            eat(point, s, e);
            return {tree[point].l, tree[point].r, tree[point].nl, tree[point].nr, tree[point].ans, e-s+1};
        }
        QUERY_NODE qa=query2(point*2, s, (s+e)/2, a, b);
        QUERY_NODE qb=query2(point*2+1, (s+e)/2+1, e, a, b);
        eat(point, s, e);
        if(qa.l==llinf)return qb;
        if(qb.l==llinf)return qa;
        return calc(qa, qb);
    }
    int query(int point, int s, int e, int a, int b){
        if(a>b)return 1;
        return query2(point, s, e, a, b).ans+1;
    }
    LL get_sum(int point, int s, int e, int a, int b){
        if(e<a||s>b)return 0;
        prop(point, s, e);
        if(a<=s&&e<=b){
            eat(point, s, e);
            return tree[point].sum;
        }
        LL ret=0;
        ret+=get_sum(point*2, s, (s+e)/2, a, b);
        ret+=get_sum(point*2+1, (s+e)/2+1, e, a, b);
        eat(point, s, e);
        return ret;
    }
}seg;

int n, q;
LL arr[300010];

int main(){
    scanf("%d %d", &n, &q);
    for(int i=1; i<=n; i++)scanf("%lld", &arr[i]);
    seg.init(1, 1, n);
    for(int i=1; i<=n; i++)seg.upd(1, 1, n, i, i, arr[i]-arr[i-1], true);
    for(int i=1; i<=q; i++){
        int qt, a, b;
        scanf("%d", &qt);
        if(qt==1){
            LL c, d;
            scanf("%d %d %lld %lld", &a, &b, &c, &d);
            if(a+1<=b)seg.upd(1, 1, n, a+1, b, d, false);
            seg.upd(1, 1, n, a, a, c, false);
            if(b<n)seg.upd(1, 1, n, b+1, b+1, -c-d*(b-a), false);
        }
        if(qt==2){
            LL c, d, fr, re;
            scanf("%d %d %lld %lld", &a, &b, &c, &d);
            re=seg.get_sum(1, 1, n, 1, b+1);
            fr=seg.get_sum(1, 1, n, 1, a-1);
            if(a+1<=b)seg.upd(1, 1, n, a+1, b, d, true);
            seg.upd(1, 1, n, a, a, c-fr, true);
            if(b<n)seg.upd(1, 1, n, b+1, b+1, re-c-d*(b-a), true);
        }
        if(qt==3){
            scanf("%d %d", &a, &b);
            int ans=seg.query(1, 1, n, a+1, b);
            printf("%d\n", ans);
        }
    }
}

Compilation message

Progression.cpp: In function 'int main()':
Progression.cpp:158:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  158 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:159:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  159 |     for(int i=1; i<=n; i++)scanf("%lld", &arr[i]);
      |                            ~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:164:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  164 |         scanf("%d", &qt);
      |         ~~~~~^~~~~~~~~~~
Progression.cpp:167:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  167 |             scanf("%d %d %lld %lld", &a, &b, &c, &d);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:174:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  174 |             scanf("%d %d %lld %lld", &a, &b, &c, &d);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:182:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  182 |             scanf("%d %d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 654 ms 61432 KB Output is correct
2 Correct 215 ms 1016 KB Output is correct
3 Correct 214 ms 888 KB Output is correct
4 Correct 211 ms 1096 KB Output is correct
5 Correct 212 ms 1144 KB Output is correct
6 Correct 214 ms 1016 KB Output is correct
7 Correct 214 ms 888 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 674 ms 61288 KB Output is correct
12 Correct 677 ms 61368 KB Output is correct
13 Correct 658 ms 61432 KB Output is correct
14 Correct 672 ms 61688 KB Output is correct
15 Correct 654 ms 61492 KB Output is correct
16 Correct 653 ms 61176 KB Output is correct
17 Correct 666 ms 61212 KB Output is correct
18 Correct 714 ms 61328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 288 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 735 ms 61520 KB Output is correct
2 Correct 178 ms 1272 KB Output is correct
3 Correct 166 ms 1144 KB Output is correct
4 Correct 139 ms 1144 KB Output is correct
5 Correct 211 ms 1272 KB Output is correct
6 Correct 174 ms 1272 KB Output is correct
7 Correct 175 ms 1400 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 802 ms 61468 KB Output is correct
12 Correct 709 ms 61560 KB Output is correct
13 Correct 807 ms 61176 KB Output is correct
14 Correct 805 ms 61176 KB Output is correct
15 Correct 723 ms 61432 KB Output is correct
16 Correct 820 ms 61876 KB Output is correct
17 Correct 903 ms 62108 KB Output is correct
18 Correct 823 ms 61960 KB Output is correct
19 Correct 732 ms 61364 KB Output is correct
20 Correct 748 ms 61304 KB Output is correct
21 Correct 719 ms 61220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1056 ms 61052 KB Output is correct
2 Correct 255 ms 764 KB Output is correct
3 Correct 239 ms 760 KB Output is correct
4 Correct 251 ms 760 KB Output is correct
5 Correct 240 ms 760 KB Output is correct
6 Correct 243 ms 760 KB Output is correct
7 Correct 259 ms 760 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1139 ms 61036 KB Output is correct
12 Correct 1064 ms 61176 KB Output is correct
13 Correct 1093 ms 60892 KB Output is correct
14 Correct 1093 ms 60924 KB Output is correct
15 Correct 980 ms 60992 KB Output is correct
16 Correct 1097 ms 61080 KB Output is correct
17 Correct 1104 ms 61176 KB Output is correct
18 Correct 1086 ms 61060 KB Output is correct
19 Correct 1041 ms 60932 KB Output is correct
20 Correct 1050 ms 61000 KB Output is correct
21 Correct 1051 ms 60920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 735 ms 61520 KB Output is correct
2 Correct 178 ms 1272 KB Output is correct
3 Correct 166 ms 1144 KB Output is correct
4 Correct 139 ms 1144 KB Output is correct
5 Correct 211 ms 1272 KB Output is correct
6 Correct 174 ms 1272 KB Output is correct
7 Correct 175 ms 1400 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 802 ms 61468 KB Output is correct
12 Correct 709 ms 61560 KB Output is correct
13 Correct 807 ms 61176 KB Output is correct
14 Correct 805 ms 61176 KB Output is correct
15 Correct 723 ms 61432 KB Output is correct
16 Correct 820 ms 61876 KB Output is correct
17 Correct 903 ms 62108 KB Output is correct
18 Correct 823 ms 61960 KB Output is correct
19 Correct 732 ms 61364 KB Output is correct
20 Correct 748 ms 61304 KB Output is correct
21 Correct 719 ms 61220 KB Output is correct
22 Correct 1111 ms 61008 KB Output is correct
23 Correct 245 ms 3576 KB Output is correct
24 Correct 220 ms 3576 KB Output is correct
25 Correct 217 ms 3608 KB Output is correct
26 Correct 226 ms 3704 KB Output is correct
27 Correct 230 ms 3576 KB Output is correct
28 Correct 230 ms 3972 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1147 ms 66808 KB Output is correct
33 Correct 1115 ms 69640 KB Output is correct
34 Correct 1167 ms 66944 KB Output is correct
35 Correct 1151 ms 66936 KB Output is correct
36 Correct 1086 ms 66680 KB Output is correct
37 Correct 1101 ms 66556 KB Output is correct
38 Correct 1079 ms 66808 KB Output is correct
39 Correct 1128 ms 69588 KB Output is correct
40 Correct 1198 ms 69368 KB Output is correct
41 Correct 1217 ms 69368 KB Output is correct
42 Correct 1179 ms 69496 KB Output is correct
43 Correct 1131 ms 69224 KB Output is correct
44 Correct 1117 ms 69112 KB Output is correct
45 Correct 1105 ms 69088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 654 ms 61432 KB Output is correct
2 Correct 215 ms 1016 KB Output is correct
3 Correct 214 ms 888 KB Output is correct
4 Correct 211 ms 1096 KB Output is correct
5 Correct 212 ms 1144 KB Output is correct
6 Correct 214 ms 1016 KB Output is correct
7 Correct 214 ms 888 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 674 ms 61288 KB Output is correct
12 Correct 677 ms 61368 KB Output is correct
13 Correct 658 ms 61432 KB Output is correct
14 Correct 672 ms 61688 KB Output is correct
15 Correct 654 ms 61492 KB Output is correct
16 Correct 653 ms 61176 KB Output is correct
17 Correct 666 ms 61212 KB Output is correct
18 Correct 714 ms 61328 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 2 ms 288 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 4 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 735 ms 61520 KB Output is correct
41 Correct 178 ms 1272 KB Output is correct
42 Correct 166 ms 1144 KB Output is correct
43 Correct 139 ms 1144 KB Output is correct
44 Correct 211 ms 1272 KB Output is correct
45 Correct 174 ms 1272 KB Output is correct
46 Correct 175 ms 1400 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 802 ms 61468 KB Output is correct
51 Correct 709 ms 61560 KB Output is correct
52 Correct 807 ms 61176 KB Output is correct
53 Correct 805 ms 61176 KB Output is correct
54 Correct 723 ms 61432 KB Output is correct
55 Correct 820 ms 61876 KB Output is correct
56 Correct 903 ms 62108 KB Output is correct
57 Correct 823 ms 61960 KB Output is correct
58 Correct 732 ms 61364 KB Output is correct
59 Correct 748 ms 61304 KB Output is correct
60 Correct 719 ms 61220 KB Output is correct
61 Correct 1056 ms 61052 KB Output is correct
62 Correct 255 ms 764 KB Output is correct
63 Correct 239 ms 760 KB Output is correct
64 Correct 251 ms 760 KB Output is correct
65 Correct 240 ms 760 KB Output is correct
66 Correct 243 ms 760 KB Output is correct
67 Correct 259 ms 760 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1139 ms 61036 KB Output is correct
72 Correct 1064 ms 61176 KB Output is correct
73 Correct 1093 ms 60892 KB Output is correct
74 Correct 1093 ms 60924 KB Output is correct
75 Correct 980 ms 60992 KB Output is correct
76 Correct 1097 ms 61080 KB Output is correct
77 Correct 1104 ms 61176 KB Output is correct
78 Correct 1086 ms 61060 KB Output is correct
79 Correct 1041 ms 60932 KB Output is correct
80 Correct 1050 ms 61000 KB Output is correct
81 Correct 1051 ms 60920 KB Output is correct
82 Correct 1111 ms 61008 KB Output is correct
83 Correct 245 ms 3576 KB Output is correct
84 Correct 220 ms 3576 KB Output is correct
85 Correct 217 ms 3608 KB Output is correct
86 Correct 226 ms 3704 KB Output is correct
87 Correct 230 ms 3576 KB Output is correct
88 Correct 230 ms 3972 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 1147 ms 66808 KB Output is correct
93 Correct 1115 ms 69640 KB Output is correct
94 Correct 1167 ms 66944 KB Output is correct
95 Correct 1151 ms 66936 KB Output is correct
96 Correct 1086 ms 66680 KB Output is correct
97 Correct 1101 ms 66556 KB Output is correct
98 Correct 1079 ms 66808 KB Output is correct
99 Correct 1128 ms 69588 KB Output is correct
100 Correct 1198 ms 69368 KB Output is correct
101 Correct 1217 ms 69368 KB Output is correct
102 Correct 1179 ms 69496 KB Output is correct
103 Correct 1131 ms 69224 KB Output is correct
104 Correct 1117 ms 69112 KB Output is correct
105 Correct 1105 ms 69088 KB Output is correct
106 Correct 1380 ms 69240 KB Output is correct
107 Correct 309 ms 3796 KB Output is correct
108 Correct 307 ms 3832 KB Output is correct
109 Correct 312 ms 3832 KB Output is correct
110 Correct 1 ms 384 KB Output is correct
111 Correct 1 ms 384 KB Output is correct
112 Correct 1 ms 384 KB Output is correct
113 Correct 1220 ms 69260 KB Output is correct
114 Correct 1182 ms 69240 KB Output is correct
115 Correct 1222 ms 69240 KB Output is correct
116 Correct 1140 ms 69004 KB Output is correct
117 Correct 1462 ms 69368 KB Output is correct
118 Correct 1129 ms 69368 KB Output is correct
119 Correct 1111 ms 68868 KB Output is correct
120 Correct 814 ms 68076 KB Output is correct
121 Correct 810 ms 68088 KB Output is correct
122 Correct 819 ms 67984 KB Output is correct
123 Correct 730 ms 67192 KB Output is correct
124 Correct 722 ms 67320 KB Output is correct
125 Correct 730 ms 67088 KB Output is correct
126 Correct 1427 ms 67012 KB Output is correct
127 Correct 1382 ms 67064 KB Output is correct
128 Correct 1403 ms 68988 KB Output is correct
129 Correct 1389 ms 67188 KB Output is correct
130 Correct 1172 ms 67192 KB Output is correct
131 Correct 1153 ms 67192 KB Output is correct
132 Correct 1145 ms 67192 KB Output is correct
133 Correct 1383 ms 69112 KB Output is correct
134 Correct 1442 ms 68984 KB Output is correct
135 Correct 1424 ms 69368 KB Output is correct
136 Correct 316 ms 3704 KB Output is correct
137 Correct 308 ms 3704 KB Output is correct
138 Correct 311 ms 3704 KB Output is correct