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
|
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &a){ T w=1; a=0; char ch=getchar(); for(;ch < '0' || ch > '9';ch=getchar()) if(ch == '-') w=-1; for(;ch>='0'&&ch<='9';ch=getchar()) a=(a<<3)+(a<<1)+(ch^48); a*=w; } template <typename T> inline void ckmax(T &a, T b){a = a > b ? a : b;} template <typename T> inline void ckmin(T &a, T b){a = a < b ? a : b;} #define fi first #define se second #define pb push_back #define mp make_pair #define mii map<int, int> #define pii pair<int, int> #define vi vector<int> #define Debug(x) cout << #x << " = " << x << endl #define For(i,l,r) for (int i = l; i <= r; ++i) #define foR(i,l,r) for (int i = l; i >= r; --i) const int N = 2e5 + 10; #define LL long long struct SGT { struct Node { int val, l, r; }; int tot, rt; vector < Node > tr; SGT (int siz) : tot(0), rt(0), tr(siz, Node{-1, 0, 0}) {} #define ls tr[x].l #define rs tr[x].r inline void put (int &x, int v) { if (!x) x = ++tot; tr[x].val = v; } void pushdown (int x) { if (~tr[x].val) put(ls, tr[x].val), put(rs, tr[x].val), tr[x].val = -1; } void update (int &x, int l, int r, int ll, int rr, int v) { if (ll <= l && r <= rr) return put(x, v), void(); pushdown(x); int mid = (l + r) / 2; if (ll < mid) update (ls, l, mid, ll, rr, v); if (rr > mid) update (rs, mid, r, ll, rr, v); } int query (int x, int l, int r, int p) { if (~tr[x].val) return tr[x].val; pushdown(x); int mid = (l + r) / 2; if (p < mid) return query (ls, l, mid, p); return query (rs, mid, r, p); } } ; int n, G, R; LL a[N], pre[N]; LL Ans[N]; int main() { read(n); read(G); read(R); For (i, 0, n) read(a[i]), pre[i] = pre[i - 1] + a[i]; SGT tr (n * 100); R += G; tr.update(tr.rt, 0, R, 0, R, n); foR (i, n - 1, 0) { int j = tr.query (tr.rt, 0, R, (R - pre[i] % R) % R); Ans[i] = Ans[j] + pre[j] - pre[i]; if (j < n) Ans[i] += (R - (pre[j] - pre[i]) % R); int l = (R + G - pre[i] % R) % R; int r = (R - pre[i] % R) % R; if (l < r) tr.update (tr.rt, 0, R, l, r, i); else { tr.update (tr.rt, 0, R, l, R, i); if (r) tr.update (tr.rt, 0, R, 0, r, i); } } int q; read(q); LL tmp = 0; while (q--) { int t; read(t); t = t xor (tmp % 2147483647); int i = tr.query (tr.rt, 0, R, t % R); tmp = Ans[i] + pre[i] + t; if (i < n) tmp += R - (pre[i] + t) % R; printf ("%lld\n", tmp); } return 0; }
|