Submission #681832

#TimeUsernameProblemLanguageResultExecution timeMemory
681832abysmalSnowball (JOI21_ho_t2)C++14
100 / 100
119 ms16944 KiB
#include<iostream> #include<stdio.h> #include<stdint.h> #include<vector> #include<algorithm> #include<utility> #include<set> #include<map> #include<queue> #include<stack> #include<deque> #include<string> #include<assert.h> using namespace std; const int64_t INF = (int64_t) 1e18 + 5; const int64_t mINF = 1e6 + 1; const int64_t MOD = (int64_t) 1e9 + 7; const int nbit = 30; const int ndig = 10; const int nchar = 26; const int p1 = 31; const int p2 = 53; const int D = 4; int dr[D] = {0, 1, 0, -1}; int dc[D] = {1, 0, -1, 0}; // 0 right // 1 down // 2 left // 3 up struct Thing { int64_t left; int64_t right; int64_t w; Thing(int64_t left_, int64_t right_, int64_t w_) : left(left_), right(right_), w(w_) {} }; struct Solution { int n; int q; vector<int64_t> a; Solution() {} void solve() { cin >> n >> q; a.push_back(-INF); for(int i = 0; i < n; i++) { int64_t val; cin >> val; a.push_back(val); } a.push_back(INF); vector<int64_t> b; for(int i = 1; i < (int) a.size(); i++) { b.push_back(a[i] - a[i - 1]); } int64_t left = 0; int64_t right = 0; int64_t sum = 0; vector<Thing> v; v.push_back(Thing(0, 0, INF)); for(int i = 0; i < q; i++) { int64_t w; cin >> w; sum += w; v[i].w = w; left = max(left, -sum); right = max(right, sum); v.push_back(Thing(left, right, INF)); } int k = b.size(); vector<int64_t> ans(n, 0); for(int i = 0; i < k; i++) { int64_t len = b[i]; int l = 0; int r = q; int id = -1; while(l <= r) { int mid = l + (r - l) / 2; int64_t tmp = v[mid].left + v[mid].right; if(tmp < len) { id = mid; l = mid + 1; } else r = mid - 1; } int64_t w = v[id].w; int64_t x = v[id].left; int64_t y = v[id].right; if(w != INF) { int64_t re = len - (x + y); if(w > 0) y += re; else x += re; } if(i != 0) ans[i - 1] += y; if(i != k - 1) ans[i] += x; } for(int i = 0; i < n; i++) { cout << ans[i] << "\n"; } } int modsub(int t1, int t2) { int res = t1 - t2; if(res < 0) res += MOD; return res; } int modadd(int t1, int t2) { int res = t1 + t2; if(res >= MOD) res -= MOD; return res; } int modmul(int t1, int t2) { int64_t res = 1LL * t1 * t2; return (res % MOD); } bool BIT(int64_t& mask, int& j) { return (mask & MASK(j)); } int64_t MASK(int j) { return (1LL << j); } }; void __startup() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); } int main() { __startup(); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { Solution().solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...