UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196352#2654. 规划tkswls1001759ms25488kbC++112.0kb2023-10-22 11:17:182023-10-22 12:07:35

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, m, a[200005], sum[200005], f[200005];
struct que {
	int l, r, k;
} c[200005];
bool cmp(que p, que q) {
	return p.r < q.r;
}
struct node {
	int l, r, maxn, tag;
} b[800005];
inline void update(int p) {
	b[p].maxn = max(b[2 * p].maxn, b[2 * p + 1].maxn);
}
inline void push_down(int p) {
	if (b[p].r - b[p].l && b[p].tag != 0) {
		b[2 * p].maxn += b[p].tag;
		b[2 * p + 1].maxn += b[p].tag;
		b[2 * p].tag += b[p].tag;
		b[2 * p + 1].tag += b[p].tag;
		b[p].tag = 0;
	}
}
inline void build(int p, int l, int r) {
	b[p].l = l;
	b[p].r = r;
	b[p].tag = 0;
	b[p].maxn = 0;
	if (l == r) return;
	build(2 * p, l, (l + r) >> 1);
	build(2 * p + 1, ((l + r) >> 1) + 1, r);
}
inline void add(int p, int l, int r, int w) {
	if (b[p].l >= l && b[p].r <= r) {
		b[p].tag += w;
		b[p].maxn += w;
		return;
	}
	push_down(p);
	int mid = (b[p].l + b[p].r) >> 1;
	if (r <= mid) add(2 * p, l, r, w);
	else if (l > mid) add(2 * p + 1, l, r, w);
	else add(2 * p, l, mid, w), add(2 * p + 1, mid + 1, r, w);
	update(p);
}
inline int query(int p, int l, int r) {
	if (b[p].l >= l && b[p].r <= r) {
		return b[p].maxn;
	}
	int mid = (b[p].l + b[p].r) >> 1;
	if (r <= mid) return query(2 * p, l, r);
	else if (l > mid) return query(2 * p + 1, l, r);
	return max(query(2 * p, l, mid), query(2 * p + 1, mid + 1, r));
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= m; i++) {
		cin >> c[i].l >> c[i].r >> c[i].k;
	}
	sort(c + 1, c + m + 1, cmp);
	int cnt = 0;
	build(1, 1, n);
	for (int i = 1; i <= n; i++) {
		add(1, 1, i, -a[i]);
		while (c[cnt + 1].r <= i && cnt < m) {
			add(1, 1, c[cnt + 1].l, c[cnt + 1].k);
			cnt++;
		}
		f[i] = max(0ll, f[i - 1]);
		f[i] = max(f[i], query(1, 1, i));
		if (i < n) {
			add(1, i + 1, i + 1, f[i]);
		}
	}
	cout << f[n];
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 98ms
memory: 6296kb

input:

4000 200000
785569201
332099451
285474404
489840630
1446649459
27606079
118902001
1226139097
4667266...

output:

210373355705241

result:

ok single line: '210373355705241'

Test #2:

score: 10
Accepted
time: 100ms
memory: 6296kb

input:

4000 200000
785586008
614574700
1908124477
1474784288
443274742
497817351
219929545
536506328
192550...

output:

210501237297309

result:

ok single line: '210501237297309'

Test #3:

score: 10
Accepted
time: 101ms
memory: 6292kb

input:

4000 200000
785602815
897049949
1383290903
312244299
1587383672
968028623
320957089
1994357206
12367...

output:

210364978400796

result:

ok single line: '210364978400796'

Test #4:

score: 10
Accepted
time: 91ms
memory: 6296kb

input:

4000 200000
785636429
1462000447
333623755
134647968
1728117885
1908451167
523012177
615091668
20068...

output:

210676576159754

result:

ok single line: '210676576159754'

Test #5:

score: 10
Accepted
time: 222ms
memory: 25488kb

input:

200000 200000
692962631
819121536
1605478282
141461019
270949104
1176259288
1802882781
56641097
6316...

output:

2502289049

result:

ok single line: '2502289049'

Test #6:

score: 10
Accepted
time: 240ms
memory: 25484kb

input:

200000 200000
692996245
1384072034
555811134
2111348335
411683317
2116681832
2004937869
824859206
14...

output:

1218457552

result:

ok single line: '1218457552'

Test #7:

score: 10
Accepted
time: 233ms
memory: 25484kb

input:

200000 200000
693013052
1666547283
30977560
948808346
1555792247
439409457
2105965413
135226437
7130...

output:

789489032

result:

ok single line: '789489032'

Test #8:

score: 10
Accepted
time: 227ms
memory: 25488kb

input:

200000 200000
693046666
84014134
1128794059
771212015
1696526460
1379832001
160536854
903444546
1483...

output:

687915790363

result:

ok single line: '687915790363'

Test #9:

score: 10
Accepted
time: 232ms
memory: 25476kb

input:

200000 200000
693080280
648964632
79126911
593615684
1837260673
172770898
362591942
1671662655
10568...

output:

0

result:

ok single line: '0'

Test #10:

score: 10
Accepted
time: 215ms
memory: 25484kb

input:

200000 200000
693097087
931439881
1701776984
1578559342
833885956
642982170
463619486
982029886
1564...

output:

517569170

result:

ok single line: '517569170'