Adit_Jain

Code #Codechef

Apr 8th, 2019
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     long long int edges,d,q,i,type,x,top,leaf;
  6.     cin >> d >> q;
  7.     edges = pow(2,d+1)-2;
  8.     top=1;
  9.     leaf = pow(2,d);
  10.     for(i=0;i<q;i++)
  11.     {
  12.         cin >> type;
  13.         if(type==1)
  14.         {
  15.             cin >> x;
  16.             if( x==1 || x==2)
  17.             {
  18.                 edges = 2*edges%1000000007 + d+1;
  19.                 top = 2*top;
  20.                 leaf = 2*leaf;
  21.             }
  22.             else if ( x == 3)
  23.             {
  24.                 edges = 2*edges%1000000007 + top;
  25.                 d = 2*d+1;
  26.                 top = leaf;
  27.             }
  28.             else if (x==4)
  29.             {
  30.                 edges = 2*edges%1000000007 + leaf;
  31.                 d = 2*d+1;
  32.                 leaf = top;
  33.             }
  34.             edges = edges%1000000007;
  35.         }
  36.         else
  37.             cout << edges << endl;
  38.     }
  39.     return 0;
  40. }
Add Comment
Please, Sign In to add comment