863D - Yet Another Array Queries Problem(思维)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }
以上是关于863D - Yet Another Array Queries Problem(思维)的主要内容,如果未能解决你的问题,请参考以下文章
863D - Yet Another Array Queries Problem(思维)
CF1748E Yet Another Array Counting Problem
D. Yet Another Yet Another Task (ST表模版 + 单调队列)
CF-1359 D. Yet Another Yet Another Task ST表+单调队列
CF-1359 D. Yet Another Yet Another Task ST表+单调队列
Educational Codeforces Round 88 (Rated for Div. 2) D. Yet Another Yet Another Task