求助
查看原帖
求助
968339
suiyuea4楼主2023/9/25 19:00
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, ans;
typedef struct data {
	int xu;
	int num;
	int col;
}Data;
bool cmp(Data x, Data y) {
	if (x.col == y.col) {
		return x.xu < y.xu;
	}
	else {
		return x.col < y.col;
	}
}
int main() {
	cin >> n >> m;

	Data a[100005];
	for (int i = 1; i <= n; i++) {
		cin >> a[i].num;
		a[i].xu = i;
	}
	for (int i = 1; i <= n; i++) {
		cin >> a[i].col;
	}
	sort(a + 1, a + n + 1, cmp);

	int r = 0;
	for (int i = 1; i <= n; i = r + 1) {
		Data c[80005], g[80005];
		int cnt1 = 0, cnt2 = 0;
		while (a[i].col == a[r + 1].col) {
			r++;
			if (a[r].xu % 2 == 0) {
				c[++cnt1] = a[r];
			}
			else {
				g[++cnt2] = a[r];
			}
		}
		int tot = 0;
		for (int j = 1; j <= cnt1; j++) {
			tot = (tot + c[j].num % 10007) % 10007;
		}
		for (int j = 1; j <= cnt1; j++) {
			int sum = (a[j].xu % 10007 * ((cnt1 - 2) * c[j].num % 10007 + tot) % 10007) % 10007;
			ans = (ans + sum) % 10007;
		}
		tot = 0;
		for (int j = 1; j <= cnt2; j++) {
			tot = (tot + g[j].num % 10007) % 10007;
		}
		for (int j = 1; j <= cnt2; j++) {
			int sum = (a[j].xu % 10007 * ((cnt2 - 2) * g[j].num % 10007 + tot) % 10007) % 10007;
			ans = (ans + sum) % 10007;
		}
	}
	cout << ans << endl;
	return 0;
}

帮忙看看吧,我要破防了

2023/9/25 19:00
加载中...