QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#536425#8058. Binary vs Ternaryucup-team3591#RE 0ms0kbC++141.8kb2024-08-29 11:44:592024-08-29 11:44:59

Judging History

你现在查看的是最新测评结果

  • [2024-08-29 11:44:59]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-08-29 11:44:59]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
inline ll read(){
	ll x=0;
	int f=0,ch=0;
	while(ch<48||ch>57) f=(ch=='-'),ch=getchar();
	while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar();
	return f?-x:x;
}
inline void write(ll x,char end='\n'){
	if(x==0){
		putchar('0');
		putchar(end);
		return;
	}
	if(x<0) putchar('-'),x=-x;
	int ch[40]={0},cnt=0;
	while(x){
		ch[cnt++]=(int)(x%10);
		x/=10;
	}
	while(cnt--) putchar(ch[cnt]+48);
	putchar(end);
}
int pw[132][132],cnt[132];
inline void init(){
	pw[0][0]=1;
	cnt[0]=1;
	for(int i=1;i<=128;++i){
		for(int j=0;j<cnt[i-1];++j)
			pw[i][j]=pw[i-1][j]*3;
		cnt[i]=cnt[i-1];
		for(int j=0;j<cnt[i];++j)
			pw[i][j+1]+=pw[i][j]/2,pw[i][j]%=2;
		while(pw[i][cnt[i]]) pw[i][cnt[i]+1]+=pw[i][cnt[i]]/2,pw[i][cnt[i]]%=2,cnt[i]++;
	}
}
inline string to(string s){
	int a[132]={0},b[132]={0};
	int n=s.size(),m=cnt[n];
	for(int i=0;i<n;++i) a[i]=s[n-i-1]-'0';
	for(int i=0;i<n;++i){
		if(a[i]){
			for(int j=0;j<cnt[i];++j)
				b[j]+=pw[i][j];
		}
	}
	for(int i=0;i<m;++i) b[i+1]+=b[i]/2,b[i]%=2;
	while(b[m]) b[m+1]+=b[m]/2,b[m]%=2,++m;
	while(m>1&&b[m-1]==0) --m;
	s.clear();
	for(int i=m-1;i>=0;--i) s.push_back((char)(b[i]+'0'));
	return s;
}
inline void change(string &s,int l,int r){
	string t=s.substr(l,r-l+1);
	string beg=s.substr(0,l);
	if(r!=(int)s.size()-1){
		string ed=s.substr(r+1,s.size()-r-1);
		s.clear();
		s.append(beg);
		s.append(to(t));
		s.append(ed);
	}
	else{
		s.clear();
		s.append(beg);
		s.append(to(t));
	}
	cout<<s<<'\n';
}
inline void solve(){
	string s;
	cin>>s;
	int n;
	cin>>n;
	while(n--){
		int l,r;
		cin>>l>>r;
		change(s,l-1,r-1);
	}
	cout<<s<<'\n';
}
int main(){
	init();
	int T=read();
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
1
111
110110
1101010
1111
111111

output:


result: