Submission #426322

# Submission time Handle Problem Language Result Execution time Memory
426322 2021-06-13T17:49:47 Z TLP39 Progression (NOI20_progression) C++14
100 / 100
1869 ms 109212 KB
#include <stdio.h>
#include <math.h>
#include <utility>
#include <string.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
struct dev{
    bool typ;
    ll s,c;
};

struct play{
    ll l,r,len,cl,dl,cr,dr,c;
};

dev rep(dev x,dev y)
{
    if(y.typ) return y;
    return {x.typ,x.s+y.s,x.c+y.c};
}

play mix(play x,play y)
{
    play ans={x.l,y.r,x.len+y.len,x.cl,x.dl,y.cr,y.dr,max(x.c,y.c)};
    if(x.cl==x.len)
    {
        if(x.len==1)
        {
            ans.dl=y.l-x.r;
            if(y.cl==1) ans.cl=2;
            else
            {
                if(y.dl==y.l-x.r) ans.cl=y.cl+1;
                else ans.cl=2;
            }
        }
        else
        {
            if(y.l-x.r!=x.dl) ans.cl=x.cl;
            else
            {
                if(y.dl==x.dl) ans.cl=x.cl+y.cl;
                else ans.cl=x.cl+1;
            }
        }
    }

    if(y.cr==y.len)
    {
        if(y.len==1)
        {
            ans.dr=y.l-x.r;
            if(x.cr==1) ans.cr=2;
            else
            {
                if(x.dr==y.l-x.r) ans.cr=x.cr+1;
                else ans.cr=2;
            }
        }
        else
        {
            if(y.l-x.r!=y.dr) ans.cr=y.cr;
            else
            {
                if(x.dr==y.dr) ans.cr=x.cr+y.cr;
                else ans.cr=y.cr+1;
            }
        }
    }

    if(y.l-x.r==x.dr)
    {
        if(y.l-x.r==y.dl)
        {
            ans.c=max(ans.c,x.cr+y.cl);
        }
        else
        {
            ans.c=max(ans.c,x.cr+1);
        }
    }
    else
    {
        if(y.l-x.r==y.dl)
        {
            ans.c=max(ans.c,1+y.cl);
        }
        else
        {
            ans.c=max(ans.c,2ll);
        }
    }

    return ans;
}

play mod(play x,dev y,ll l,ll r)
{
    play ans=x;
    if(y.typ)
    {
        ans.l=y.s+(l-1)*y.c;
        ans.r=y.s+(r-1)*y.c;
        ans.cl=ans.len;
        ans.cr=ans.len;
        ans.c=ans.len;
        ans.dl=ans.dr=y.c;
        return ans;
    }
    ans.l+=(y.s+(l-1)*y.c);
    ans.r+=(y.s+(r-1)*y.c);
    ans.dl+=y.c;
    ans.dr+=y.c;
    return ans;
}

ll n,q;
ll a[300010];
play seg[1200040];
dev lz[1200040];
bool marked[1200040],bottom[1200040];

void build(ll v,ll st,ll ed)
{
    if(st==ed)
    {
        seg[v]={a[st],a[st],1,1,0,1,0,1};
        bottom[v]=true;
        return;
    }
    ll mid=(st+ed)>>1;
    build(2*v,st,mid);
    build(2*v+1,mid+1,ed);
    seg[v]=mix(seg[2*v],seg[2*v+1]);
}

void push_down(ll v,ll l,ll r)
{
    if(!marked[v] || bottom[v]) return;
    marked[v]=false;
    marked[2*v]=marked[2*v+1]=true;
    ll mid=(l+r)>>1;
    seg[2*v]=mod(seg[2*v],lz[v],l,mid);
    lz[2*v]=rep(lz[2*v],lz[v]);
    seg[2*v+1]=mod(seg[2*v+1],lz[v],mid+1,r);
    lz[2*v+1]=rep(lz[2*v+1],lz[v]);
    lz[v]={false,0,0};
}

