Submission #650210

# Submission time Handle Problem Language Result Execution time Memory
650210 2022-10-12T22:57:36 Z milisav Snowball (JOI21_ho_t2) C++14
100 / 100
101 ms 13500 KB
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
int n,q;
long long x[maxn];
long long w[maxn];
long long a[maxn];
long long cnt[maxn];
bool sg(long long u,long long v) {
    if(u<=0 && v<=0) return true;
    if(u>=0 && v>=0) return true;
    return false;
}
int main() {
    scanf("%d %d",&n,&q);
    for(int i=0;i<n;i++) {
        scanf("%lld",&x[i]);
    }
    for(int i=0;i<q;i++) {
        scanf("%lld",&w[i]);
    }
    long long mi=0,ma=0;
    long long pos=w[0];
    a[0]=0;
    a[1]=pos;
    mi=min(mi,pos);
    ma=max(ma,pos);
    int m=2;

    for(int i=1;i<q;i++) {
        pos+=w[i];
        mi=min(mi,pos);
        ma=max(ma,pos);
        //cout<<i<<" "<<pos<<" "<<a[m-1]<<endl;
        if(sg(pos,a[m-1])) {
            if(abs(pos)>abs(a[m-1])) {
                a[m-1]=pos;
            }
        }
        else {
            //cout<<a[m-2]<<endl;
            if(abs(pos)>abs(a[m-2])) {
                //cout<<"inc"<<endl;
                a[m]=pos;
                m++;
            }
        }
    }
    //for(int i=0;i<m;i++) cout<<a[i]<<" ";
    //cout<<endl;

    cnt[0]-=mi;
    cnt[n-1]+=ma;
    for(int i=1;i<n;i++) {
        long long len=x[i]-x[i-1];
        int l=1;
        int r=m-1;
        if(abs(a[r])+abs(a[r-1])<len) {
            if(a[r]<=0) {
                cnt[i]-=a[r];
                cnt[i-1]+=a[r-1];
            }
            else {
                cnt[i-1]+=a[r];
                cnt[i]-=a[r-1];
            }
            continue;
        }
        while(l<r) {
            int md=(l+r)/2;
            if(abs(a[md])+abs(a[md-1])<len) l=md+1;
            else r=md;
        }
        //cout<<i<<" "<<x[i]<<" "<<x[i-1]<<" "<<l<<" "<<a[l]<<" "<<a[l-1]<<" "<<len<<endl;
        if(a[l]>=0) {
            cnt[i]-=a[l-1];
            cnt[i-1]+=(len+a[l-1]);
        }
        else {
            cnt[i-1]+=a[l-1];
            cnt[i]+=(len-a[l-1]);
        }
    }

    for(int i=0;i<n;i++) {
        printf("%lld\n",cnt[i]);
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d %d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%lld",&x[i]);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%lld",&w[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 28 ms 4748 KB Output is correct
21 Correct 27 ms 4488 KB Output is correct
22 Correct 26 ms 4280 KB Output is correct
23 Correct 29 ms 4172 KB Output is correct
24 Correct 33 ms 4652 KB Output is correct
25 Correct 93 ms 11052 KB Output is correct
26 Correct 93 ms 11008 KB Output is correct
27 Correct 90 ms 10616 KB Output is correct
28 Correct 94 ms 10684 KB Output is correct
29 Correct 90 ms 9804 KB Output is correct
30 Correct 72 ms 8940 KB Output is correct
31 Correct 58 ms 8268 KB Output is correct
32 Correct 73 ms 8492 KB Output is correct
33 Correct 10 ms 1380 KB Output is correct
34 Correct 83 ms 10644 KB Output is correct
35 Correct 84 ms 10096 KB Output is correct
36 Correct 94 ms 10976 KB Output is correct
37 Correct 101 ms 10588 KB Output is correct
38 Correct 93 ms 10572 KB Output is correct
39 Correct 93 ms 10716 KB Output is correct
40 Correct 76 ms 10692 KB Output is correct
41 Correct 32 ms 4556 KB Output is correct
42 Correct 81 ms 8508 KB Output is correct
43 Correct 73 ms 13312 KB Output is correct
44 Correct 28 ms 5952 KB Output is correct
45 Correct 62 ms 10756 KB Output is correct
46 Correct 81 ms 13500 KB Output is correct
47 Correct 78 ms 12088 KB Output is correct
48 Correct 74 ms 12164 KB Output is correct