# Comet OJ - Contest #8 D 菜菜种菜（树状数组）

## 题目链接

#pragma comment(linker, "/STACK:102400000,102400000")

#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<cmath>
#include<stack>
#include<string>

const int mod = 998244353;
const int maxn = 1e6 + 5;
const int inf = 1e9;
const long long onf = 1e18;
#define me(a, b) memset(a,b,sizeof(a))
#define lowbit(x) x&(-x)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI 3.14159265358979323846
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int sum[maxn], val[maxn], ans[maxn];
int n, m, q;
int l[maxn], r[maxn];

struct node {
int l, r, id;

bool friend operator<(node a, node b) {
return a.r < b.r;
}
} a[maxn];

struct Node {
int l, r, val;
};
vector<Node> maps[maxn];

void push_date(int pos, int val) {
while (pos <= n) {
sum[pos] += val;
pos += lowbit(pos);
}
}

int query(int pos) {
int ans = 0;
while (pos) {
ans += sum[pos];
pos -= lowbit(pos);
}
return ans;
}

int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= n; i++) {
scanf("%d", &val[i]);
l[i] = 0, r[i] = n + 1;
}
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
if (v > u)
r[u] = min(r[u], v);
else
l[u] = max(l[u], v);
}
for (int i = 1; i <= q; i++) {
scanf("%d%d", &a[i].l, &a[i].r);
a[i].id = i;
}
for (int i = 1; i <= n; i++) {
maps[i].push_back(Node{l[i] + 1, i + 1, val[i]});///因为询问区间要包含i点，所以右端点是i
maps[r[i]].push_back(Node{l[i] + 1, i + 1, -val[i]});///当不在这个区间后，要减去该点的影响
}
sort(a + 1, a + 1 + q);
int nowpos = 1;
for (int i = 1; i <= q; i++) {
while (nowpos <= a[i].r) {
for (int j = 0; j < maps[nowpos].size(); j++) {
push_date(maps[nowpos][j].l, maps[nowpos][j].val);
push_date(maps[nowpos][j].r, -maps[nowpos][j].val);
}
nowpos++;
}
ans[a[i].id] = query(a[i].l);
}
ll Ans = 0;
for (int i = 1; i <= q; i++) {
Ans ^= (ll) ans[i] * i;
}
printf("%lld\n", Ans);
return 0;
}

08-10 136

08-10 119

08-14 47

08-12 32

08-20 56

08-16 62

08-10 92

08-03 1万+

#### TIOBE 8 月编程语言：C、Java 差距拉大，R 语言盛行

©️2020 CSDN 皮肤主题: 创作都市 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。