import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.List; class Node { private Node next; private int value; public Node(int value) { this.value = value; } public Node getNext() { return next; } public void setNext(Node next) { this.next = next; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } public static Node createNodeList(Integer[] values) { Node head = new Node((values[0])); Node node = head; for (int i = 1; i < values.length; i++) { Node newNode = new Node(values[i]); node.next = newNode; node = newNode; } return head; } public static Node createNodeList(String[] values) { Node head = new Node(Integer.parseInt(values[0])); Node node = head; for (int i = 1; i < values.length; i++) { Node newNode = new Node(Integer.parseInt(values[i])); node.next = newNode; node = newNode; } return head; } } class LinkReverse { public static StringBuilder linkReverse(Node head, int len, int left,int right) { StringBuilder sb = new StringBuilder(); if(left>right||left>len||right>len)return sb; //找left节点和right节点 Node left_node=findNode(head,len+1-left); Node right_node=findNode(head,len+1-right); //left节点的前一个节点,若存在则给出,若不存在则为null(不存在说明left为头节点) Node left_forward=null; if(len+2-left<=len){ left_forward=findNode(head,len+2-left); } //开始反转 if (right - left > 0) { Node n1 = left_node; Node n2 = n1.getNext(); Node n3 = n2.getNext(); while (n1 != right_node) { n2.setNext(n1); n1 = n2; n2 = n3; if (n3 != null)n3 = n3.getNext(); } left_node.setNext(n2); if(left_forward!=null){ left_forward.setNext(n1); }else{ head=n1;//若left节点为头结点,说明头结点被翻转了,head需指向翻转的尾部 } } //输出 Node n = head; while (n != null) { sb.append(n.getValue()).append(" "); n = n.getNext(); } return sb; } //找倒数第x个节点 public static Node findNode(Node head, int x) { Node n_fast = head;//快指针 Node n_low = head;//慢指针 //快指针先走k步 for (int i = 0; i < x; i++) { n_fast = n_fast.getNext(); } //快慢指针一起走,到快指针走完为止,慢指针刚好指向目标位置 while (n_fast != null) { n_fast = n_fast.getNext(); n_low = n_low.getNext(); } return n_low; } } public class Main { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(input.readLine()); String[] strings1 = input.readLine().split(" "); Node head = Node.createNodeList(strings1); String[] strings2 = input.readLine().split(" "); int l = Integer.parseInt(strings2[0]); int r = Integer.parseInt(strings2[1]); System.out.print(LinkReverse.linkReverse(head, n, l, r).toString()); } }