社区讨论

求HACK栈做法的数据

P14567【MX-S12-T2】区间参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@mif6h5wy
此快照首次捕获于
2025/11/26 06:59
3 个月前
此快照最后确认于
2025/11/26 10:43
3 个月前
查看原帖
RT
被hack了一个点,找不到问题
代码
CPP
#include<bits/stdc++.h>
#define LL long long
using namespace std;
inline int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9') {
        if(ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch<='9')
        x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}
int n, i;
int a[1000100];
LL val[1000100], f[1000100];
int e[1000100], pos[1000100];
bool h[1000100], g[1000100];
LL mi = 1e18;
int top;
int stk[1000100], id[1000100];
void get(int l, int r) {
	LL ans = 0;
	for (int i = l; i <= r; ++i)
		ans += val[i] * f[i - l + 1];
	mi = min(mi, ans);
}
int main () {
//	freopen("interval/interval8.in", "r", stdin);
//	freopen("interval.out", "w", stdout);
	n = read();
	for (i = 1; i <= n; ++i) a[i] = read();
	for (i = 1; i <= n; ++i) val[i] = 1ll * read(), ++e[a[i]], h[a[i]] = 1;
	for (i = 1; i <= n; ++i) f[i] = 1ll * read();
	for (i = 1; i <= n; ++i) {
		int x = a[i];
		if(h[x] == 1) pos[x] = i, h[x] = 0;
		stk[++top] = x; id[top] = i; --e[x];
		bool flag = false;
		while(top > 0 && e[stk[top]] == 0)
			--top, flag = true;
		if(flag && e[stk[top + 1]] == 0 && pos[stk[top + 1]] == id[top + 1]) {
			get(id[top + 1], i);
			while(top > 0) g[stk[top]] = 1, --top;
		}
	}
	printf("%lld", mi);
}

回复

1 条回复,欢迎继续交流。

正在加载回复...