void upd(ll v,ll st,ll ed,ll l,ll r,dev x)
{
    if(st>ed) return;
    if(st==l && ed==r)
    {
        marked[v]=true;
        seg[v]=mod(seg[v],x,l,r);
        lz[v]=rep(lz[v],x);
        return;
    }
    push_down(v,l,r);
    ll mid=(l+r)>>1;
    upd(2*v,st,min(mid,ed),l,mid,x);
    upd(2*v+1,max(mid+1,st),ed,mid+1,r,x);
    seg[v]=mix(seg[2*v],seg[2*v+1]);
}

play que(ll v,ll st,ll ed,ll l,ll r)
{
    if(l==st && r==ed) return seg[v];
    push_down(v,l,r);
    ll mid=(l+r)>>1;
    if(ed<=mid) return que(2*v,st,ed,l,mid);
    if(st>mid) return que(2*v+1,st,ed,mid+1,r);
    return mix(que(2*v,st,mid,l,mid),que(2*v+1,mid+1,ed,mid+1,r));
}

int main()
{
    scanf("%lld %lld",&n,&q);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(ll i=0;i<1200040;i++)
    {
        marked[i]=false;
        bottom[i]=false;
        lz[i]={false,0,0};
    }
    build(1,1,n);
    ll ty,l,r;
    ll s,c;
    dev temp;
    while(q--)
    {
        scanf("%lld",&ty);
        if(ty==1)
        {
            scanf("%lld %lld %lld %lld",&l,&r,&s,&c);
            temp={false,s+(1-l)*c,c};
            upd(1,l,r,1,n,temp);
        }
        else if(ty==2)
        {
            scanf("%lld %lld %lld %lld",&l,&r,&s,&c);
            temp={true,s+(1-l)*c,c};
            upd(1,l,r,1,n,temp);
        }
        else
        {
            scanf("%lld %lld",&l,&r);
            printf("%lld\n",(que(1,l,r,1,n)).c);
        }
    }
}

Compilation message

