fork download
  1. //#define LOCAL 7
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define wspc "\n\t "
  6. #ifdef LOCAL
  7. #define d(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
  8. #else
  9. #define d(...) 1729
  10. #endif
  11. void debug() {cerr<<wspc[0];}
  12. template<typename Head,typename... Tail>
  13. void debug(Head H, Tail... T){cerr << " " <<to_string(H);debug(T...);}
  14.  
  15. template <typename A, typename B>string to_string(pair<A, B> p);
  16. template<typename A,typename B,typename C>string to_string(tuple<A, B, C> p);
  17. template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p);
  18. string to_string(const string& s){return '"'+s+'"';}
  19. string to_string(const char* s){return to_string((string) s);}
  20. string to_string(bool b){return (b?"true":"false");}
  21. string to_string(vector<bool> v){bool first=1;string res="{";for(int i=0;i<static_cast<int>(v.size());i++){
  22. if(!first){res+=", ";}first=0;res+=to_string(v[i]);}res+="}";return res;}
  23. template <size_t N>string to_string(bitset<N> v){string res="";
  24. for(size_t i=0;i<N;i++){res+=static_cast<char>('0'+v[i]);}return res;}
  25. template <typename A>string to_string(A v){bool first=1;string res="{";
  26. for(const auto &x : v){if(!first){res+=", ";}first=0;res+=to_string(x);}res+="}";return res;}
  27. template<typename A,typename B>string to_string(pair<A, B> p)
  28. {return "("+to_string(p.first)+", "+to_string(p.second)+")";}
  29. template<typename A,typename B,typename C>string to_string(tuple<A, B, C> p)
  30. {return"("+to_string(get<0>(p))+", "+to_string(get<1>(p))+", "+to_string(get<2>(p))+")";}
  31. template<typename A,typename B,typename C,typename D>string to_string(tuple<A, B, C, D> p)
  32. {return "("+to_string(get<0>(p))+", "+to_string(get<1>(p))+", "+to_string(get<2>(p))+", "+to_string(get<3>(p))+")";}
  33.  
  34. #define pb push_back
  35. #define rep(i, n) for (int i = 0; i < (n); i++)
  36. #define fast ios_base::sync_with_stdio(0)
  37. #define scan(a) for(auto &val:a)cin>>val;
  38.  
  39. //Code started :
  40. const int N = 1e6+5;
  41. char memo[N]={0};
  42.  
  43. bool solve()
  44. {
  45. int n,tmp;
  46. cin>>n;
  47. int a[n];
  48. scan(a);
  49.  
  50. vector<int>present,breaks;
  51. int i;
  52. //0->wait,1->entered,2->left
  53. rep(i,n)
  54. {
  55. if(a[i]<0)
  56. {
  57. a[i]=-a[i];
  58. if(memo[a[i]]!=1)
  59. return 0;
  60. memo[a[i]]=2;
  61. }
  62. else if(memo[a[i]]==2)
  63. {
  64. for(auto x : present)
  65. {
  66. if(memo[a[x]]==1)
  67. return 0;
  68. }
  69. //if()
  70. breaks.pb(present.size());
  71. present.clear();
  72. memo[a[i]]=1;
  73. }
  74. else if(memo[a[i]]==0)
  75. memo[a[i]]=1;
  76. else
  77. return 0;
  78.  
  79. present.pb(i);
  80. tmp=memo[a[i]];
  81. d(i,present);
  82. d(breaks,a[i],tmp);
  83. }
  84.  
  85. d(present);
  86. for(auto x : present)
  87. {
  88. if(memo[a[x]]==1)
  89. return 0;
  90. }
  91. breaks.pb(present.size());
  92. d(breaks);
  93.  
  94. cout<<breaks.size()<<'\n';
  95. for(auto x : breaks)
  96. cout<<x<<" ";
  97.  
  98. return 1;
  99. }
  100.  
  101. int main()
  102. {
  103. fast;
  104. if(!solve())cout<<"-1\n";
  105. return 0;
  106. }
Success #stdin #stdout 0s 4552KB
stdin
Standard input is empty
stdout
-1