Блог пользователя Riyad_Hossain

Автор Riyad_Hossain, 2 месяца назад, По-английски

Recently, I have tried a problem: 1893B - Neutral Tonality and solved it with O(NlogN) tc.

Problem Summary: Insert array b into array a at any position while making sure that the LIS is minized.

Approach: For an element el of the array a insert the elements of b which are greater than or equal to el.

However, the solution got TLE on the third test case: Submission 282567664

What's wrong in my approach/code? Can anyone help me to debug this problem?

Code: Used multiset to find elements and map to store the elements.


void solve() { int n, m, x; cin >> n >> m; vi a(n); multiset<int> ms; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> x, ms.insert(x); map<int, vi> elements; forr(i, 0, n - 1) { auto it = lb(a[i], ms); while (it != ms.end()) { elements[i].pb(*it); ms.erase(it); if (!sz(ms)) break; it = lb(a[i], ms); } } forr(i, 0, n - 1) { reverse(all(elements[i])); for (int v : elements[i]) printsp(v); printsp(a[i]); } while (sz(ms)) printsp(*ms.rbegin()), ms.erase(--ms.end()); }
  • Проголосовать: нравится
  • +20
  • Проголосовать: не нравится

»
2 месяца назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Try replacing

lb(a[i], ms)

With this

ms.lower_bound(a[i])

NOT THAT (That is wrong)

lower_bound(ms.begin(), ms.end(), a[i])