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.
- Prepare
- Data Structures
- Advanced
- Swaps and Sum
- Discussions
Swaps and Sum
Swaps and Sum
Sort by
recency
|
6 Discussions
|
Please Login in order to post a comment
Am I completely mistaken, but will not a cartesian tree based on the indices always form a linked list? Left node will always be empty???
include
include
using namespace std;
int main() { int n=0,m=0; int t=0,l=0,r=0,x=0,sum=0; cin>>n>>m; int arr[n];
}
????
ok,if you are talking about segmentation fault error then you have taken "sum" variable in "Integer" datatype. You should have taken "long" datatype instead of "int" for variable "sum" as it sums array elements which individually can store value from 1-10^6 that means if two of elements having value 10^6 will cross the limit of "Integer datatype and will come under "long".
So, this was for segmentation fault error, after resolving this you will find 9 test cases still failing, due to time complexity. that is why it is in advanced category. and itteration of such long array will definately cause time error
question is not clear
c++
undef NDEBUG
ifdef ssu1
define _GLIBCXX_DEBUG
endif
include
include
include
include
include
include
include
include
include
include
include
include
include
include
include
include
include
include
using namespace std;
struct node{ int cnt, pr, info; long long sum; bool rev; node *l, *r, *par; node(){ cnt = 1; pr = info = 0; sum = 0; rev = false; l = r = par = 0; } };
typedef node* tree;
const int MAX_BUF = 2e6; int szbuf; node buf[MAX_BUF];
struct explicit_treap{
};
void tswap(explicit_treap& t1, int l1, int r1, explicit_treap& t2, int l2, int r2){ tree p1, p2, p3, q1, q2, q3;
}
int main() {
ifdef ssu1
endif
ifdef ssu1
endif
}
The explanation in the editorial doesn't clarify that much why this solution is better. It would be nice if you explain what a cartesian tree is, for the ones don't know about. I know, just need to google it and find it, but again, would be nice that the participants could find all the information they need to be better programmers in the site. Besides that, code is clean, but some comments would help to understand the code to less expert developers.
The best option here is to use two Splay Trees. Because it is much easier to cut / join the tree in Splay Tree.
for complete solution in java c++ and c programming search for programs.programmingoneonone.com on google