Skip to content

Instantly share code, notes, and snippets.

@Hacv16

Hacv16/domino.cc Secret

Created October 6, 2023 22:49
Show Gist options
  • Save Hacv16/efd3f00e84b4b595bbb67e84285395b0 to your computer and use it in GitHub Desktop.
Save Hacv16/efd3f00e84b4b595bbb67e84285395b0 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
int n, x[MAXN], h[MAXN], f[MAXN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; i++) cin >> x[i];
for(int i = 1; i <= n; i++) cin >> h[i];
stack<int> ativos;
for(int i = n; i >= 1; i--)
{
int curF = 0;
while(!ativos.empty() && x[i] + h[i] >= x[ ativos.top() ])
{
curF += f[ ativos.top() ];
ativos.pop();
}
f[i] = curF + 1;
ativos.push(i);
}
for(int i = 1; i <= n; i++)
cout << f[i] << ' ';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment