Skip to content

Commit

Permalink
chore: solved hard day 5 task
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutosh-3474 committed Apr 11, 2024
1 parent bde62a6 commit ce470a5
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions hard/day_5/solution.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
//Write your code here
// LUOGU_RID: 147799314
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 5e5 + 5;

ll a[MAXN], dif[MAXN];
map<int, ll> mp;
int l_[MAXN], r_[MAXN]; ll x_[MAXN];

int main() { ios::sync_with_stdio(0); cin.tie(0);
int t; cin >> t; while (t--) {
int n; cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int ans = 0;
int q; cin >> q; for (int i = 1; i <= q; i++) {
int l, r; ll x; cin >> l >> r >> x; l_[i] = l; r_[i] = r, x_[i] = x;
mp[l] += x;
if (r+1 <= n)
mp[r+1] -= x;
while (!mp.empty() && mp.begin()->second == 0)
mp.erase(mp.begin());
if (!mp.empty() && mp.begin()->second < 0) {
ans = i;
mp.clear();
}
}
for (int i = 1; i <= ans; i++) {
int l = l_[i], r = r_[i]; ll x = x_[i];
dif[l] += x;
if (r+1 <= n)
dif[r+1] -= x;
}
for (int i = 1; i <= n; i++) {
dif[i] += dif[i-1];
a[i] += dif[i];
cout << a[i] << " \n"[i == n];
}

// init
for (int i = 1; i <= n; i++)
dif[i] = 0;
mp.clear();
}
return 0;
}

0 comments on commit ce470a5

Please sign in to comment.