求调
  • 板块P10508 质因子
  • 楼主Escapism
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/5/19 17:23
  • 上次更新2024/5/19 18:13:10
查看原帖
求调
361505
Escapism楼主2024/5/19 17:23

RT,赛时过了大样例,然后保龄了。

记录

#include<bits/stdc++.h>
using namespace std;

long long a[40],n,q;
long long p3[40] = {1,3,9,27,81,243,729,2187,6561,19683,59049,177147,531441,1594323,4782969,14348907,43046721,129140163,387420489,1162261467,3486784401,10460353203,31381059609,94143178827,282429536481,847288609443,2541865828329,7625597484987,22876792454961,68630377364883,205891132094649,617673396283947,1853020188851841,5559060566555523,16677181699666569,50031545098999707,150094635296999121,450283905890997363};
void stn(long long x) {
	long long t = x,cur = 0;
	while (t != 0) a[cur++] = t % 3,t /= 3;
}
int main(){
	cin>>n>>q;
	stn(n);
	while(q--){
		long long op,x,y;
		cin>>op>>x;
		if (op == 1){
			if (a[x] == 0) y = 1;
			if (a[x] == 1) y = 2;
			if (a[x] == 2) y = 0;
		}
		if (op == 2){
			if (a[x] == 0) y = 2;
			if (a[x] == 1) y = 0;
			if (a[x] == 2) y = 1;
		}
		if (op == 3){
			if (a[x] == 1) y = 2;
			if (a[x] == 2) y = 1;
		}
		n = n - a[x] * p3[x] + y *  p3[x];
		cout<<n<<endl;
		a[x] = y;
	}
}
2024/5/19 17:23
加载中...