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.
include<bits/stdc++.h>
using namespace std; 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"); } }