Submission #951136

# Submission time Handle Problem Language Result Execution time Memory
951136 2024-03-21T08:02:37 Z veljko Snowball (JOI21_ho_t2) C++17
33 / 100
2500 ms 18032 KB
/*****from dust I have come, dust I will be*****/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define forn(i,n) for(int i=0;i<n;i++)
int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int ceil_div(int a, int b) {return a % b == 0 ? a / b : a / b + 1;}
 
const int MOD = 1000000007;
//const int MOD = 998244353;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
 
/*
int k = A.order_of_key(p[i].second);
A.erase(A.find_by_order(k));
erase element from pbds multiset
*/


void solve(){
    int n, q; cin >> n>> q;
    vector<int>a(n); for (auto &t : a) cin >> t;
    vector<int>b(q); for (auto &t : b) cin >> t;
    vector<int>dif;
    forn(i,q){
        if (i == 0) dif.push_back(b[0]);
        else dif.push_back(dif.back() + b[i]);
    }
    // for (auto t : dif) cout <<t<<' ';
    // cout <<'\n';

    
    map<int, int>mp;
    forn(i,q){
        if (mp.find(dif[i]) == mp.end()) mp[dif[i]] = i;
    }

    //for (auto t : mp) cout <<t.first<<' '<<t.second<<'\n';
    vector<int>ans(n, 0);
    for (int i=0;i<n-1;i++){
        int l = 0, r = a[i+1] - a[i], x = 0, y = 0;
  
        while (l <= r){
            int mid = (l + r) / 2;
            bool ok = false;
            int bad = (a[i+1] - a[i]) - mid;
            for (auto t : dif){
                if (t >= mid){
                    ok = true;
                    break;
                }
                if (-t > bad){
                    ok = false;
                    break;
                }
            }
            if (ok){
                l = mid + 1;
                x = mid;
            }
            else r = mid - 1;
        }
        
        ans[i] += x;
    }
    ans[n-1] += max(*max_element(dif.begin(), dif.end()), 0ll);
    for (int i=1;i<n;i++){
        int l = 0, r = a[i] - a[i-1], x = 0;
        while (l <= r){
            int mid = (l + r) / 2;
            int bad = (a[i] - a[i-1]) - mid;
            //cout <<bad<<'\n';
            bool ok = false;
            for (auto t : dif){
                if (-t >= mid){
                    ok = true;
                    break;
                }
                if (t > bad){
                    ok = false;
                    break;
                }
            }
            if (ok){
                l = mid + 1;
                x = mid;
            }
            else r = mid - 1;
        }
        
        ans[i] += x;
    }
    ans[0] += max(0ll, *min_element(dif.begin(), dif.end()) * - 1);
    for (auto t : ans) cout <<t<<'\n';
}
 
 
int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 

 
    int t = 1; //cin >>t;
    for (int i=1;i<=t;i++){
        solve();
    }
    return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:46:46: warning: unused variable 'y' [-Wunused-variable]
   46 |         int l = 0, r = a[i+1] - a[i], x = 0, y = 0;
      |                                              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 616 KB Output is correct
3 Correct 13 ms 604 KB Output is correct
4 Correct 93 ms 632 KB Output is correct
5 Correct 49 ms 604 KB Output is correct
6 Correct 35 ms 464 KB Output is correct
7 Correct 29 ms 668 KB Output is correct
8 Correct 25 ms 600 KB Output is correct
9 Correct 21 ms 604 KB Output is correct
10 Correct 10 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 69 ms 680 KB Output is correct
16 Correct 57 ms 672 KB Output is correct
17 Correct 42 ms 680 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 46 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 616 KB Output is correct
3 Correct 13 ms 604 KB Output is correct
4 Correct 93 ms 632 KB Output is correct
5 Correct 49 ms 604 KB Output is correct
6 Correct 35 ms 464 KB Output is correct
7 Correct 29 ms 668 KB Output is correct
8 Correct 25 ms 600 KB Output is correct
9 Correct 21 ms 604 KB Output is correct
10 Correct 10 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 69 ms 680 KB Output is correct
16 Correct 57 ms 672 KB Output is correct
17 Correct 42 ms 680 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 46 ms 604 KB Output is correct
20 Correct 54 ms 18032 KB Output is correct
21 Correct 130 ms 17856 KB Output is correct
22 Correct 739 ms 17856 KB Output is correct
23 Execution timed out 2554 ms 17472 KB Time limit exceeded
24 Halted 0 ms 0 KB -