답안 #387039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387039 2021-04-07T20:17:29 Z lukameladze Snowball (JOI21_ho_t2) C++14
100 / 100
730 ms 18796 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=0;
          ri=q;            
       anss=0;
          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=0;
          ri=q;
       anss=0;
          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;
     }
     
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 8 ms 492 KB Output is correct
5 Correct 8 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 7 ms 492 KB Output is correct
11 Correct 7 ms 620 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 8 ms 620 KB Output is correct
16 Correct 8 ms 620 KB Output is correct
17 Correct 8 ms 512 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 7 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 8 ms 492 KB Output is correct
5 Correct 8 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 7 ms 492 KB Output is correct
11 Correct 7 ms 620 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 8 ms 620 KB Output is correct
16 Correct 8 ms 620 KB Output is correct
17 Correct 8 ms 512 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 7 ms 492 KB Output is correct
20 Correct 95 ms 8812 KB Output is correct
21 Correct 86 ms 8556 KB Output is correct
22 Correct 82 ms 8428 KB Output is correct
23 Correct 80 ms 8300 KB Output is correct
24 Correct 139 ms 8940 KB Output is correct
25 Correct 697 ms 16876 KB Output is correct
26 Correct 689 ms 16748 KB Output is correct
27 Correct 684 ms 16364 KB Output is correct
28 Correct 698 ms 16492 KB Output is correct
29 Correct 683 ms 15980 KB Output is correct
30 Correct 658 ms 15348 KB Output is correct
31 Correct 595 ms 14956 KB Output is correct
32 Correct 590 ms 14956 KB Output is correct
33 Correct 83 ms 2028 KB Output is correct
34 Correct 704 ms 17260 KB Output is correct
35 Correct 714 ms 16620 KB Output is correct
36 Correct 705 ms 16808 KB Output is correct
37 Correct 680 ms 16492 KB Output is correct
38 Correct 730 ms 16364 KB Output is correct
39 Correct 682 ms 16620 KB Output is correct
40 Correct 628 ms 16476 KB Output is correct
41 Correct 114 ms 9452 KB Output is correct
42 Correct 617 ms 14956 KB Output is correct
43 Correct 668 ms 18284 KB Output is correct
44 Correct 113 ms 9324 KB Output is correct
45 Correct 607 ms 16364 KB Output is correct
46 Correct 669 ms 18540 KB Output is correct
47 Correct 673 ms 18540 KB Output is correct
48 Correct 671 ms 18796 KB Output is correct