863D - Yet Another Array Queries Problem(思维)

原题连接:http://codeforces.com/problemset/problem/863/D

题意:对a数列有两种操作:

1 l r ,[l, r] 区间的数字滚动,即a[i+1]=a[i], a[l]=a[r]

2 l r ,[l, r] 区间的数字位置反转。

若干个操作之后输出a[b[i]].

思路:

由于是在操作结束后输出,且b[i]的个数不多(<=100),所以可以通过反推求出答案。

AC代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 typedef long long LL;
 6 const int MAXN = 2e5+10;
 7 struct Query {
 8     int type;
 9     int l,r;
10 }Q[MAXN];
11 int a[MAXN];
12 int n, q, m;
13 void print(int b)
14 {
15     for (int i = 1;i <= q;i++) {
16         if (b >= Q[i].l&&b <= Q[i].r) {
17             if (Q[i].type == 1) {
18                 b--;
19                 if (b < Q[i].l)
20                     b = Q[i].r;
21             }
22             else
23                 b = Q[i].r - (b - Q[i].l);
24         }
25     }
26     printf("%d", a[b]);
27     return;
28 }
29 int main() {
30
31     scanf("%d %d %d", &n, &q, &m);
32     for (int i = 1;i <= n;i++) {
33         scanf("%d", &a[i]);
34     }
35     for (int i = q;i >= 1;i--) {
36         scanf("%d %d %d", &Q[i].type, &Q[i].l, &Q[i].r);
37     }
38     int b;
39     for (int i = 0;i < m;i++) {
40         scanf("%d", &b);
41         if (i != 0) printf(" ");
42         print(b);
43     }
44     printf("\n");
45     return 0;
46 }
时间: 2024-10-31 06:12:32

863D - Yet Another Array Queries Problem(思维)的相关文章

lightoj Again Array Queries

1100 - Again Array Queries   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB Given an array with n integers, and you are given two indices i and j (i ≠ j) in the array. You have to find two integers in the range whose diffe

LightOJ Array Queries 1082【线段树求区间最值】

1082 - Array Queries PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 64 MB Given an array with N elements, indexed from 1 to N. Now you will be given some queries in the form I J, your task is to find the minimum value from index

lightoj-1082 - Array Queries

1082 - Array Queries PDF (English) Statistics ForumTime Limit: 3 second(s) Memory Limit: 64 MBGiven an array with N elements, indexed from 1 to N. Now you will be given some queries in the form I J, your task is to find the minimum value from index I

Array Queries CodeForces - 797E

Array Queries CodeForces - 797E WATLERE之路: 很显然的一道dp题,于是我妄想着通过时间O(n^2)的dp把它A掉,然后,我就走上了WATLERE之路..... 第一次,递归,RE 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int ans[100100]; 6 int a[100100]; 7 int n

codeforces 797 E. Array Queries【dp,暴力】

题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为止,求每次询问要转换的次数. 题解:纯暴力会TLE,所以在k为根号100000范围内dp打表 dp[i][j]表示初始p为i, k为j,需要转换几次可以大于n. 状态转移方程:dp[i][j] = dp[i+a[i]+j] + 1 #include <cstdio> #include <al

Light oj 1100 - Again Array Queries (鸽巢原理+暴力)

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1100 给你n个数,数的范围是1~1000,给你q个询问,每个询问问你l到r之间数的最小差是多少. 要是l到r的数字个数大于1000,必定会有两个数字重复,所以此时最小差就为0.要是小于等于1000就直接暴力即可. 1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include <alg

zoj3798Abs Problem(思维)

题目链接: huangjing 题目意思: 用1~n中的数字进行组合,得到后面减前面的一项的最大最小值... 思路: 多试两个就会发现从n到1的排列得到的是最小值,同理从n-1到1得到的也是最小值,那么用n-这个最小值,那么必定得到的是最大值... 题目: Abs Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Alice and Bob is playing a game, and thi

[Algorithm] Array production problem

Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i. For example, if our input was [1, 2, 3, 4, 5], the expected output would be

FZU - 2038 -E - Another Postman Problem (思维+递归+回溯)

Chinese Postman Problem is a very famous hard problem in graph theory. The problem is to find a shortest closed path or circuit that visits every edge of a (connected) undirected graph. When the graph has an Eulerian Circuit (a closed walk that cover