Jaggu Playing with Balloons

  • + 1 comment

    cant understand what to do after this its not able to pass test cases other than test case0

    #include <cmath>
    #include<string.h>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    class Node{
        public:
        int data;
        int pos;
        Node* next;
    };
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
        Node* start=new Node();
        start=NULL;   
        int Q;
        cin >> Q;
        char op;
        int pos, pos1, pos2, plus, M;
        while (Q--)
        {
            Node* n=new Node();
            cin >> op;
            if (op == 'U')      //Update
            {
                int sum=0;
                cin >> pos >> M >> plus;
                    int N=1000000;  //1 million
                    for (int i=1;i<=50;i++)
                    {
                        int back = pos;
                        for(int j=1;j<=1000;j++)
                        {
                            Node* p=new Node();
                            p->data=M;
                            p->pos=pos-1;
                            p->next=NULL;
                            if(start==NULL){
                                start=p;
                                n=p;
                            }
                            else{
                                n->next=p;
                                n=p;
                            }
                            int s,in=__builtin_popcount(pos);
                            for(int k=0;;k++)
                        {
                            s=pos+pow(2,k);
                            if( __builtin_popcount(s) <= in )
                            {
                                in = __builtin_popcount(s);
                                pos = s;
                                if(pos>N)       break;
                               Node* p=new Node();
                                p->data=M;
                                p->pos=pos-1;
                                p->next=NULL;
                                n->next=p;
                                n=p;
                            }
                        }
                        pos = pos - N;
                    }
                    pos = back+plus;
                    if(pos>N) pos-=N;
        }
    
               }
                else
                {
                    cin >> pos1 >> pos2;
                    long long x = 0;
                         Node* p=new Node();
                         p=start;
                         while(p->next!=NULL){
                             if(p->pos>pos1 && p->pos<pos2)
                                x += p->data;
                            p=p->next;
                         }
                    cout << x << endl;
                }
        }
         return 0;
    }