a53

Descompunere Intervale

a53
Aug 1st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. vector <pair<int, int>> ans;
  5. void rezolva (int st, int dr, int a, int b)
  6. {
  7. if (a<=st && dr<=b)
  8. {
  9. ans.push_back({st, dr});
  10. return;
  11. }
  12. int mij = st+dr>>1;
  13. if (a<=mij) rezolva(st, mij, a, b);
  14. if (mij<b) rezolva(mij+1, dr, a, b);
  15. }
  16. int main()
  17. {
  18. ifstream fin ("di.in");
  19. ofstream fout ("di.out");
  20. int n, m;
  21. fin >> n >> m;
  22. while (m--)
  23. {
  24. ans.clear();
  25. int x, y;
  26. fin >> x >> y;
  27. rezolva(1, n, x, y);
  28. fout << ans.size() << " ";
  29. sort(ans.begin(), ans.end());
  30. fout << ans[0].first << " ";
  31. for (auto x:ans)
  32. fout << x.second << " ";
  33. fout << '\n';
  34. }
  35. return 0;
  36. }
Add Comment
Please, Sign In to add comment