Submission #951136

#TimeUsernameProblemLanguageResultExecution timeMemory
951136veljkoSnowball (JOI21_ho_t2)C++17
33 / 100
2554 ms18032 KiB
/*****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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...