Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define forn(l, r) for(int i = l; i < (r); ++i)
- #define forj(l, r) for(int j = l; j < (r); ++j)
- #define TAM 1000100
- #define SYNC ios::sync_with_stdio(0);
- #define $ << ' ' <<
- #define F first
- #define S second
- #define endl '\n'
- using namespace std;
- using ll = long long int;
- using ii = pair<int, int>;
- using vii = vector<ii>;
- using vi = vector<int>;
- using graph = vector<vi>;
- const int INF = 0x3f3f3f3f;
- const int MAXN = 112345;
- const ll mod = 1000000007;
- int main() {
- //SYNC
- vector<string> ans;
- stack<int> ptA, stt;
- queue<int> ptB;
- int n, vag;
- while (cin >> n && n) {
- while (cin >> vag && vag) {
- while(!ptA.empty()) ptA.pop();
- while(!ptB.empty()) ptB.pop();
- while(!stt.empty()) stt.pop();
- for (int i = n; i > 0; --i) {
- ptA.push(i);
- }
- ptB.push(vag);
- for (int i = 1; i < n; ++i) {
- int j;
- cin >> j;
- ptB.push(j);
- }
- while (!ptA.empty()) {
- //cout << "x\n";
- stt.push(ptA.top());
- ptA.pop();
- //cout << stt.top() << ' ' << ptB.front() << endl;
- while (!stt.empty() && stt.top() == ptB.front()) {
- stt.pop();
- ptB.pop();
- }
- }
- if (stt.empty()) ans.push_back("Yes");
- else ans.push_back("No");
- }
- if (!vag) {
- ans.push_back("");
- }
- }
- for (auto x : ans) {
- cout << x << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment