75pts 求调
查看原帖
75pts 求调
231022
1234567890regis楼主2024/11/30 16:28
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MAXN = 1e6 + 7, mod = 1e9 + 7;
unordered_map<int, int> mp;

pair<int, int> inp[MAXN];

int qpow(int u, int v)
{
	int res = 1;
	while (v)
	{
		if (v & 1) res = res * u % mod;
		u = u * u % mod;
		v >>= 1;
	}
	return res;
}

signed main()
{
	// freopen("assign.in", "r", stdin);
	// freopen("assign.out", "w", stdout);
	int t; scanf("%lld", &t);
	while (t--)
	{
		mp.clear();
		int n, m, v; scanf("%lld%lld%lld", &n, &m, &v); bool zero = false;
		for (int i = 1; i <= m; i++)
		{
			scanf("%lld%lld", &inp[i].first, &inp[i].second);
			if (mp[inp[i].first] != 0 && mp[inp[i].first] != inp[i].second) {
				zero = true;
				break;
			}
			mp[inp[i].first] = inp[i].second;
		}
		if (zero) {
			puts("0");
			continue;
		}
		sort(inp + 1, inp + m + 1);
		int res = qpow(v, 2 * inp[1].first - 2);
		int lst = 1;
		for (int i = 2; i <= m; i++)
		{
			int len = inp[i].first - inp[lst].first;
			if (len == 0) continue;
			res = res * ((qpow(v, 2 * len) - qpow(v, len) + qpow(v, len - 1) + mod) % mod) % mod;
			lst = i;
		}
		res = res * qpow(v, 2 * (n - inp[m].first)) % mod;
		printf("%lld\n", res);
	}
}
2024/11/30 16:28
加载中...