Psychotic_D_BKL's blog

By Psychotic_D_BKL, history, 5 days ago, In English

https://www.spoj.com/problems/KQUERY/

this was the question and my code is

include <bits/stdc++.h>

using namespace std;

define int long long

int n; vector<vector> segmentTree; vector a;

void build(int l, int r, int index) { if (l == r) { segmentTree[index].push_back(a[l]); return; } int mid = l + (r — l) / 2; build(l, mid, 2 * index + 1); build(mid + 1, r, 2 * index + 2); merge(segmentTree[2 * index + 1].begin(), segmentTree[2 * index + 1].end(), segmentTree[2 * index + 2].begin(), segmentTree[2 * index + 2].end(), back_inserter(segmentTree[index])); }

int query(int l, int r, int start, int end, int index, int k) { if (l > end || r < start) { return 0; } if (l >= start && r <= end) { return segmentTree[index].end() — upper_bound(segmentTree[index].begin(), segmentTree[index].end(), k); } int mid = l + (r — l) / 2; return query(l, mid, start, end, 2 * index + 1, k) + query(mid + 1, r, start, end, 2 * index + 2, k); }

int32_t main() { cin >> n; segmentTree.resize(4 * n); a.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; } build(0, n — 1, 0);

int q;
cin >> q;
while (q--) {
    int l, r, k;
    cin >> l >> r >> k;
    cout << query(0, n - 1, l - 1, r - 1, 0, k) << endl;
}

}

can anyone tell me why am i getting tle..

Full text and comments »

  • Vote: I like it
  • -7
  • Vote: I do not like it

By Psychotic_D_BKL, history, 5 days ago, In English

Hello coders,

can anyone pin some basics segment tree problem where the concept of lazy propoagtion may be used but the level of question should be easy to medium

Full text and comments »

By Psychotic_D_BKL, history, 3 weeks ago, In English

Dear Codeforces Backend Team,

In the CSES question set platform, we have the option to view the full test cases where our solution fails. However, this feature is not available on Codeforces, as the test cases are not visible.

It would be a great help if you could make these test cases visible.

Thank you for considering this suggestion.

Best regards,

Full text and comments »

  • Vote: I like it
  • +18
  • Vote: I do not like it