Advertisement
phanindhar1

flip

Feb 11th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include<iostream>
  2. #include<map>
  3. using namespace std;
  4. map<int,bool> mMap;
  5. int main()
  6. {
  7. int n,a,b;
  8. bool k;
  9. cin>>n;
  10. for(int i=0;i<n;i++)
  11. mMap[i]=0;//mMap[i]=0 indicates it as tail.. else 1 for head;
  12. cin>>n;
  13. for(int i=0;i<n;i++)
  14. {
  15. cin>>k>>a>>b;
  16. if(k)//k==1 counting heads
  17. {
  18. int count = 0;
  19. for(int j=a;j<=b;j++)
  20. if(mMap[j])count++;//when mMap[j]=1 count of head increments..
  21. cout<<count<<endl;
  22. }
  23. else
  24. {
  25. for(int j=a;j<=b;j++)//from mMap[a]to mMap[b] fliping the coins..
  26. mMap[j]=!(mMap[j]);
  27. }
  28. }
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement