正文
增加 25 行删除 25 行
60 行未改动61626364656667686910 行未改动80818283848586878889909192939419 行未改动11411511611711811912012112274 行未改动1971981992002012022032042052062072082092102112122132142152163 行未改动2202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542 行未改动2572582592602612622632642652 行未改动60 行未改动return val < b.val;}};priority_queue<xwx> qu;void prework() {//离散化所有出现的权值。sort(lsh + 1, lsh + totl + 1);totl = unique(lsh + 1, lsh + totl + 1) - lsh - 1;for (int i = 1; i <= n; ++i) {10 行未改动int f[N];#define ls tr<<1#define rs tr<<1 | 1struct SegmentTree1 {//第一棵线段树,用来预处理 fstruct node {int lc, rc;int ans;} tree[N << 2];void push_up(int tr) {tree[tr].ans = tree[ls].ans + tree[rs].ans - (tree[ls].rc & tree[rs].lc);tree[tr].lc = tree[ls].lc;tree[tr].rc = tree[rs].rc;19 行未改动return tree[1].ans;}} s1;struct SegmentTree2 {//第二棵线段树,用来处理修改。struct node {int val, tag;} tree[N << 2];//这里R就是值域totl 了74 行未改动for (int i = 1; i <= m; ++i) {if (q[i].id) {int id = q[i].id, del = q[i].val;//这一部分建议结合曲线图来理解修改的区间(三个点的就够)if (id == 1) {//首尾两个点特殊照顾一下。if (a[id] < del) {//权值增加if (del > a[id + 1]) {//如果增加的范围超过了右侧点s2.modify(1, 1, totl, max(a[id + 1], a[id]) + 1, del, 1);}} else if (a[id] > del) {//权值减少if (a[id] > a[id + 1]) {//如果减少前权值比右侧点大s2.modify(1, 1, totl, max(a[id + 1], del) + 1, a[id], -1);}}} else if (id == n) {//和 id == 1 类似if (a[id] < del) {if (del > a[id - 1]) {s2.modify(1, 1, totl, max(a[id - 1], a[id]) + 1, del, 1);}3 行未改动}}} else {int mx = max(a[id - 1], a[id + 1]), mn = min(a[id - 1], a[id + 1]);//我们只关心两侧点中较大的和较小的值为多少if (a[id] < del) {//权值增加if (a[id] < mn) {//修改前比较小值还要小if (del <= mx) {//修改后没超过较大值s2.modify(1, 1, totl, a[id] + 1, min(del, mn), -1);} else {//超过了s2.modify(1, 1, totl, a[id] + 1, mn, -1);s2.modify(1, 1, totl, mx + 1, del, 1);}} else if (a[id] <= mx) {//修改前在两侧权值之间if (del > mx) {//只有修改后超过较大值才会更新答案s2.modify(1, 1, totl, mx + 1, del, 1);}} else {//修改前比较大值大s2.modify(1, 1, totl, a[id] + 1, del, 1);}} else if (a[id] > del) {//权值减少if (a[id] < mn) {//修改前低于较小值s2.modify(1, 1, totl, del + 1, a[id], 1);} else if (a[id] <= mx) {//修改前在两侧权值之间if (del < mn) {s2.modify(1, 1, totl, del + 1, mn, 1);}} else {//修改前在两侧权值上if (del >= mn) {//如果修改后不低于较小值s2.modify(1, 1, totl, max(mx, del) + 1, a[id], -1);} else {s2.modify(1, 1, totl, mx + 1, a[id], -1);s2.modify(1, 1, totl, del + 1, mn, 1);2 行未改动}}a[id] = del;} else {printf("%d\n", s2.query(1, 1, totl, q[i].val));//单点查询。}}return 0;}2 行未改动60 行未改动61626364656667686910 行未改动80818283848586878889909192939419 行未改动11411511611711811912012112274 行未改动1971981992002012022032042052062072082092102112122132142152163 行未改动2202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542 行未改动2572582592602612622632642652 行未改动60 行未改动return val < b.val;}};priority_queue<xwx> qu;void prework() {//离散化所有出现的权值。sort(lsh + 1, lsh + totl + 1);totl = unique(lsh + 1, lsh + totl + 1) - lsh - 1;for (int i = 1; i <= n; ++i) {10 行未改动int f[N];#define ls tr<<1#define rs tr<<1 | 1struct SegmentTree1 {//第一棵线段树,用来预处理 fstruct node {int lc, rc;int ans;} tree[N << 2];void push_up(int tr) {tree[tr].ans = tree[ls].ans + tree[rs].ans - (tree[ls].rc & tree[rs].lc);tree[tr].lc = tree[ls].lc;tree[tr].rc = tree[rs].rc;19 行未改动return tree[1].ans;}} s1;struct SegmentTree2 {//第二棵线段树,用来处理修改。struct node {int val, tag;} tree[N << 2];//这里R就是值域totl 了74 行未改动for (int i = 1; i <= m; ++i) {if (q[i].id) {int id = q[i].id, del = q[i].val;//这一部分建议结合曲线图来理解修改的区间(三个点的就够)if (id == 1) {//首尾两个点特殊照顾一下。if (a[id] < del) {//权值增加if (del > a[id + 1]) {//如果增加的范围超过了右侧点s2.modify(1, 1, totl, max(a[id + 1], a[id]) + 1, del, 1);}} else if (a[id] > del) {//权值减少if (a[id] > a[id + 1]) {//如果减少前权值比右侧点大s2.modify(1, 1, totl, max(a[id + 1], del) + 1, a[id], -1);}}} else if (id == n) {//和 id == 1 类似if (a[id] < del) {if (del > a[id - 1]) {s2.modify(1, 1, totl, max(a[id - 1], a[id]) + 1, del, 1);}3 行未改动}}} else {int mx = max(a[id - 1], a[id + 1]), mn = min(a[id - 1], a[id + 1]);//我们只关心两侧点中较大的和较小的值为多少if (a[id] < del) {//权值增加if (a[id] < mn) {//修改前比较小值还要小if (del <= mx) {//修改后没超过较大值s2.modify(1, 1, totl, a[id] + 1, min(del, mn), -1);} else {//超过了s2.modify(1, 1, totl, a[id] + 1, mn, -1);s2.modify(1, 1, totl, mx + 1, del, 1);}} else if (a[id] <= mx) {//修改前在两侧权值之间if (del > mx) {//只有修改后超过较大值才会更新答案s2.modify(1, 1, totl, mx + 1, del, 1);}} else {//修改前比较大值大s2.modify(1, 1, totl, a[id] + 1, del, 1);}} else if (a[id] > del) {//权值减少if (a[id] < mn) {//修改前低于较小值s2.modify(1, 1, totl, del + 1, a[id], 1);} else if (a[id] <= mx) {//修改前在两侧权值之间if (del < mn) {s2.modify(1, 1, totl, del + 1, mn, 1);}} else {//修改前在两侧权值上if (del >= mn) {//如果修改后不低于较小值s2.modify(1, 1, totl, max(mx, del) + 1, a[id], -1);} else {s2.modify(1, 1, totl, mx + 1, a[id], -1);s2.modify(1, 1, totl, del + 1, mn, 1);2 行未改动}}a[id] = del;} else {printf("%d\n", s2.query(1, 1, totl, q[i].val));//单点查询。}}return 0;}2 行未改动