-
Notifications
You must be signed in to change notification settings - Fork 5
/
863D (reverse queries).cpp
45 lines (36 loc) · 1.19 KB
/
863D (reverse queries).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// https://codeforces.com/contest/863/problem/D
// Ideq: for each request for index x return all queries in which x falls (works only if m is small enough)
// Time complexity: О(m * q)
// Space complexity: O(max(n,q))
#include<cstdio>
#include <vector>
using namespace std;
int main() {
int n, q, m;
scanf("%d %d %d", &n, &q, &m);
vector<int> a(n + 1), type(q + 1), l(q + 1), r(q + 1);
int x;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= q; ++i) {
scanf("%d %d %d", &type[i], &l[i], &r[i]);
}
while (m--) {
scanf("%d", &x);
for (int i = q; i >= 1; --i) {
if (x >= l[i] && x <= r[i]) { // if it is in the curr query range
if (type[i] == 2) { // rev
x = l[i] + r[i] - x; // 1...l...x...y...r
// Let [1...l]=lambda, then y = lambda + (r - l) - (x - lambda) = l + r - l - x + l = l + r - x
} else if (x == l[i]) { //cyc - corner case
x = r[i];
} else { // cyc
--x;
}
}
}
printf("%d ", a[x]);
}
return 0;
}