QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#66024 | #5110. Splitstream | rumen_m# | WA | 2ms | 9516kb | C++14 | 2.3kb | 2022-12-06 00:09:58 | 2022-12-06 00:10:01 |
Judging History
answer
# include <bits/stdc++.h>
const int MAXN = 1e6+5;
using namespace std;
struct step
{
char type;
int a,b,c;
};
step w[MAXN];
int from[MAXN],to[MAXN],sz[MAXN];
bool fl[MAXN];
void bfs()
{
queue <int> q;
q.push(1);
while(!q.empty())
{
int x = q.front();
q.pop();
//cout<<x<<endl;
int id = to[x];
if(id==0)continue;
if(fl[x])continue;
fl[x] = 1;
if(w[id].type == 'S')
{
//cout<<"OK"<<endl;
sz[w[id].b] = (sz[x]+1)/2;
sz[w[id].c] = (sz[x]/2);
q.push(w[id].b);
q.push(w[id].c);
}
else
{
sz[w[id].c] = sz[w[id].a] + sz[w[id].b];
// cout<<w[id].c<<" --> "<<sz[w[id].c]<<endl;
q.push(w[id].c);
}
}
}
int findit(int x, int k)
{
//cout<<x<<" && "<<k<<" "<<sz[x]<<endl;
if(x == 1) return k;
int id = from[x];
if(w[id].type == 'M')
{
int a = w[id].a;
int b = w[id].b;
if(2*min(sz[a],sz[b])>=k)
{
// cout<<"Here"<<endl;
if(k%2 == 0)
{
return findit(b,k/2);
}
else
return findit(a,(k+1)/2);
}else
{
if(sz[a] < sz[b])
{
return findit(b,k-sz[a]);
}
else
return findit(a, k-sz[b]);
}
}
else
{
int a = w[id].a;
int b = w[id].b;
int c = w[id].c;
if(b==x)
{
return findit(a,k*2-1);
}
else
return findit(a,k*2);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n,q,m,i,j;
cin>>m>>n>>q;
for(i = 1;i<=q;i++)
{
cin>>w[i].type>>w[i].a>>w[i].b>>w[i].c;
if(w[i].type == 'S')
{
to[w[i].a] = i;
from[w[i].b] = i;
from[w[i].c] = i;
}
else
{
to[w[i].a] = i;
to[w[i].b] = i;
from[w[i].c] = i;
}
}
sz[1] = m;
bfs();
int x,k;
for(i = 1;i<=q;i++)
{
cin>>x>>k;
cout<<findit(x,k)<<endl;;
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9516kb
input:
5 8 26 M 8 9 13 S 2 4 5 S 1 2 3 M 6 5 8 S 4 9 10 S 10 14 15 S 3 6 7 S 7 11 12 2 3 2 4 3 2 3 3 4 2 4 3 5 1 5 2 6 1 6 2 7 1 7 2 8 2 8 3 9 1 9 2 10 1 10 2 11 1 11 2 12 1 13 3 13 4 14 1 14 2 15 1
output:
163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584 163584
result:
wrong answer 1st lines differ - expected: '5', found: '163584'