Progression.cpp: In function 'int main()':
Progression.cpp:184:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  184 |     scanf("%lld %lld",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
Progression.cpp:185:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  185 |     for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
      |                          ~~~~~^~~~~~~~~~~~~~
Progression.cpp:198:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  198 |         scanf("%lld",&ty);
      |         ~~~~~^~~~~~~~~~~~
Progression.cpp:201:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  201 |             scanf("%lld %lld %lld %lld",&l,&r,&s,&c);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:207:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  207 |             scanf("%lld %lld %lld %lld",&l,&r,&s,&c);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:213:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  213 |             scanf("%lld %lld",&l,&r);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 324 ms 99456 KB Output is correct
2 Correct 162 ms 31128 KB Output is correct
3 Correct 161 ms 31080 KB Output is correct
4 Correct 173 ms 31008 KB Output is correct
5 Correct 160 ms 31152 KB Output is correct
6 Correct 187 ms 31188 KB Output is correct
7 Correct 158 ms 31060 KB Output is correct
8 Correct 20 ms 30756 KB Output is correct
9 Correct 20 ms 30740 KB Output is correct
10 Correct 18 ms 30796 KB Output is correct
11 Correct 247 ms 99452 KB Output is correct
12 Correct 250 ms 99424 KB Output is correct
13 Correct 254 ms 99660 KB Output is correct
14 Correct 252 ms 99600 KB Output is correct
15 Correct 254 ms 99652 KB Output is correct
16 Correct 252 ms 99396 KB Output is correct
17 Correct 257 ms 99348 KB Output is correct
18 Correct 256 ms 99396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 30924 KB Output is correct
2 Correct 18 ms 30804 KB Output is correct
3 Correct 19 ms 30736 KB Output is correct
4 Correct 20 ms 30796 KB Output is correct
5 Correct 21 ms 30772 KB Output is correct
6 Correct 20 ms 30736 KB Output is correct
7 Correct 18 ms 30824 KB Output is correct
8 Correct 20 ms 30928 KB Output is correct
9 Correct 20 ms 31048 KB Output is correct
10 Correct 19 ms 30904 KB Output is correct
11 Correct 19 ms 30924 KB Output is correct
12 Correct 20 ms 30988 KB Output is correct
13 Correct 19 ms 30904 KB Output is correct
14 Correct 19 ms 30924 KB Output is correct
15 Correct 19 ms 30936 KB Output is correct
16 Correct 19 ms 30992 KB Output is correct
17 Correct 22 ms 30996 KB Output is correct
18 Correct 19 ms 30996 KB Output is correct
19 Correct 19 ms 30796 KB Output is correct
20 Correct 20 ms 30796 KB Output is correct
21 Correct 22 ms 30820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 363 ms 99832 KB Output is correct
2 Correct 147 ms 31400 KB Output is correct
3 Correct 144 ms 31372 KB Output is correct
4 Correct 143 ms 31300 KB Output is correct
5 Correct 148 ms 31476 KB Output is correct
6 Correct 156 ms 31556 KB Output is correct
7 Correct 144 ms 31492 KB Output is correct
8 Correct 19 ms 30796 KB Output is correct
9 Correct 20 ms 30796 KB Output is correct
10 Correct 20 ms 30784 KB Output is correct
11 Correct 450 ms 99628 KB Output is correct
12 Correct 379 ms 99908 KB Output is correct
13 Correct 448 ms 99664 KB Output is correct
14 Correct 427 ms 99612 KB Output is correct
15 Correct 379 ms 99776 KB Output is correct
16 Correct 454 ms 100164 KB Output is correct
17 Correct 431 ms 100216 KB Output is correct
18 Correct 472 ms 100292 KB Output is correct
19 Correct 359 ms 99412 KB Output is correct
20 Correct 364 ms 99440 KB Output is correct
21 Correct 372 ms 99524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 759 ms 99108 KB Output is correct
2 Correct 197 ms 30972 KB Output is correct
3 Correct 200 ms 30964 KB Output is correct
4 Correct 195 ms 30916 KB Output is correct
5 Correct 207 ms 30956 KB Output is correct
6 Correct 211 ms 30964 KB Output is correct
7 Correct 202 ms 31148 KB Output is correct
8 Correct 19 ms 30796 KB Output is correct
9 Correct 18 ms 30760 KB Output is correct
10 Correct 18 ms 30796 KB Output is correct
11 Correct 764 ms 99220 KB Output is correct
12 Correct 777 ms 99176 KB Output is correct
13 Correct 830 ms 99120 KB Output is correct
14 Correct 747 ms 99208 KB Output is correct
15 Correct 705 ms 99048 KB Output is correct
16 Correct 784 ms 99212 KB Output is correct
17 Correct 805 ms 99224 KB Output is correct
18 Correct 827 ms 99192 KB Output is correct
19 Correct 784 ms 99056 KB Output is correct
20 Correct 789 ms 99236 KB Output is correct
21 Correct 751 ms 99196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 363 ms 99832 KB Output is correct
2 Correct 147 ms 31400 KB Output is correct
3 Correct 144 ms 31372 KB Output is correct
4 Correct 143 ms 31300 KB Output is correct
5 Correct 148 ms 31476 KB Output is correct
6 Correct 156 ms 31556 KB Output is correct
7 Correct 144 ms 31492 KB Output is correct
8 Correct 19 ms 30796 KB Output is correct
9 Correct 20 ms 30796 KB Output is correct
10 Correct 20 ms 30784 KB Output is correct
11 Correct 450 ms 99628 KB Output is correct
12 Correct 379 ms 99908 KB Output is correct
13 Correct 448 ms 99664 KB Output is correct
14 Correct 427 ms 99612 KB Output is correct
15 Correct 379 ms 99776 KB Output is correct
16 Correct 454 ms 100164 KB Output is correct
17 Correct 431 ms 100216 KB Output is correct
18 Correct 472 ms 100292 KB Output is correct
19 Correct 359 ms 99412 KB Output is correct
20 Correct 364 ms 99440 KB Output is correct
21 Correct 372 ms 99524 KB Output is correct
22 Correct 1708 ms 99200 KB Output is correct
23 Correct 233 ms 34108 KB Output is correct
24 Correct 223 ms 34148 KB Output is correct
25 Correct 228 ms 33968 KB Output is correct
26 Correct 232 ms 34024 KB Output is correct
27 Correct 227 ms 33988 KB Output is correct
28 Correct 229 ms 34052 KB Output is correct
29 Correct 23 ms 30796 KB Output is correct
30 Correct 20 ms 30792 KB Output is correct
31 Correct 18 ms 30756 KB Output is correct
32 Correct 1736 ms 105256 KB Output is correct
33 Correct 1620 ms 108204 KB Output is correct
34 Correct 1720 ms 105340 KB Output is correct
35 Correct 1708 ms 105364 KB Output is correct
36 Correct 1323 ms 105156 KB Output is correct
37 Correct 1429 ms 105268 KB Output is correct
38 Correct 1456 ms 105288 KB Output is correct
39 Correct 1637 ms 108068 KB Output is correct
40 Correct 1799 ms 108464 KB Output is correct
41 Correct 1686 ms 108168 KB Output is correct
42 Correct 1775 ms 108212 KB Output is correct
43 Correct 1650 ms 108112 KB Output is correct
44 Correct 1635 ms 108160 KB Output is correct
45 Correct 1708 ms 108048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 324 ms 99456 KB Output is correct
2 Correct 162 ms 31128 KB Output is correct
3 Correct 161 ms 31080 KB Output is correct
4 Correct 173 ms 31008 KB Output is correct
5 Correct 160 ms 31152 KB Output is correct
6 Correct 187 ms 31188 KB Output is correct
7 Correct 158 ms 31060 KB Output is correct
8 Correct 20 ms 30756 KB Output is correct
9 Correct 20 ms 30740 KB Output is correct
10 Correct 18 ms 30796 KB Output is correct
11 Correct 247 ms 99452 KB Output is correct
12 Correct 250 ms 99424 KB Output is correct
13 Correct 254 ms 99660 KB Output is correct
14 Correct 252 ms 99600 KB Output is correct
15 Correct 254 ms 99652 KB Output is correct
16 Correct 252 ms 99396 KB Output is correct
17 Correct 257 ms 99348 KB Output is correct
18 Correct 256 ms 99396 KB Output is correct
19 Correct 20 ms 30924 KB Output is correct
20 Correct 18 ms 30804 KB Output is correct
21 Correct 19 ms 30736 KB Output is correct
22 Correct 20 ms 30796 KB Output is correct
23 Correct 21 ms 30772 KB Output is correct
24 Correct 20 ms 30736 KB Output is correct
25 Correct 18 ms 30824 KB Output is correct
26 Correct 20 ms 30928 KB Output is correct
27 Correct 20 ms 31048 KB Output is correct
28 Correct 19 ms 30904 KB Output is correct
29 Correct 19 ms 30924 KB Output is correct
30 Correct 20 ms 30988 KB Output is correct
31 Correct 19 ms 30904 KB Output is correct
32 Correct 19 ms 30924 KB Output is correct
33 Correct 19 ms 30936 KB Output is correct
34 Correct 19 ms 30992 KB Output is correct
35 Correct 22 ms 30996 KB Output is correct
36 Correct 19 ms 30996 KB Output is correct
37 Correct 19 ms 30796 KB Output is correct
38 Correct 20 ms 30796 KB Output is correct
39 Correct 22 ms 30820 KB Output is correct
40 Correct 363 ms 99832 KB Output is correct
41 Correct 147 ms 31400 KB Output is correct
42 Correct 144 ms 31372 KB Output is correct
43 Correct 143 ms 31300 KB Output is correct
44 Correct 148 ms 31476 KB Output is correct
45 Correct 156 ms 31556 KB Output is correct
46 Correct 144 ms 31492 KB Output is correct
47 Correct 19 ms 30796 KB Output is correct
48 Correct 20 ms 30796 KB Output is correct
49 Correct 20 ms 30784 KB Output is correct
50 Correct 450 ms 99628 KB Output is correct
51 Correct 379 ms 99908 KB Output is correct
52 Correct 448 ms 99664 KB Output is correct
53 Correct 427 ms 99612 KB Output is correct
54 Correct 379 ms 99776 KB Output is correct
55 Correct 454 ms 100164 KB Output is correct
56 Correct 431 ms 100216 KB Output is correct
57 Correct 472 ms 100292 KB Output is correct
58 Correct 359 ms 99412 KB Output is correct
59 Correct 364 ms 99440 KB Output is correct
60 Correct 372 ms 99524 KB Output is correct
61 Correct 759 ms 99108 KB Output is correct
62 Correct 197 ms 30972 KB Output is correct
63 Correct 200 ms 30964 KB Output is correct
64 Correct 195 ms 30916 KB Output is correct
65 Correct 207 ms 30956 KB Output is correct
66 Correct 211 ms 30964 KB Output is correct
67 Correct 202 ms 31148 KB Output is correct
68 Correct 19 ms 30796 KB Output is correct
69 Correct 18 ms 30760 KB Output is correct
70 Correct 18 ms 30796 KB Output is correct
71 Correct 764 ms 99220 KB Output is correct
72 Correct 777 ms 99176 KB Output is correct
73 Correct 830 ms 99120 KB Output is correct
74 Correct 747 ms 99208 KB Output is correct
75 Correct 705 ms 99048 KB Output is correct
76 Correct 784 ms 99212 KB Output is correct
77 Correct 805 ms 99224 KB Output is correct
78 Correct 827 ms 99192 KB Output is correct
79 Correct 784 ms 99056 KB Output is correct
80 Correct 789 ms 99236 KB Output is correct
81 Correct 751 ms 99196 KB Output is correct
82 Correct 1708 ms 99200 KB Output is correct
83 Correct 233 ms 34108 KB Output is correct
84 Correct 223 ms 34148 KB Output is correct
85 Correct 228 ms 33968 KB Output is correct
86 Correct 232 ms 34024 KB Output is correct
87 Correct 227 ms 33988 KB Output is correct
88 Correct 229 ms 34052 KB Output is correct
89 Correct 23 ms 30796 KB Output is correct
90 Correct 20 ms 30792 KB Output is correct
91 Correct 18 ms 30756 KB Output is correct
92 Correct 1736 ms 105256 KB Output is correct
93 Correct 1620 ms 108204 KB Output is correct
94 Correct 1720 ms 105340 KB Output is correct
95 Correct 1708 ms 105364 KB Output is correct
96 Correct 1323 ms 105156 KB Output is correct
97 Correct 1429 ms 105268 KB Output is correct
98 Correct 1456 ms 105288 KB Output is correct
99 Correct 1637 ms 108068 KB Output is correct
100 Correct 1799 ms 108464 KB Output is correct
101 Correct 1686 ms 108168 KB Output is correct
102 Correct 1775 ms 108212 KB Output is correct
103 Correct 1650 ms 108112 KB Output is correct
104 Correct 1635 ms 108160 KB Output is correct
105 Correct 1708 ms 108048 KB Output is correct
106 Correct 1776 ms 109180 KB Output is correct
107 Correct 254 ms 34296 KB Output is correct
108 Correct 274 ms 34236 KB Output is correct
109 Correct 256 ms 34244 KB Output is correct
110 Correct 18 ms 30836 KB Output is correct
111 Correct 18 ms 30820 KB Output is correct
112 Correct 19 ms 30812 KB Output is correct
113 Correct 1727 ms 108104 KB Output is correct
114 Correct 1773 ms 108188 KB Output is correct
115 Correct 1727 ms 108200 KB Output is correct
116 Correct 1667 ms 108160 KB Output is correct
117 Correct 1758 ms 108968 KB Output is correct
118 Correct 1678 ms 108216 KB Output is correct
119 Correct 1797 ms 108052 KB Output is correct
120 Correct 524 ms 106752 KB Output is correct
121 Correct 458 ms 106564 KB Output is correct
122 Correct 450 ms 106676 KB Output is correct
123 Correct 361 ms 105860 KB Output is correct
124 Correct 375 ms 105796 KB Output is correct
125 Correct 358 ms 105848 KB Output is correct
126 Correct 1828 ms 105792 KB Output is correct
127 Correct 1789 ms 105744 KB Output is correct
128 Correct 1869 ms 109160 KB Output is correct
129 Correct 1815 ms 105816 KB Output is correct
130 Correct 1456 ms 105840 KB Output is correct
131 Correct 1498 ms 105828 KB Output is correct
132 Correct 1410 ms 105776 KB Output is correct
133 Correct 1841 ms 109168 KB Output is correct
134 Correct 1827 ms 109124 KB Output is correct
135 Correct 1817 ms 109212 KB Output is correct
136 Correct 257 ms 34148 KB Output is correct
137 Correct 252 ms 34232 KB Output is correct
138 Correct 261 ms 34184 KB Output is correct