• C - Copy (hdu)


    Kayzin has a list of integers, initially the list is a_1,a_2,\ldots,a_na1​,a2​,…,an​. He will execute qq operations.

    For an operation of first type, he will select an interval [l_i, r_i][li​,ri​], copy and insert it to the end of the interval.

    For an operation of second type, he wonder the x_ixi​-th integer of the list.

    You need to print the xor sum of all the answers of second type operations.

    ps: What is xor? The xor value of two integers is equal to addition in binary without carry.

    ps: nn is a constant for each test case.

    Input

    First line is an integer TT, indicating the number of test cases. For each test case:

    First line is 2 integers n,qn,q, indicating the length of initial list and the number of operations.

    Next line is nn integers a_1,a_2,\ldots,a_na1​,a2​,…,an​, indicating the initial list.

    Next qq line, one operation per line. The ii-th line could be 3 integers (1,l_i,r_i1,li​,ri​), indicating the first type operation, or 2 integers (2,x_i2,xi​), indicating the second type operation.

    1\le T \le 10,1≤T≤10, 1\le n,q\le 10^5,1≤n,q≤105, 1\le a_i\le 10^9,1≤ai​≤109, \sum n \le 10^5,∑n≤105, \sum q \le 10^5,∑q≤105, 1\le x_i,l_i,r_i \le n,1≤xi​,li​,ri​≤n, the sum of the number of first type operations (all test cases together) not exceeds 2000020000.

    Output

    For each test case, print one line, indicating the xor sum of the answers.

    题意:有一个长度为n的数组,然后有两个操作,操作1 l r是将lr这段数复制之后加在r后,操作2 x是找位于x的数的所有异或和

    思路:将lr这段复制加在r后面相当于加了长度为(r-l+1)的数让r后面的数往后了,所以变化后的r后面的数是原来数组里的数往后推了(l-r+1)个,那么我们找变化后的r后面的数ai实际上就是他前面的第r-l+1个数,即变化后的数组里的a[i]=变化前的数里的a[i-(r-l+1)],然后我们可以从后往前遍历数组让r+1~n的数ai全是a[i-(r-l+1)],就完成了每次的复制。

    1. /*
    2. .----------------. .----------------. .----------------. .----------------.
    3. | .--------------. || .--------------. || .--------------. || .--------------. |
    4. | | ________ | || | _________ | || | ____ ____ | || | ____ | |
    5. | | |_ ___ `. | || | |_ ___ | | || ||_ \ / _|| || | .' `. | |
    6. | | | | `. \ | || | | |_ \_| | || | | \/ | | || | / .--. \ | |
    7. | | | | | | | || | | _| _ | || | | |\ /| | | || | | | | | | |
    8. | | _| |___.' / | || | _| |___/ | | || | _| |_\/_| |_ | || | \ `--' / | |
    9. | | |________.' | || | |_________| | || ||_____||_____|| || | `.____.' | |
    10. | | | || | | || | | || | | |
    11. | '--------------' || '--------------' || '--------------' || '--------------' |
    12. '----------------' '----------------' '----------------' '----------------'
    13. */
    14. #include
    15. #include
    16. #include
    17. #include
    18. #include
    19. #include
    20. #include
    21. #include
    22. #include
    23. #include
    24. #include
    25. #define int long long
    26. #define lowbit(x) x&(-x)
    27. #define PI 3.1415926535
    28. #define endl "\n"
    29. using namespace std;
    30. typedef long long ll;
    31. typedef pair<int,int> pii;
    32. int gcd(int a,int b){
    33. return b>0 ? gcd(b,a%b):a;
    34. }
    35. const int N=1e5+10;
    36. int n,q;
    37. int a[N];
    38. /*
    39. int dx[8]={-2,-2,-1,1,2,2,-1,1};
    40. int dy[8]={-1,1,2,2,1,-1,-2,-2};
    41. int dx[4]={0,-1,0,1};
    42. int dy[4]={-1,0,1,0};
    43. int dx[8]={-1,1,0,0,-1,-1,1,1};
    44. int dy[8]={0,0,-1,1,-1,1,-1,1};
    45. */
    46. void sove(){
    47. cin>>n>>q;
    48. for(int i=1;i<=n;i++){
    49. cin>>a[i];
    50. }
    51. int con=0;
    52. while(q--){
    53. int op;
    54. cin>>op;
    55. if(op==1){
    56. int l,r;
    57. cin>>l>>r;
    58. for(int i=n;i>=r+1;i--){
    59. a[i]=a[i-(r-l+1)];
    60. }
    61. }else{
    62. int x;
    63. cin>>x;
    64. con^=a[x];
    65. }
    66. }
    67. cout<
    68. }
    69. signed main(){
    70. ios::sync_with_stdio(false);
    71. cin.tie() ,cout.tie() ;
    72. int t=1;
    73. cin>>t;
    74. while(t--){
    75. sove();
    76. }
    77. return 0;
    78. }

  • 相关阅读:
    面试官:完全背包都不会,是你自己走还是我送你?
    fatal error: linux/compiler-gcc9.h: No such file or directory
    JavaScript:实现 jugglerSequence杂耍者序列算法 (附完整源码)
    PlugLink:让数据分析与工作流无缝连接(附源码)
    HMS Core图形图像技术展现最新功能和应用场景,加速构建数智生活
    Python匿名函数
    苍穹外卖(四) AOP切面公共字段自动填充及文件上传
    快手创作者版App正式上线
    008 OpenCV matchTemplate 模板匹配
    部署轻量级Gitea替代GitLab进行版本控制(一)
  • 原文地址:https://blog.csdn.net/qq_61903556/article/details/126058048