最后一个点过不去
#include <ctime>
#include <iostream>
#include <cassert>
#include <queue>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <bitset>
using namespace std;
#define debug puts("qwq")
#define open(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define close fclose(stdin);fclose(stdout);
#define all(x) x.begin(), x.end()
namespace FastIO {
template <typename T = int>
inline T read() {
T s = 0, w = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') w = -1;
c = getchar();
}
while (isdigit(c)) s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
return s * w;
}
template <typename T>
inline void read(T &s) {
s = 0;
int w = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') w = -1;
c = getchar();
}
while (isdigit(c)) s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
s = s * w;
}
template <typename T, typename... Args> inline void read(T &x, Args &...args) {
read(x), read(args...);
}
template <typename T>
inline void write(T x, char ch) {
if (x < 0) x = -x, putchar('-');
static char stk[25];
int top = 0;
do {
stk[top++] = x % 10 + '0', x /= 10;
} while (x);
while (top) putchar(stk[--top]);
putchar(ch);
return;
}
void quit() {
exit(0);
}
} using namespace FastIO;
const int mod = 1e9 + 7;
int ksm(int a, int b, int p) {
int res = 1;
while (b) {
if (b & 1) res = 1LL * res * a % p;
b >>= 1;
a = 1LL * a * a % p;
}
return res;
}
int sum[1000011], power[1000011];
vector<int> idx[1000011], idy[1000011];
struct node {
int x, y, val;
} a[1000011];
bitset<1000011> in;
signed main() {
int n, m; read(n, m);
int v = 10000;
for (int i = 1; i <= n; ++i) {
read(a[i].x, a[i].y, a[i].val);
idx[a[i].x].emplace_back(i);
}
for (int i = 1; i <= n; ++i) {
if (idx[i].size() >= v) in[i] = 1;
power[i] = 1;
}
for (int i = 1; i <= n; ++i) {
if (in[a[i].x] == 0) sum[a[i].y] =(sum[a[i].y] + a[i].val) % mod;
else idy[a[i].y].emplace_back(i);
}
while (m--) {
int opt, x, y;
read(opt);
if (opt == 1) {
read(x);
if (in[x] == 1) {
(power[x] <<= 1) %= (mod-1);
} else {
for (const auto i : idx[x]) {
sum[a[i].y] -= a[i].val;
a[i].val = a[i].val * 1LL * a[i].val % mod;
sum[a[i].y] = (a[i].val + sum[a[i].y]) % mod;
if (sum[a[i].y] < 0) sum[a[i].y] += mod;
}
}
} else {
read(y);
int ans = sum[y];
for (const auto i : idy[y]) {
ans = (ans + ksm(a[i].val, power[a[i].x], mod)) % mod;
}
write(ans, '\n');
}
}
return 0;
}