Submission #421723

# Submission time Handle Problem Language Result Execution time Memory
421723 2021-06-09T11:22:58 Z juggernaut Snowball (JOI21_ho_t2) C++17
100 / 100
131 ms 14072 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
    #define printl(args...)printf(args)
#else
    #define printl(args...)((void)0)
#endif
int n,q;
ll a[200005];
ll l[200005];
ll r[200005];
ll ans[200005];
bool dir[200005];
int main(){
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
    ll cnt=0;
    for(int i=1;i<=q;i++){
        ll x;
        scanf("%lld",&x);
        cnt+=x;
        l[i]=min(l[i-1],cnt);
        r[i]=max(r[i-1],cnt);
        dir[i]=(x>0);
    }
    ans[1]-=l[q];
    ans[n]+=r[q];
    for(int i=1;i<n;i++){
        if(a[i]+r[q]<=a[i+1]+l[q]){
            ans[i]+=r[q];
            ans[i+1]-=l[q];
        }else{
            int l=1,r=q;
            while(l<r){
                int mid=(l+r)>>1;
                if(a[i]+::r[mid]>a[i+1]+::l[mid])r=mid;
                else l=mid+1;
            }
            if(dir[l]){
                ans[i]+=max(0ll,a[i+1]+::l[l-1]-a[i]);
                ans[i+1]+=max(0ll,a[i+1]-(a[i+1]+::l[l-1]));
            }else{
                ans[i]+=max(0ll,a[i]+::r[l-1]-a[i]);
                ans[i+1]+=max(0ll,a[i+1]-a[i]-::r[l-1]);
            }
        }
    }
    for(int i=1;i<=n;i++)printf("%lld\n",ans[i]);
}

Compilation message

Main.cpp: In function 'void usaco(std::string)':
Main.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d%d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:28:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
      |                          ~~~~~^~~~~~~~~~~~~~
Main.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%lld",&x);
      |         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 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 1 ms 332 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 360 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 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 1 ms 332 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 360 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 37 ms 3872 KB Output is correct
21 Correct 33 ms 5440 KB Output is correct
22 Correct 32 ms 5308 KB Output is correct
23 Correct 31 ms 5164 KB Output is correct
24 Correct 39 ms 5796 KB Output is correct
25 Correct 131 ms 11984 KB Output is correct
26 Correct 126 ms 11968 KB Output is correct
27 Correct 121 ms 11604 KB Output is correct
28 Correct 127 ms 11760 KB Output is correct
29 Correct 118 ms 11228 KB Output is correct
30 Correct 112 ms 10692 KB Output is correct
31 Correct 86 ms 10212 KB Output is correct
32 Correct 69 ms 10248 KB Output is correct
33 Correct 12 ms 1484 KB Output is correct
34 Correct 122 ms 12356 KB Output is correct
35 Correct 125 ms 11716 KB Output is correct
36 Correct 128 ms 12100 KB Output is correct
37 Correct 122 ms 11784 KB Output is correct
38 Correct 118 ms 11604 KB Output is correct
39 Correct 123 ms 11836 KB Output is correct
40 Correct 92 ms 11844 KB Output is correct
41 Correct 35 ms 6296 KB Output is correct
42 Correct 69 ms 10192 KB Output is correct
43 Correct 91 ms 13568 KB Output is correct
44 Correct 37 ms 6200 KB Output is correct
45 Correct 79 ms 11728 KB Output is correct
46 Correct 97 ms 13604 KB Output is correct
47 Correct 98 ms 13820 KB Output is correct
48 Correct 104 ms 14072 KB Output is correct