社区讨论

挂成92,WA on #2 #16求hack数据

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

讨论操作

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

当前回复
0 条
当前快照
1 份
快照标识符
@mi9tste4
此快照首次捕获于
2025/11/22 13:05
4 个月前
此快照最后确认于
2025/11/22 13:51
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int N = 1e6 + 20;
const int INF = 1e9;
const ll INFF = 1e18;

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<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}

int n;
int c[N], v[N], f[N], sum[N];
struct color{
	int l, r, w, tag;
}col[N];
bool cmp( color A , color B ){return A.l < B.l;}
int stk[N], top;
ll ans = INFF;
int main(){
//	freopen("interval8.in","r",stdin);
//	freopen("interval.out","w",stdout);
	n = read();
	for( int i = 1 ; i <= n ; ++i )col[i].l = col[i].r = INF; 
	for( int i = 1 ; i <= n ; ++i ){
		c[i] = read();
		col[c[i]].w++;
		if( col[c[i]].l == INF )col[c[i]].l = col[c[i]].r = i;
		col[c[i]].r = max(col[c[i]].r,i);
	}
	for( int i = 1 ; i <= n ; ++i )v[i] = read();
	for( int i = 1 ; i <= n ; ++i )f[i] = read();
	sort(col+1,col+n+1,cmp);
	for( int i = 1 ; i <= n ; ++i ){
		if( i != col[c[i]].r ) sum[i] = 1;
		else sum[i] = -(col[c[i]].w - 1);
	}
	for( int i = 1 ; i <= n ; ++i )sum[i] += sum[i-1];
	stk[++top] = 1;
	for( int i = 1 ; i <= n ; ++i ){
		if( col[i].l > col[stk[top]].r && top > 0 ){
			int lc = col[stk[top]].l, rc = col[stk[top]].r;
			if( col[stk[top]].w == rc - lc + 1 ){
				ll tmp = 0;
				for( int j = lc ; j <= rc ; ++j )tmp += v[j] * f[j - lc + 1];
				ans = min(ans, tmp);
				top--;
				if( col[i].r < col[stk[top]].r )stk[++top] = i;
				else{
					top = 1;
					stk[top] = i;
				}
			}
		}
		if( col[i].l == INF )break;
		while( col[stk[top]].r < col[i].r && top > 0 ){
			if( col[i].l < col[stk[top]].r ){
				col[i].l = min(col[i].l,col[stk[top]].l);
				col[i].r = max(col[i].r,col[stk[top]].r);
				col[i].w += col[stk[top]].w;
			}
			top--;
		}
		stk[++top] = i;
	}
	cout << ans << "\n";
	return 0;
}

回复

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

正在加载回复...