入门题暴力写挂求调
查看原帖
入门题暴力写挂求调
424089
LuoTianyi_Official楼主2024/1/7 18:23

。。。

#include <iostream>
#include <vector>
using namespace std;
long long qp(long long n, long long m, long long p) {
	long long ans = 1, base = n;
	while (m) {
		if (m & 1) (ans *= base) %= p;
		(base *= base) %= p;
		m >>= 1;
	}
	return ans;
}
vector<int> Cubic[1000005], qwasd[1000005], rzh;
int t[1000005];
long long summ[1000005];
signed main() {
	int n, m, x, y, v, op, bl=1;
	cin >> n >> m;
	for (int i=1; i<=n; i++) {
		cin >> x >> y >> v, Cubic[y].push_back(x), qwasd[y].push_back(v), summ[y] += v;
		if (Cubic[y].size() == bl) rzh.push_back(y);
	}
	for (int i=1; i<=m; i++) {
		cin >> op >> x;
		if (op == 1) {
			for (int i: rzh) {
				auto sc84bbs = lower_bound(Cubic[i].begin(), Cubic[i].end(), x);
				if (sc84bbs != Cubic[i].end() && *sc84bbs == x) summ[i] += (long long)qwasd[i][sc84bbs-Cubic[i].begin()] * qwasd[i][sc84bbs-Cubic[i].begin()] % (int)(1e9+7) - qwasd[i][sc84bbs-Cubic[i].begin()], qwasd[i][sc84bbs-Cubic[i].begin()] = (long long)qwasd[i][sc84bbs-Cubic[i].begin()] * qwasd[i][sc84bbs-Cubic[i].begin()] % (int)(1e9+7);
			}
			t[x]++;
			continue;
		}
		if (Cubic[x].size() >= bl) cout << summ[x] % (int)(1e9+7); else {
			long long qwq=0;
			for (int i=0; i<Cubic[x].size(); i++) qwq += qp(qwasd[x][i], qp(2, t[Cubic[x][i]], (int)(1e9+6)), (int)(1e9+7));
			cout << qwq % (int)(1e9+7);
		}
		cout << endl;
	}
}
2024/1/7 18:23
加载中...