QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#68884 | #5110. Splitstream | zhangboju | WA | 2ms | 3584kb | C++17 | 1.4kb | 2022-12-21 16:47:23 | 2022-12-21 16:47:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x)
{
x=0;short f=1;char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
x*=f;return;
}
const int N=1e4+5;
int m,n,q;
array<int,4>a[N];
int in[N],out[N];
int siz[N];
void work(int x,int v)
{
siz[x]=v;
if(!in[x]) return;
auto p=a[in[x]];
if(siz[p[0]]==-1||siz[p[1]]==-1) return;
if(p[1]) work(p[2],siz[p[0]]+siz[p[1]]);
else
{
work(p[2],(siz[p[0]]+1)/2);
work(p[3],siz[p[0]]/2);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>m>>n>>q;
int maxx=0;
for(int i=1;i<=n;++i)
{
char ch;int x,y,z;
cin>>ch>>x>>y>>z;
maxx=max({maxx,x,y,z});
if(ch=='S') a[i]={x,0,y,z};
else a[i]={x,y,z,0};
}
for(int i=1;i<=n;++i)
in[a[i][0]]=in[a[i][1]]=out[a[i][2]]=out[a[i][3]]=i;
memset(siz,-1,sizeof siz);
siz[0]=0;
work(1,m);
for(int i=2;i<=maxx;++i)
if(!out[i]) work(i,0);
while(q--)
{
int x,k;cin>>x>>k;
if(k>siz[x])
{
cout<<"none\n";
continue;
}
while(x!=1)
{
auto p=a[out[x]];
if(p[1])
{
int t=min(siz[p[0]],siz[p[1]]);
if(k<=2*t)
{
x=p[!(k%2)];
k=(k+1)/2;
}
else
{
x=p[siz[p[1]]>siz[p[0]]];
k-=t;
}
}
else
{
k=2*k-(p[2]==x);
x=p[0];
}
}
cout<<k<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3584kb
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:
5 none 4 none 5 none 3 none 2 none 4 none 3 none 1 none 5 none 4 none none 3 none 5 none none
result:
ok 26 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3564kb
input:
1000000000 8191 1000 S 1 2 3 S 2 4 5 S 3 6 7 S 4 8 9 S 5 10 11 S 6 12 13 S 7 14 15 S 8 16 17 S 9 18 19 S 10 20 21 S 11 22 23 S 12 24 25 S 13 26 27 S 14 28 29 S 15 30 31 S 16 32 33 S 17 34 35 S 18 36 37 S 19 38 39 S 20 40 41 S 21 42 43 S 22 44 45 S 23 46 47 S 24 48 49 S 25 50 51 S 26 52 53 S 27 54 55...
output:
none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none none ...
result:
wrong answer 1st lines differ - expected: '1', found: 'none'