Submission #465033

# Submission time Handle Problem Language Result Execution time Memory
465033 2021-08-14T21:33:41 Z Deepesson Snowball (JOI21_ho_t2) C++17
100 / 100
315 ms 14016 KB
#include <bits/stdc++.h>
///Bola de neve
#define MAX 2000005
long long valores[MAX][2];
bool dir[MAX];
int main()
{
    int N,Q;
    std::cin>>N>>Q;
    long long array[N];for(auto&x:array)std::cin>>x;
    for(auto&x:array) x += 1LL<<30LL;
    long long left=0,right=0,pos=0;
    for(int i=0;i!=Q;++i){
        long long D;
        std::cin>>D;
        pos+=D;
        if(pos<0){
            long long val = pos;
            if(val<0)val*=-1;
            left=std::max(left,val);
            dir[i]=true;
        }else {
            long long val = pos;
            if(val<0)val*=-1;
            right=std::max(right,val);
        }
        valores[i][0]=left;
        valores[i][1]=right;
    }
    long long resultados[N]={};
    resultados[0]+=left;
    resultados[N-1]+=right;
    for(int i=1;i!=N;++i){
        ///i-1 eh esquerda, se referindo a direita
        ///i eh a direita, e ira para a esquerda
        /// i-1 -> Direita     Esquerda <- i
        long long obj = array[i]-array[i-1];
        if(valores[Q-1][0]+valores[Q-1][1]>obj){
            int l=0,r=Q-1;
            while(l<r){
                int m = (l+r)/2;
                long long val = valores[m][0]+valores[m][1];
                if(val>=obj){
                    r=m;
                }else l=m+1;
            }

            long long a = valores[l][0]; ///Esquerda
            long long b = valores[l][1]; ///Direita
            if(a+b==obj){
                resultados[i-1]+=b;
                resultados[i]+=a;
            }else {
                long long dif = (a+b)-(obj);
                if(dir[l]){///Para a esquerda
                    a-=dif;
                }else {///Para a direita
                    b-=dif;
                }
                resultados[i-1]+=b;
                resultados[i]+=a;
            }

        }else {
            resultados[i-1]+=right;
            resultados[i]+=left;
        }
    }
    for(auto&x:resultados)std::cout<<x<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 316 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 316 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 316 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 3 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 316 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 96 ms 5664 KB Output is correct
21 Correct 95 ms 5444 KB Output is correct
22 Correct 84 ms 5360 KB Output is correct
23 Correct 80 ms 5232 KB Output is correct
24 Correct 90 ms 5648 KB Output is correct
25 Correct 236 ms 12000 KB Output is correct
26 Correct 237 ms 11948 KB Output is correct
27 Correct 227 ms 11620 KB Output is correct
28 Correct 315 ms 11772 KB Output is correct
29 Correct 218 ms 11292 KB Output is correct
30 Correct 206 ms 10656 KB Output is correct
31 Correct 187 ms 10028 KB Output is correct
32 Correct 167 ms 10200 KB Output is correct
33 Correct 24 ms 1448 KB Output is correct
34 Correct 247 ms 12296 KB Output is correct
35 Correct 233 ms 11696 KB Output is correct
36 Correct 233 ms 12072 KB Output is correct
37 Correct 230 ms 11716 KB Output is correct
38 Correct 225 ms 11540 KB Output is correct
39 Correct 263 ms 11820 KB Output is correct
40 Correct 208 ms 11804 KB Output is correct
41 Correct 125 ms 6156 KB Output is correct
42 Correct 166 ms 10052 KB Output is correct
43 Correct 245 ms 13476 KB Output is correct
44 Correct 114 ms 6208 KB Output is correct
45 Correct 190 ms 11804 KB Output is correct
46 Correct 245 ms 13616 KB Output is correct
47 Correct 256 ms 13872 KB Output is correct
48 Correct 254 ms 14016 KB Output is correct