1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| void solve(){ int n = read(); for(int i = 1; i <= n; ++ i) a[i] = read(); for(int i = 1; i <= n; ++ i) b[i] = read(); stack<int> stk; int idx = 1; for(int i = 1; i <= n; ++ i){ stk.push(a[i]); while(stk.size() && stk.top() == b[idx]){ ++ idx; stk.pop(); } } if(stk.size() == 0){ cout << "Yes" << endl; } else cout << "No" << endl; }
|