Submission #1166188

#TimeUsernameProblemLanguageResultExecution timeMemory
1166188hainam2k9Snowball (JOI21_ho_t2)C++20
100 / 100
53 ms8464 KiB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 2e5+5;
const string NAME = "";
int n,q,pos=0;
ll a[MAXN],rs[MAXN],x,sum=0,MAX=0,MIN=0;
vector<pair<ll,pair<int,int>>> v;
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n >> q;
    for(int i = 1; i<=n; ++i){
        cin >> a[i];
        if(i>1) v.pb(a[i]-a[i-1],mp(i,i-1));
    }
    sort(v.begin(),v.end());
    while(q--){
        cin >> x;
        sum+=x;
        if(sum>MAX){
            MAX=sum;
            while(pos<sz(v)&&MAX-MIN>=v[pos].fi){
                rs[v[pos].se.fi]-=MIN, rs[v[pos].se.se]+=v[pos].fi+MIN;
                ++pos;
            }
        }else if(sum<MIN){
            MIN=sum;
            while(pos<sz(v)&&MAX-MIN>=v[pos].fi){
                rs[v[pos].se.se]+=MAX, rs[v[pos].se.fi]+=v[pos].fi-MAX;
                ++pos;
            }
        }
    }
    rs[1]-=MIN, rs[n]+=MAX;
    while(pos<sz(v)) rs[v[pos].se.se]+=MAX, rs[v[pos].se.fi]-=MIN, ++pos;
    for(int i = 1; i<=n; ++i)
        cout << rs[i] << "\n";
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:45: note: in expansion of macro 'fo'
   28 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
Main.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:45: note: in expansion of macro 'fo'
   28 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...