Submission #543244

# Submission time Handle Problem Language Result Execution time Memory
543244 2022-03-29T23:58:11 Z Deepesson Hacker (BOI15_hac) C++17
100 / 100
390 ms 73776 KB
#include <bits/stdc++.h>
#define MAX 2100000
#define LSB(A) (A&(-A))
using ll = long long;
typedef std::pair<ll,ll> pll;
typedef std::pair<ll,pll> plp;
ll ft[MAX];
void update(int t,int k){t+=8;
    while(t<MAX){
        ft[t]+=k;
        t+=LSB(t);
    }
}
ll query(int t){t+=8;
    ll ans=0;
    while(t>0){
        ans+=ft[t];
        t-=LSB(t);
    }
    return ans;
}
ll seg(int l,int r){
    return query(r)-query(l-1);
}
ll array[MAX];
ll tab[MAX*4];
void update(int l,int r,ll k,int la=0,int ra=MAX-1,int pos=1){
    if(ra<l||la>r)return;
    if(l<=la&&ra<=r){
        tab[pos]=std::max(tab[pos],k);
        return;
    }
    int m = (la+ra)/2;
    update(l,r,k,la,m,pos*2);
    update(l,r,k,m+1,ra,(pos*2)+1);
}
ll querys(int t,int la=0,int ra=MAX-1,int pos=1){
    if(ra<t||la>t)return 0;
    if(la==ra){
        return tab[pos];
    }
    int m = (la+ra)/2;
    return std::max(tab[pos],std::max(querys(t,la,m,pos*2),querys(t,m+1,ra,(pos*2)+1)));
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    int N;
    std::cin>>N;
    long long soma=0;
    for(int i=0;i!=N;++i){
        std::cin>>array[i];
        soma+=array[i];
    }
    for(int i=0;i!=MAX;++i){
        array[i]=array[i%N];
    }
    for(int i=0;i!=MAX;++i){
        update(i,array[i]);
    }
    ll respostas[N]={};
    ll puxa=N/2;
    ll ans=0;
    ll left[N]={},right[N]={};
    std::vector<plp> vec;
    for(int i=0;i!=N;++i){
        respostas[i]=seg(i,i+puxa-1);
        int l = i,r=(i+puxa-1);
      ///  std::cout<<l<<" "<<r<<" "<<respostas[i]<<"\n";
        vec.push_back({respostas[i],{l,i+puxa-1}});
        if(r<N){///Ok
            if(r!=N-1){
                update(r+1,N-1,respostas[i]);
               /// std::cout<<r+1<<" "<<N-1<<" "<<respostas[i]<<"\n";
            }
            if(l){
               /// std::cout<<0<<" "<<l-1<<" "<<respostas[i]<<"\n";
                update(0,l-1,respostas[i]);
            }
        }else {
            ++r;--l;
            r%=N;
            if(r<l)std::swap(r,l);
            ///std::cout<<l<<" "<<r<<" "<<respostas[i]<<"!\n";
            update(l,r,respostas[i]);
        }
    }
    ll total[N]={};
    {
        for(int i=0;i!=N;++i){
            total[i]=querys(i);
           /// std::cout<<total[i]<<"\n";
        }
    }
    std::cout<<(soma-(*std::min_element(total,&total[N])))<<"\n";
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:65:8: warning: unused variable 'ans' [-Wunused-variable]
   65 |     ll ans=0;
      |        ^~~
hac.cpp:66:8: warning: unused variable 'left' [-Wunused-variable]
   66 |     ll left[N]={},right[N]={};
      |        ^~~~
hac.cpp:66:19: warning: unused variable 'right' [-Wunused-variable]
   66 |     ll left[N]={},right[N]={};
      |                   ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 71 ms 33100 KB Output is correct
2 Correct 74 ms 33104 KB Output is correct
3 Correct 76 ms 33100 KB Output is correct
4 Correct 76 ms 33156 KB Output is correct
5 Correct 73 ms 33136 KB Output is correct
6 Correct 75 ms 33236 KB Output is correct
7 Correct 69 ms 33264 KB Output is correct
8 Correct 70 ms 33240 KB Output is correct
9 Correct 75 ms 33228 KB Output is correct
10 Correct 76 ms 33204 KB Output is correct
11 Correct 74 ms 33172 KB Output is correct
12 Correct 70 ms 33220 KB Output is correct
13 Correct 78 ms 33196 KB Output is correct
14 Correct 78 ms 33156 KB Output is correct
15 Correct 71 ms 33172 KB Output is correct
16 Correct 70 ms 33272 KB Output is correct
17 Correct 69 ms 33188 KB Output is correct
18 Correct 72 ms 33344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 33100 KB Output is correct
2 Correct 74 ms 33104 KB Output is correct
3 Correct 76 ms 33100 KB Output is correct
4 Correct 76 ms 33156 KB Output is correct
5 Correct 73 ms 33136 KB Output is correct
6 Correct 75 ms 33236 KB Output is correct
7 Correct 69 ms 33264 KB Output is correct
8 Correct 70 ms 33240 KB Output is correct
9 Correct 75 ms 33228 KB Output is correct
10 Correct 76 ms 33204 KB Output is correct
11 Correct 74 ms 33172 KB Output is correct
12 Correct 70 ms 33220 KB Output is correct
13 Correct 78 ms 33196 KB Output is correct
14 Correct 78 ms 33156 KB Output is correct
15 Correct 71 ms 33172 KB Output is correct
16 Correct 70 ms 33272 KB Output is correct
17 Correct 69 ms 33188 KB Output is correct
18 Correct 72 ms 33344 KB Output is correct
19 Correct 75 ms 33212 KB Output is correct
20 Correct 92 ms 33236 KB Output is correct
21 Correct 71 ms 33228 KB Output is correct
22 Correct 70 ms 33464 KB Output is correct
23 Correct 75 ms 33712 KB Output is correct
24 Correct 80 ms 33516 KB Output is correct
25 Correct 73 ms 33732 KB Output is correct
26 Correct 72 ms 33712 KB Output is correct
27 Correct 70 ms 33216 KB Output is correct
28 Correct 73 ms 33216 KB Output is correct
29 Correct 75 ms 33136 KB Output is correct
30 Correct 74 ms 33768 KB Output is correct
31 Correct 73 ms 33712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 33188 KB Output is correct
2 Correct 71 ms 33232 KB Output is correct
3 Correct 74 ms 33736 KB Output is correct
4 Correct 115 ms 40004 KB Output is correct
5 Correct 189 ms 49324 KB Output is correct
6 Correct 205 ms 53336 KB Output is correct
7 Correct 236 ms 60344 KB Output is correct
8 Correct 359 ms 73504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 33100 KB Output is correct
2 Correct 74 ms 33104 KB Output is correct
3 Correct 76 ms 33100 KB Output is correct
4 Correct 76 ms 33156 KB Output is correct
5 Correct 73 ms 33136 KB Output is correct
6 Correct 75 ms 33236 KB Output is correct
7 Correct 69 ms 33264 KB Output is correct
8 Correct 70 ms 33240 KB Output is correct
9 Correct 75 ms 33228 KB Output is correct
10 Correct 76 ms 33204 KB Output is correct
11 Correct 74 ms 33172 KB Output is correct
12 Correct 70 ms 33220 KB Output is correct
13 Correct 78 ms 33196 KB Output is correct
14 Correct 78 ms 33156 KB Output is correct
15 Correct 71 ms 33172 KB Output is correct
16 Correct 70 ms 33272 KB Output is correct
17 Correct 69 ms 33188 KB Output is correct
18 Correct 72 ms 33344 KB Output is correct
19 Correct 75 ms 33212 KB Output is correct
20 Correct 92 ms 33236 KB Output is correct
21 Correct 71 ms 33228 KB Output is correct
22 Correct 70 ms 33464 KB Output is correct
23 Correct 75 ms 33712 KB Output is correct
24 Correct 80 ms 33516 KB Output is correct
25 Correct 73 ms 33732 KB Output is correct
26 Correct 72 ms 33712 KB Output is correct
27 Correct 70 ms 33216 KB Output is correct
28 Correct 73 ms 33216 KB Output is correct
29 Correct 75 ms 33136 KB Output is correct
30 Correct 74 ms 33768 KB Output is correct
31 Correct 73 ms 33712 KB Output is correct
32 Correct 71 ms 33188 KB Output is correct
33 Correct 71 ms 33232 KB Output is correct
34 Correct 74 ms 33736 KB Output is correct
35 Correct 115 ms 40004 KB Output is correct
36 Correct 189 ms 49324 KB Output is correct
37 Correct 205 ms 53336 KB Output is correct
38 Correct 236 ms 60344 KB Output is correct
39 Correct 359 ms 73504 KB Output is correct
40 Correct 77 ms 34188 KB Output is correct
41 Correct 94 ms 35096 KB Output is correct
42 Correct 96 ms 35824 KB Output is correct
43 Correct 172 ms 49424 KB Output is correct
44 Correct 334 ms 73424 KB Output is correct
45 Correct 123 ms 41412 KB Output is correct
46 Correct 240 ms 60316 KB Output is correct
47 Correct 364 ms 73568 KB Output is correct
48 Correct 390 ms 73776 KB Output is correct
49 Correct 341 ms 72788 KB Output is correct
50 Correct 364 ms 73068 KB Output is correct