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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| #include <bits/stdc++.h>
#define x first #define y second #define y1 Y1 #define y2 Y2 #define mp make_pair #define pb push_back
using namespace std;
typedef long long LL; typedef pair<int, int> pii;
template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; } template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
inline void proc_status() { ifstream t ("/proc/self/status"); cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) <<endl; }
inline int read () { int sum = 0, fl = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1; for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0'; return sum * fl; }
const int Maxn = 2e5 + 100;
int N, M, P, A[Maxn];
namespace SEG { #define ls Tree[root << 1] #define rs Tree[root << 1 | 1] #define lson root << 1, l, mid #define rson root << 1 | 1, mid + 1, r struct tree { int val, max; }Tree[Maxn << 2];
inline int query (int root, int l, int r, int suf) { if (l == r) return Tree[root].val = max (Tree[root].max, suf) + l; int mid = l + r >> 1; if (suf <= rs.max) return min (Tree[root].val, query (rson, suf)); return min(query (lson, suf), suf + mid + 1); }
inline void push_up (int root, int l, int r, int mid) { Tree[root].max = max(ls.max, rs.max); Tree[root].val = query (lson, rs.max); }
inline void build (int root, int l, int r) { if (l == r) { Tree[root].max = A[l], Tree[root].val = A[l] + l; return ; } int mid = l + r >> 1; build (lson), build (rson); push_up (root, l, r, mid); }
inline void update (int root, int l, int r, int x) { if (l == r) { Tree[root].max = A[l], Tree[root].val = A[l] + l; return ; } int mid = l + r >> 1; if (x <= mid) update (lson, x); else update (rson, x); push_up (root, l, r, mid); } }
inline void Solve () { SEG :: build (1, 1, N << 1); int ans = SEG :: Tree[1].val + N - 1; cout<<ans<<endl; while (M--) { int x = read(), y = read(); if (P) x ^= ans, y ^= ans; A[x] = y - x, A[x + N] = y - x - N; SEG :: update (1, 1, N << 1, x), SEG :: update (1, 1, N<< 1, x + N); printf("%d\n", ans = SEG :: Tree[1].val + N - 1); } }
inline void Input () { N = read(), M = read(), P = read(); for (int i = 1; i <= N; ++i) A[i] = read() - i, A[i + N] = A[i] - N; }
int main() { #ifdef hk_cnyali freopen("A.in", "r", stdin); freopen("A.out", "w", stdout); #endif Input(); Solve(); return 0; }
|