神秘,求解释
查看原帖
神秘,求解释
808222
Kotobuki_Tsumugi楼主2024/5/19 13:48

见注释。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll v,q,a[50],cnt,P[50];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>v>>q;
	while(v != 0){
		a[cnt++] = v%3;
		v /= 3;
	}
	P[0] = 1;
	for(int i = 1;i<=49;i++)
		P[i] = P[i-1] * 3;
	while(q--){
		ll opx,x;
		cin>>opx>>x;
		cnt = max(cnt,x+1);
		if(opx == 1) a[x] = (a[x]+1)%3;
		if(opx == 2) a[x] = (a[x]+2)%3;
		if(opx == 3) a[x] = (3-a[x])%3;//这样写AC
		/*if(opx == 3){				   //注释掉的这一部分是我的赛时代码,全WA
			if(a[x] == 1) a[x]++;
			if(a[x] == 2) a[x]--;
		}*/
		ll ans = 0;
		for(int i = 0;i<cnt;i++)
			ans += a[i]*P[i];
		cout<<ans<<endl;
	}
	return 0;
}
2024/5/19 13:48
加载中...