Advertisement
9I_HE_TbI_A_9I

Untitled

Oct 26th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main(){
  10. ios::sync_with_stdio(0);
  11. int n;
  12. cin >> n;
  13. vector<int> depth(n, 0);
  14. vector<vector<int>> jump(n, vector<int>(19, 0));
  15. vector<int> kol(n, 0);
  16.  
  17. jump[0][0] = 0; int a, b;
  18. for (int i = 0; i < n; i++) {
  19. char ch, dop;
  20. ch = 'A';
  21. a = i + 1; b = i + 2;
  22. a--; b--;
  23. if (i == n - 1) {
  24. a = 0; b = i; ch = 'G';
  25. }
  26. if (i % 100000 == 0) {
  27. cout << i << endl;
  28. }
  29. if (ch == 'A') {
  30. depth[b] = depth[a] + 1;
  31. jump[b][0] = a;
  32. for (int k = 1; k <= 18; k++) {
  33. int e = 1;
  34. }
  35. }
  36. else {
  37. if (depth[a] < depth[b]) {
  38. swap(a, b);
  39. }
  40. for (int k = 18; k >= 0; k--) {
  41. if (depth[jump[a][k]] >= depth[b]) {
  42. a = jump[a][k];
  43. }
  44. }
  45. if (a != b) {
  46. for (int k = 18; k >= 0; k--) {
  47. if (jump[a][k] != jump[b][k]) {
  48. a = jump[a][k];
  49. b = jump[b][k];
  50. }
  51. }
  52. a = jump[a][0];
  53. }
  54. cout << a + 1 << endl;
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement