Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <memory.h>
  4. #include <iterator>
  5. #include <cassert>
  6. #include <fstream>
  7. #include <iomanip>
  8. #include <cstdlib>
  9. #include <bitset>
  10. #include <vector>
  11. #include <cstdio>
  12. #include <string>
  13. #include <queue>
  14. #include <deque>
  15. #include <cmath>
  16. #include <ctime>
  17. #include <stack>
  18. #include <set>
  19. #include <map>
  20.  
  21. //#include <tuple>
  22. //#include <typeinfo>
  23.  
  24. using namespace std;
  25.  
  26. #define fi first
  27. #define se second
  28. #define pb push_back
  29. #define mp make_pair
  30. #define all(x) x.begin() , x.end()
  31.  
  32. typedef long long ll;
  33. typedef long double ld;
  34. typedef pair < ll , ll > pll;
  35. typedef pair < int , int > pii;
  36.  
  37. template < typename T >
  38. T read(){
  39. T p = 1 , x = 0;
  40. char s = getchar();
  41. while(s == ' ' || s == '\n') s = getchar();
  42. if(s == '-') p = -1 , s = getchar();
  43. while(s >= '0' && s <= '9'){
  44. x = x * 10 + s - '0';
  45. s = getchar();
  46. }
  47. return x * p;
  48. }
  49.  
  50. template < typename A , typename B >
  51. void Umax(A &a , const B &b){
  52. if(a < b)
  53. a = b;
  54. }
  55.  
  56. template < typename A , typename B >
  57. void Umin(A &a , const B &b){
  58. if(a > b){
  59. a = b;
  60. }
  61. }
  62.  
  63. ll bin_pow (ll a , ll n) {
  64. if(n == 0){
  65. return 1;
  66. }
  67. if(n % 2 == 1){
  68. ll cnt = a * bin_pow(a , n - 1);
  69. return cnt;
  70. }
  71. else {
  72. ll cnt = bin_pow(a , n / 2);
  73. return cnt * cnt;
  74. }
  75. }
  76.  
  77. const int N = (int) 1e6 + 10;
  78. const int MOD = (int) 1e9 + 7;
  79. const int INF = (int) 1e9 + 10;
  80. const ll LLINF = (ll) 1e18 + 10;
  81.  
  82. set <int> zz;
  83. map <int, pair<int, bool>> m;
  84.  
  85. int main () {
  86.  
  87. ios_base::sync_with_stdio(false);
  88.  
  89. int n;
  90. cin >> n;
  91.  
  92. for(int i = 0; i < n; ++i) {
  93. int x; cin >> x;
  94.  
  95. //cout << x << endl;
  96.  
  97. if(m[x].se == false) {
  98. m[x] = mp(i, true);
  99. zz.insert(x);
  100. } else {
  101. auto t = m[x];
  102. auto f = *zz.begin();
  103.  
  104. //cout << t.fi << ' ' << ' ' << f << endl;
  105.  
  106. if((i - t.fi + 1) % 2 == 0 && f == x) {
  107. m[x] = mp(0, false);
  108. zz.erase(f);
  109. } else {
  110. cout << "NO" << endl;
  111. return 0;
  112. }
  113. }
  114. }
  115.  
  116. int cnt = 0;
  117. for(const auto &it : m) {
  118. if(it.se.se == true) cnt++;
  119. }
  120.  
  121. if(cnt <= 1) {
  122. cout << "YES" << endl;
  123. } else {
  124. cout << "NO" << endl;
  125. }
  126.  
  127.  
  128. return 0;
  129. }
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. //qwerty
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement