首页 > 其他分享 >BZOJ 3747: [POI2015]Kinoman

BZOJ 3747: [POI2015]Kinoman

时间:2022-10-25 15:34:41浏览次数:64  
标签:pre int 3747 ll tree POI2015 Kinoman ans include


题目链接:​​传送门​

好像之前在洛谷上做过一个叫KIN的题
一个电影看多次就不会记贡献
那么这个电影产生贡献的区间就是(这一次看)到(上一次看的后一天)
在这一块内才会记录它的贡献
再往前要在(上一次看的上一次的后一天)到(上一次看的后一天)这段区间减去贡献
因为对于那个时间段这个电影已经产生不了贡献了
这题做法很多
看了一些做法感觉单点修改的最好理解

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define

using namespace std;
typedef long long ll;
struct node {
int l, r; ll w, f;
}tree[A];
void down(int k) {
tree[k << 1].f += tree[k].f;
tree[k << 1 | 1].f += tree[k].f;
tree[k << 1].w += tree[k].f;
tree[k << 1 | 1].w += tree[k].f;
tree[k].f = 0;
}
void build(int k, int l, int r) {
tree[k].l = l; tree[k].r = r;
if (l == r) {
tree[k].w = tree[k].f = 0;
return;
}
int m = (l + r) >> 1;
build(k << 1, l, m);
build(k << 1 | 1, m + 1, r);
}
void change(int k, int l, int r, ll val) {
if (tree[k].l >= l and tree[k].r <= r) {
tree[k].w += val; tree[k].f += val;
return;
}
if (tree[k].f) down(k);
int m = (tree[k].l + tree[k].r) >> 1;
if (l <= m) change(k << 1, l, r, val);
if (r > m) change(k << 1 | 1, l, r, val);
tree[k].w = max(tree[k << 1].w, tree[k << 1 | 1].w);
}
ll ask(int k, int l, int r) {
if (tree[k].l >= l and tree[k].r <= r) return tree[k].w;
int m = (tree[k].l + tree[k].r) >> 1; ll ans = 0;
if (tree[k].f) down(k);
if (l <= m) ans = max(ans, ask(k << 1, l, r));
if (r > m) ans = max(ans, ask(k << 1 | 1, l, r));
return ans;
}
int n, m, pos[A], lst[A], pre[A]; ll ans, w[A];

int main(int argc, char const *argv[]) {
scanf("%d%d", &n, &m); build(1, 1, n);
for (int i = 1; i <= n; i++) scanf("%d", &pos[i]);
for (int i = 1; i <= m; i++) scanf("%lld", &w[i]);
for (int i = 1; i <= n; i++) pre[i] = lst[pos[i]], lst[pos[i]] = i;
for (int i = 1; i <= n; i++) {
ans = max(ans, tree[1].w);
change(1, pre[i] + 1, i, w[pos[i]]);
if (pre[i]) change(1, pre[pre[i]] + 1, pre[i], -w[pos[i]]);
ans = max(ans, ask(1, 1, i));
}
printf("%lld\n", ans);
return 0;
}


标签:pre,int,3747,ll,tree,POI2015,Kinoman,ans,include
From: https://blog.51cto.com/lyle/5794782

相关文章

  • 【题解】P3583 [POI2015] KWA
    模拟赛出这道题???还好赛时乱搞做出来了(/hanxlinkDescription定义一个数\(n\)的拆分为:将\(n\)表示为若干个不同的正整数的平方和。令\(k(n)\)为\(n\)的拆分中最......
  • POI2015 合集
    KUR题面考虑小串会在大串的哪些位置出现,然后就是设小串开头的位置为\(x\),然后小串第\(i\)个位置如果\(a_i=0\),则\(0\leqa(x+i)+b<p(\modn)\),\(a_i=1\)同理,然......
  • P3592 [POI2015] MYJ 洗车店
    P3592[POI2015]MYJ洗车店点击查看代码//此题与人的区间[a,b]有关:区间DP;将[l,p-1],[p+1][r]的区间递归计算,经过p的区间//f[l][r][k]表示l<=a<=b<=r的洗车店的价......