We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Almost sorted interval
Almost sorted interval
Sort by
recency
|
48 Discussions
|
Please Login in order to post a comment
using namespace std;
typedef long long ll;
const int MAXN = 1001000; int fenwickTree[MAXN], n; vector addLater[MAXN];
inline int getPrefixSum(int idx) { int sum = 0; while (idx >= 0) { sum += fenwickTree[idx]; idx = (idx & (idx + 1)) - 1; } return sum; }
inline void update(int idx, int delta) { while (idx < n) { fenwickTree[idx] += delta; idx = (idx | (idx + 1)); } }
ll solve(vector& arr) { vector nextGreater(sz(arr)), prevSmaller(sz(arr)); vector st;
}
int main() { n = readInt(1, MAXN); vector arr(n); forn(i, n) { arr[i] = readInt(1, n) - 1; } cout << solve(arr) << endl; return 0; }
Python3 solution
Hi Not sure who may look It looks like test expected output is wrong for several input test cases (I manually calculated periods for some and never got as expected output)
Moreover, then I looked at Editorial section and seems there is an error That code gives 17 count for input: 7, {3, 1, 2, 5, 4, 6, 7} Will not be there only 13: {3}, {1}, {1, 2}, {1, 2, 5}, {2}, {2, 5}, {5}, {4}, {4, 6}, {4, 6, 7}, {6}, {6, 7}, {7}?
Hi, I have written code in Ruby. It works fine in my local but here it says wrong answer for test case 4
end
here is hackerrank almost sorted interval solution