Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #ifdef ERFANUL007
- #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
- template < typename Arg1 >
- void __f(const char* name, Arg1&& arg1){
- cout << name << " = " << arg1 << std::endl;
- }
- template < typename Arg1, typename... Args>
- void __f(const char* names, Arg1&& arg1, Args&&... args){
- const char* comma = strchr(names, ',');
- cout.write(names, comma - names) << " = " << arg1 <<" | ";
- __f(comma+1, args...);
- }
- #else
- #define debug(...)
- #endif
- int main(){
- #ifdef ERFANUL007
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n;
- while(cin >> n && n){
- int a[n];
- while(1){
- cin >> a[0];
- if(!a[0]) break;
- for(int i=1; i<n; i++) cin >> a[i];
- bool vis[n], f = true;
- memset(vis, 0, sizeof(vis));
- int last = 0;
- priority_queue<int> pq;
- for(int i=0; i<n; i++){
- if(a[i] > last){
- int x = a[i] - 1;
- while(x > last){
- if(!vis[x]) pq.push(x);
- x--;
- }
- vis[a[i]] = true;
- last = a[i];
- }
- else{
- if(pq.top() != a[i]) f = false;
- vis[a[i]] = true;
- pq.pop();
- }
- }
- if(f) cout<< "Yes\n";
- else cout << "No\n";
- }
- cout << '\n';
- }
- #ifdef ERFANUL007
- fprintf(stderr, ">>> Runtime : %.9f\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement