이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,a[200005],k,trie[1000006][4];
string ans;
string to(int x)
{
string s;
while(x)
{
s.push_back('0'+(x%2));
x/=2;
}
while(s.size()!=32)s.push_back('0');
reverse(s.begin(),s.end());
return s;
}
int too(string s)
{
int x=0;
for(int i=0;i<s.size();i++)
{
x*=2;
if(s[i]=='1')x++;
}
return x;
}
void ad(string s)
{
int nod=0;
for(int i=0;i<s.size();i++)
{
int x=s[i]-'0';
if(trie[nod][x]==0)trie[nod][x]=++k;
nod=trie[nod][x];
}
}
void dfs(int x,int nod,string s)
{
if(s[x]=='0')
{
if(trie[nod][1])
{
dfs(x+1,trie[nod][1],s);
ans[x]='1';
}
else if(trie[nod][0])
{
dfs(x+1,trie[nod][0],s);
}
}
if(s[x]=='1')
{
if(trie[nod][0])
{
dfs(x+1,trie[nod][0],s);
}
else if(trie[nod][1])
{
dfs(x+1,trie[nod][1],s);
ans[x]='0';
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen("gpsduel.in","r",stdin);
//freopen("gpsduel.out","w",stdout);
cin>>n;
for(int i=0;i<n;i++)
{
string s;
int x,y;
cin>>s>>x>>y;
if(s=="Add")
{
a[i+2]=a[x]^y;
string st=to(a[i+2]);
ad(st);
}
else
{
int b=a[x]^a[y];
ans=to(b);
dfs(0,0,ans);
cout<<too(ans)<<endl;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
klasika.cpp: In function 'int too(std::__cxx11::string)':
klasika.cpp:21:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<s.size();i++)
~^~~~~~~~~
klasika.cpp: In function 'void ad(std::__cxx11::string)':
klasika.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<s.size();i++)
~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |