Submission #387035

# Submission time Handle Problem Language Result Execution time Memory
387035 2021-04-07T20:13:03 Z lukameladze Snowball (JOI21_ho_t2) C++14
0 / 100
9 ms 640 KB
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N=1e6+5;
long long n,q,qq[N],a[N],prmx[N],pr[N],prmn[N],x1,x2,le,ri,anss,rii[N],lef[N],mid,x;
int main() {
     cin>>n>>q;
     for (int i=1; i<=n; i++) {
          cin>>a[i];
     }
     for (int i=1; i<=q; i++) {
          cin>>qq[i];
          pr[i]=pr[i-1]+qq[i];
          prmx[i]=max(prmx[i-1],pr[i]);
          prmn[i]=min(prmn[i-1],pr[i]);
     }
     for(int i=2; i<=n; i++) {
          x1=a[i-1];
          x2=a[i];
          le=1;
          ri=q;
          while (le<=ri) {
               mid=(le+ri)/2;
               if (x1+prmx[mid]<=x2+prmn[mid]) {
                    anss=mid;
                    
                    //m1=x1+prmx[mid];
                    //m2=x2+prmn[mid];
                    le=mid+1;
               }
               else ri=mid-1;
          }
          if (prmn[anss+1]<prmn[anss]) {
               lef[i]=x1+prmx[anss];
          } else {
                  lef[i]=x2+prmn[anss];
           }
          //if(i==4) cout<<anss<<endl<<endl;
          lef[i]=min(a[i],lef[i]);
     }
     for (int i=1; i<n; i++) {
          x1=a[i];
          x2=a[i+1];
          le=1;
          ri=q;
          while (le<=ri) {
               mid=(le+ri)/2;
               if (x1+prmx[mid]<=x2+prmn[mid]) {
                    anss=mid;
                    //rii[i]=x2+prmn[mid];
                    le=mid+1;
               }
               else ri=mid-1;
          }
          if (prmx[anss+1]>prmx[anss]) {
               rii[i]=x2+prmn[anss];
          }
          else rii[i]=x1+prmx[anss];
          rii[i]=max(a[i],rii[i]);
     }
     lef[1]=min(a[1], a[1]+prmn[q]);
     rii[n]=max(a[n], a[n]+prmx[q]);
     for (int i=1; i<=n; i++) {
         // cout<<rii[i]<<" "<<lef[i]<<endl;
          cout<<rii[i]-lef[i]<<endl;
     }
     
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 9 ms 620 KB Output is correct
5 Correct 9 ms 492 KB Output is correct
6 Correct 7 ms 492 KB Output is correct
7 Correct 8 ms 492 KB Output is correct
8 Correct 7 ms 492 KB Output is correct
9 Correct 7 ms 492 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Correct 8 ms 620 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Incorrect 2 ms 364 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
4 Correct 9 ms 620 KB Output is correct
5 Correct 9 ms 492 KB Output is correct
6 Correct 7 ms 492 KB Output is correct
7 Correct 8 ms 492 KB Output is correct
8 Correct 7 ms 492 KB Output is correct
9 Correct 7 ms 492 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Correct 8 ms 620 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Incorrect 2 ms 364 KB Output isn't correct
15 Halted 0 ms 0 KB -