yshen94's blog

By yshen94, history, 5 weeks ago, In English

As a newbie, I am just trying to solve Codeforces Round 977 C1.

Initially, I was thinking about any effective data structure. Then I saw some solutions submitted like below, and I just find it really difficult to comprehend. What is the best way to understand what the solution is doing.

int t,n,m,q,a,to[200005],b;

int main(){

scanf("%d",&t);

while(t--){

    scanf("%d%d%d",&n,&m,&q);

    for(int i=1;i<=n;i++)scanf("%d",&a),to[a]=i;

    int ans=1,cur=0;

    for(int i=1;i<=m;i++)scanf("%d",&b),ans&=(to[b]<=cur+1),cur=max(cur,to[b]);

    puts(ans?"YA":"TIDAK");

}

}

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by yshen94 (previous revision, new revision, compare).