其他分享
首页 > 其他分享> > 20210720

20210720

作者:互联网

Game

code
const int N = 1e5+5;
int n,T,a[N],p;

int mx,lsh[N],cnt[N];

void solve() {
	LL ans = 0;
	read(p);
	for(int i = 1; i < p; ++i) {
		++cnt[a[i]];
		if( a[i] > mx ) mx = a[i];
	}
	int f = 1;
	for(int i = p; i <= n; ++i, f = -f) {
		if( a[i] >= mx ) { ans += f * lsh[a[i]]; continue; }
		++cnt[a[i]];
		while( !cnt[mx] ) --mx;
		ans += f * lsh[mx], --cnt[mx];
	}
	for(int i = 1; i < p; ++i, f = -f) {
		while( !cnt[mx] ) --mx;
		ans += f * lsh[mx], --cnt[mx];
	}
	write(ans);
}

signed main() {
	read(n,T);
	For(i,1,n) read(a[i]), lsh[i] = a[i];
	sort(lsh+1,lsh+n+1), lsh[0] = unique(lsh+1,lsh+n+1)-lsh-1;
	For(i,1,n) a[i] = lower_bound(lsh+1,lsh+lsh[0]+1,a[i])-lsh;
	while( T-- ) solve();
	return iocl();
}

标签:20210720,cnt,int,lsh,--,ans,mx
来源: https://www.cnblogs.com/401rk8/p/noip0720.html