Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node {
- long long v;
- int h;
- node *l;
- node *r;
- };
- long long a=0,b=0;
- int h(node *n){
- if (n==NULL){
- return 1;
- }else{
- a+=h(n->l);
- b+=h(n->r);
- }
- }
- void pridaj(long long x, node *n, int _h) {
- if (n == NULL) {
- n = new node;
- n->l = NULL;
- n->r = NULL;
- n->v = x;
- n->h = _h;
- return;
- }
- if (x == n->v){
- return;
- }
- if (x > n->v) {
- if (n->r == NULL){
- n->r = new node;
- n->r->l = NULL;
- n->r->r = NULL;
- n->r->v = x;
- n->r->h = _h;
- return;
- }else{
- pridaj(x, n.r, h+1);
- }
- }
- if (x < n->v) {
- if (n->l == NULL){
- n->l = new node;
- n->l->l = NULL;
- n->l->r = NULL;
- n->l->v = x;
- n->l->h = _h;
- return;
- }else{
- pridaj(x,n.l, h+1);
- }
- }
- }
- int main(int argc, char** argv) {
- node *root=new node();
- root->l = NULL;
- root->r = NULL;
- root->h = 0;
- int t;
- cin >> t;
- for (int i = 0; i<t; i++){
- int n, x;
- cin>>n>>x;
- int tmp=(x * 25173 + 13849) % 65536;
- root->v=tmp;
- for (int j=1; j<n; j++){
- tmp=(tmp * 25173 + 13849) % 65536;
- pridaj(tmp, root, root->h);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement