大样例过了,但全wa了,求调

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int unsigned long long
int shu[1000010];
int ans[100010];
int f[100010];
signed main() {
// ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
int v, q;
cin >> v >> q;
int tt = 0, n = v;
while (n) {
shu[++tt] = n % 3;
n /= 3;
}
for (int i = 1; i <= tt; i++) {
ans[i] = shu[i];
}
for (int i = 1; i <= q; i++) {
int op, x;
cin >> op >> x;
x++;
tt = max(tt, x);
if (op == 1) {
ans[x]++;
ans[x] %= 3;
}
if (op == 2) {
ans[x] += 2;
ans[x] %= 3;
}
if (op == 3) {
if (ans[x] == 1)ans[x]++;
if (ans[x] == 2)ans[x]--;
}
int sum = 0;
for (int j = 1000; j >= 1; j--) {
sum = sum*3+ans[j];
}
cout << sum << '\n';
}
//return cerr << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl, 0;
return 0;
}