Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <memory.h>
- #include <iterator>
- #include <cassert>
- #include <fstream>
- #include <iomanip>
- #include <cstdlib>
- #include <bitset>
- #include <vector>
- #include <cstdio>
- #include <string>
- #include <queue>
- #include <deque>
- #include <cmath>
- #include <ctime>
- #include <stack>
- #include <set>
- #include <map>
- //#include <tuple>
- //#include <typeinfo>
- using namespace std;
- #define fi first
- #define se second
- #define pb push_back
- #define mp make_pair
- #define all(x) x.begin() , x.end()
- typedef long long ll;
- typedef long double ld;
- typedef pair < ll , ll > pll;
- typedef pair < int , int > pii;
- template < typename T >
- T read(){
- T p = 1 , x = 0;
- char s = getchar();
- while(s == ' ' || s == '\n') s = getchar();
- if(s == '-') p = -1 , s = getchar();
- while(s >= '0' && s <= '9'){
- x = x * 10 + s - '0';
- s = getchar();
- }
- return x * p;
- }
- template < typename A , typename B >
- void Umax(A &a , const B &b){
- if(a < b)
- a = b;
- }
- template < typename A , typename B >
- void Umin(A &a , const B &b){
- if(a > b){
- a = b;
- }
- }
- ll bin_pow (ll a , ll n) {
- if(n == 0){
- return 1;
- }
- if(n % 2 == 1){
- ll cnt = a * bin_pow(a , n - 1);
- return cnt;
- }
- else {
- ll cnt = bin_pow(a , n / 2);
- return cnt * cnt;
- }
- }
- const int N = (int) 1e6 + 10;
- const int MOD = (int) 1e9 + 7;
- const int INF = (int) 1e9 + 10;
- const ll LLINF = (ll) 1e18 + 10;
- set <int> zz;
- map <int, pair<int, bool>> m;
- int main () {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- for(int i = 0; i < n; ++i) {
- int x; cin >> x;
- //cout << x << endl;
- if(m[x].se == false) {
- m[x] = mp(i, true);
- zz.insert(x);
- } else {
- auto t = m[x];
- auto f = *zz.begin();
- //cout << t.fi << ' ' << ' ' << f << endl;
- if((i - t.fi + 1) % 2 == 0 && f == x) {
- m[x] = mp(0, false);
- zz.erase(f);
- } else {
- cout << "NO" << endl;
- return 0;
- }
- }
- }
- int cnt = 0;
- for(const auto &it : m) {
- if(it.se.se == true) cnt++;
- }
- if(cnt <= 1) {
- cout << "YES" << endl;
- } else {
- cout << "NO" << endl;
- }
- return 0;
- }
- //qwerty
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement