답안 #284283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284283 2020-08-27T07:09:39 Z 문홍윤(#5761) Progression (NOI20_progression) C++17
100 / 100
1458 ms 64376 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].lzy;
            }
        }
        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].l;
            }
        }
        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);
      |             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 682 ms 63424 KB Output is correct
2 Correct 229 ms 2556 KB Output is correct
3 Correct 214 ms 2552 KB Output is correct
4 Correct 213 ms 2808 KB Output is correct
5 Correct 220 ms 2808 KB Output is correct
6 Correct 218 ms 2656 KB Output is correct
7 Correct 212 ms 2680 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 665 ms 63352 KB Output is correct
12 Correct 661 ms 63280 KB Output is correct
13 Correct 657 ms 63704 KB Output is correct
14 Correct 650 ms 63992 KB Output is correct
15 Correct 667 ms 63652 KB Output is correct
16 Correct 663 ms 63488 KB Output is correct
17 Correct 693 ms 63692 KB Output is correct
18 Correct 685 ms 63736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 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 3 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 3 ms 512 KB Output is correct
14 Correct 3 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 4 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
# 결과 실행 시간 메모리 Grader output
1 Correct 743 ms 63696 KB Output is correct
2 Correct 176 ms 2680 KB Output is correct
3 Correct 166 ms 2424 KB Output is correct
4 Correct 161 ms 2424 KB Output is correct
5 Correct 183 ms 2672 KB Output is correct
6 Correct 180 ms 2556 KB Output is correct
7 Correct 179 ms 2808 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 851 ms 63464 KB Output is correct
12 Correct 724 ms 63736 KB Output is correct
13 Correct 800 ms 63384 KB Output is correct
14 Correct 813 ms 63608 KB Output is correct
15 Correct 745 ms 63840 KB Output is correct
16 Correct 862 ms 64120 KB Output is correct
17 Correct 853 ms 64124 KB Output is correct
18 Correct 820 ms 64120 KB Output is correct
19 Correct 723 ms 63368 KB Output is correct
20 Correct 719 ms 63352 KB Output is correct
21 Correct 712 ms 62968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1061 ms 63868 KB Output is correct
2 Correct 236 ms 2168 KB Output is correct
3 Correct 246 ms 2168 KB Output is correct
4 Correct 236 ms 2168 KB Output is correct
5 Correct 246 ms 2168 KB Output is correct
6 Correct 248 ms 2168 KB Output is correct
7 Correct 240 ms 2168 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 1105 ms 63608 KB Output is correct
12 Correct 1058 ms 64248 KB Output is correct
13 Correct 1068 ms 63608 KB Output is correct
14 Correct 1056 ms 63620 KB Output is correct
15 Correct 1008 ms 64044 KB Output is correct
16 Correct 1099 ms 64376 KB Output is correct
17 Correct 1095 ms 64248 KB Output is correct
18 Correct 1111 ms 64296 KB Output is correct
19 Correct 1033 ms 64248 KB Output is correct
20 Correct 1069 ms 64292 KB Output is correct
21 Correct 1038 ms 64248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 743 ms 63696 KB Output is correct
2 Correct 176 ms 2680 KB Output is correct
3 Correct 166 ms 2424 KB Output is correct
4 Correct 161 ms 2424 KB Output is correct
5 Correct 183 ms 2672 KB Output is correct
6 Correct 180 ms 2556 KB Output is correct
7 Correct 179 ms 2808 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 851 ms 63464 KB Output is correct
12 Correct 724 ms 63736 KB Output is correct
13 Correct 800 ms 63384 KB Output is correct
14 Correct 813 ms 63608 KB Output is correct
15 Correct 745 ms 63840 KB Output is correct
16 Correct 862 ms 64120 KB Output is correct
17 Correct 853 ms 64124 KB Output is correct
18 Correct 820 ms 64120 KB Output is correct
19 Correct 723 ms 63368 KB Output is correct
20 Correct 719 ms 63352 KB Output is correct
21 Correct 712 ms 62968 KB Output is correct
22 Correct 1124 ms 64352 KB Output is correct
23 Correct 224 ms 1528 KB Output is correct
24 Correct 220 ms 1400 KB Output is correct
25 Correct 216 ms 1396 KB Output is correct
26 Correct 227 ms 1528 KB Output is correct
27 Correct 237 ms 1400 KB Output is correct
28 Correct 221 ms 1400 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 1156 ms 61432 KB Output is correct
33 Correct 1091 ms 61304 KB Output is correct
34 Correct 1166 ms 61560 KB Output is correct
35 Correct 1142 ms 61408 KB Output is correct
36 Correct 1077 ms 61560 KB Output is correct
37 Correct 1170 ms 61632 KB Output is correct
38 Correct 1054 ms 61560 KB Output is correct
39 Correct 1156 ms 61304 KB Output is correct
40 Correct 1214 ms 61560 KB Output is correct
41 Correct 1209 ms 61728 KB Output is correct
42 Correct 1304 ms 61560 KB Output is correct
43 Correct 1142 ms 61688 KB Output is correct
44 Correct 1136 ms 61432 KB Output is correct
45 Correct 1117 ms 61644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 682 ms 63424 KB Output is correct
2 Correct 229 ms 2556 KB Output is correct
3 Correct 214 ms 2552 KB Output is correct
4 Correct 213 ms 2808 KB Output is correct
5 Correct 220 ms 2808 KB Output is correct
6 Correct 218 ms 2656 KB Output is correct
7 Correct 212 ms 2680 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 665 ms 63352 KB Output is correct
12 Correct 661 ms 63280 KB Output is correct
13 Correct 657 ms 63704 KB Output is correct
14 Correct 650 ms 63992 KB Output is correct
15 Correct 667 ms 63652 KB Output is correct
16 Correct 663 ms 63488 KB Output is correct
17 Correct 693 ms 63692 KB Output is correct
18 Correct 685 ms 63736 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 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 3 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 3 ms 512 KB Output is correct
32 Correct 3 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 4 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 743 ms 63696 KB Output is correct
41 Correct 176 ms 2680 KB Output is correct
42 Correct 166 ms 2424 KB Output is correct
43 Correct 161 ms 2424 KB Output is correct
44 Correct 183 ms 2672 KB Output is correct
45 Correct 180 ms 2556 KB Output is correct
46 Correct 179 ms 2808 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 851 ms 63464 KB Output is correct
51 Correct 724 ms 63736 KB Output is correct
52 Correct 800 ms 63384 KB Output is correct
53 Correct 813 ms 63608 KB Output is correct
54 Correct 745 ms 63840 KB Output is correct
55 Correct 862 ms 64120 KB Output is correct
56 Correct 853 ms 64124 KB Output is correct
57 Correct 820 ms 64120 KB Output is correct
58 Correct 723 ms 63368 KB Output is correct
59 Correct 719 ms 63352 KB Output is correct
60 Correct 712 ms 62968 KB Output is correct
61 Correct 1061 ms 63868 KB Output is correct
62 Correct 236 ms 2168 KB Output is correct
63 Correct 246 ms 2168 KB Output is correct
64 Correct 236 ms 2168 KB Output is correct
65 Correct 246 ms 2168 KB Output is correct
66 Correct 248 ms 2168 KB Output is correct
67 Correct 240 ms 2168 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 1105 ms 63608 KB Output is correct
72 Correct 1058 ms 64248 KB Output is correct
73 Correct 1068 ms 63608 KB Output is correct
74 Correct 1056 ms 63620 KB Output is correct
75 Correct 1008 ms 64044 KB Output is correct
76 Correct 1099 ms 64376 KB Output is correct
77 Correct 1095 ms 64248 KB Output is correct
78 Correct 1111 ms 64296 KB Output is correct
79 Correct 1033 ms 64248 KB Output is correct
80 Correct 1069 ms 64292 KB Output is correct
81 Correct 1038 ms 64248 KB Output is correct
82 Correct 1124 ms 64352 KB Output is correct
83 Correct 224 ms 1528 KB Output is correct
84 Correct 220 ms 1400 KB Output is correct
85 Correct 216 ms 1396 KB Output is correct
86 Correct 227 ms 1528 KB Output is correct
87 Correct 237 ms 1400 KB Output is correct
88 Correct 221 ms 1400 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 1156 ms 61432 KB Output is correct
93 Correct 1091 ms 61304 KB Output is correct
94 Correct 1166 ms 61560 KB Output is correct
95 Correct 1142 ms 61408 KB Output is correct
96 Correct 1077 ms 61560 KB Output is correct
97 Correct 1170 ms 61632 KB Output is correct
98 Correct 1054 ms 61560 KB Output is correct
99 Correct 1156 ms 61304 KB Output is correct
100 Correct 1214 ms 61560 KB Output is correct
101 Correct 1209 ms 61728 KB Output is correct
102 Correct 1304 ms 61560 KB Output is correct
103 Correct 1142 ms 61688 KB Output is correct
104 Correct 1136 ms 61432 KB Output is correct
105 Correct 1117 ms 61644 KB Output is correct
106 Correct 1369 ms 62072 KB Output is correct
107 Correct 304 ms 1424 KB Output is correct
108 Correct 299 ms 1440 KB Output is correct
109 Correct 300 ms 1272 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 1205 ms 61608 KB Output is correct
114 Correct 1184 ms 61608 KB Output is correct
115 Correct 1203 ms 61852 KB Output is correct
116 Correct 1102 ms 61392 KB Output is correct
117 Correct 1458 ms 61976 KB Output is correct
118 Correct 1119 ms 61432 KB Output is correct
119 Correct 1105 ms 61712 KB Output is correct
120 Correct 795 ms 62328 KB Output is correct
121 Correct 855 ms 62456 KB Output is correct
122 Correct 824 ms 62292 KB Output is correct
123 Correct 735 ms 61432 KB Output is correct
124 Correct 740 ms 61308 KB Output is correct
125 Correct 755 ms 61436 KB Output is correct
126 Correct 1367 ms 61448 KB Output is correct
127 Correct 1383 ms 61340 KB Output is correct
128 Correct 1382 ms 61952 KB Output is correct
129 Correct 1382 ms 61324 KB Output is correct
130 Correct 1153 ms 61944 KB Output is correct
131 Correct 1189 ms 61944 KB Output is correct
132 Correct 1151 ms 62072 KB Output is correct
133 Correct 1443 ms 61516 KB Output is correct
134 Correct 1389 ms 61604 KB Output is correct
135 Correct 1374 ms 61692 KB Output is correct
136 Correct 302 ms 888 KB Output is correct
137 Correct 308 ms 888 KB Output is correct
138 Correct 316 ms 888 KB Output is correct