Advertisement
Hydron

496 D

Apr 13th, 2022
934
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.50 KB | None | 0 0
  1. /// https://codeforces.com/contest/496/problem/D
  2. #include<bits/stdc++.h>
  3.  
  4. #pragma GCC optimize ("O3")
  5. #pragma GCC optimize ("Ofast")
  6. #pragma GCC optimize ("unroll-loops")
  7.  
  8. #define y1 yy
  9. #define I first
  10. #define II second
  11. #define ver1 v*2+1
  12. #define ver2 ver1+1
  13. #define tm ((tl+tr)>>1)
  14. #define pb push_back
  15. #define accelerate ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  16.  
  17. #define vec2(type,row,col,name,val) vector<vector<type>> name((row), vector<type>((col), val))
  18. #define matrix(type,name,n,m) type **name; name = new type*[(n)]; for (int i = 0; i < (n); i++) *(name + i) = new type[m];
  19. #define pairprint(v) cout<<(v).I<<' '<<(v).II<<endl;
  20. #define vec(type,col,name,val) vector<type> name((col), val)
  21. #define pairrev(v) swap(v.I,v.II)
  22. #define all(NAME) (NAME).begin(),(NAME).end()
  23. #define rall(NAME) (NAME).rbegin(),(NAME).rend()
  24. #define square(x) ((x) * (x))
  25. #define dig(c) ((ll)(c)-'0')
  26.  
  27. #define left lft
  28. #define right rght
  29.  
  30. using namespace std;
  31.  
  32. using ll = long long;
  33. using ld = long double;
  34. using pairll = pair<ll,ll>;
  35. using ull = unsigned long long;
  36.  
  37. const ll DIM = 2e5+1;
  38. const ll MOD = 998244353;
  39. const ll LOG = 18;
  40. const ll INF = 1e9+7;
  41. const ld PI = 2*asin(1);
  42.  
  43. const char *type = (sizeof(ll) == sizeof(long long) ? "%lld" : sizeof(ll) == sizeof(short) ? "%hd" : "%d");
  44.  
  45. bool is_prime(ll &x){
  46.     for (ll i=2; i*i<=x; i++) if (x%i == 0) return false;
  47.     return true;
  48. }
  49.  
  50. bool is_number(string &s){
  51.     for (char c: s){
  52.         if (c > '9' || c < '0') return false;
  53.     }
  54.     return true;
  55. }
  56.  
  57. struct line{
  58.     ll k, b, x, num;
  59. };
  60.  
  61. struct segment{
  62.     ll l, r, num;
  63. };
  64.  
  65. void coutmod(ll x, ll mod = INF){
  66.     cout << (x%mod + mod) % mod << '\n';
  67. }
  68.  
  69. struct triple{
  70.     ll I, II, III;
  71. };
  72.  
  73. template<class T>
  74. void right_shift(T &a){
  75.     auto tmp = a.back();
  76.     for (ll i=a.size()-1; i>-1; i--){
  77.         a[i] = a[i-1];
  78.     }
  79.     a[0] = tmp;
  80. }
  81.  
  82. struct fraction{
  83.     ll num, denum;
  84.     fraction(ll a, ll b){
  85.         num = a / __gcd(a, b);
  86.         denum = b / __gcd(a, b);
  87.     }
  88.     bool operator==(const fraction b){
  89.         return (num == b.num && denum == b.denum);
  90.     }
  91.     bool operator<(const fraction b){
  92.         if (*this == b) return false;
  93.         if (b.denum == 0 && denum == 0) return (num < b.num);
  94.         if (b.denum == 0) return true;
  95.         if (denum == 0) return false;
  96.         ll n1 = num, n2 = b.num, m1 = denum, m2 = b.denum;
  97.         ll m3 = m1 * m2 / __gcd(m1, m2);
  98.         n1 *= (m3 / m1);
  99.         n2 *= (m3 / m2);
  100.         return (n1 < n2);
  101.     }
  102.  
  103. };
  104. fraction operator*(fraction a, fraction b){
  105.     return fraction(a.num * b.num, a.denum * b.denum);
  106. }
  107. fraction operator+(fraction a, fraction b){
  108.     return fraction(a.num * b.denum + b.num * a.denum, a.denum * b.denum);
  109. }
  110. ostream &operator<<(ostream &out, fraction &a){
  111.     out << "( " << a.num << " / " << a.denum << " )";
  112.     return out;
  113. }
  114.  
  115. ll res(vector<ll>c[], ll t, ll &s){
  116.     ll cnt[] = {0, 0};
  117.     ll i = 0, j = 0;
  118.     while(i < c[0].size() && j < c[1].size()){
  119.         ll i1 = min(i+t-1, (ll)c[0].size()), j1 = min(j+t-1, (ll)c[1].size());
  120.  
  121.         if (i1 == c[0].size()){
  122.             if (j1 == c[1].size()){
  123.                 return -1;
  124.             }else{
  125.                 if ((c[1].size() - j) % t == 0){
  126.                     cnt[1] += (c[1].size() - j)/t;
  127.                     j = c[1].size();
  128.                     break;
  129.                 }else return -1;
  130.             }
  131.         }
  132.         if (j1 == c[1].size()){
  133.             if ((c[0].size() - i) % t == 0){
  134.                 cnt[0] += (c[0].size() - i)/t;
  135.                 i = c[0].size();
  136.                 break;
  137.             }else return -1;
  138.         }
  139.  
  140.         if (c[0][i1] < c[1][j1]){
  141.             cnt[0] ++;
  142.             i = i1 + 1;
  143.             ll l = j, r = c[1].size(), m;
  144.             while(l<r){
  145.                 m = (l+r) >> 1;
  146.                 if (c[1][m] > c[0][i1]) r = m;
  147.                 else l = m+1;
  148.             }
  149.             j = r;
  150.         }else{
  151.             cnt[1] ++;
  152.             j = j1 + 1;
  153.             ll l = i, r = c[0].size(), m;
  154.             while(l<r){
  155.                 m = (l+r) >> 1;
  156.                 if (c[0][m] > c[1][j1]) r = m;
  157.                 else l = m+1;
  158.             }
  159.             i = r;
  160.         }
  161.     }
  162.  
  163.     if (j < c[1].size()){
  164.         if ((c[1].size()-j)%t == 0){
  165.             cnt[1] += (c[1].size()-j) / t;
  166.         }else{
  167.             return -1;
  168.         }
  169.     }else{
  170.         if (i < c[0].size()){
  171.             if ((c[0].size()-i)%t == 0){
  172.                 cnt[0] += (c[0].size()-i) / t;
  173.             }else{
  174.                 return -1;
  175.             }
  176.         }
  177.     }
  178.     if (cnt[0] == cnt[1]){
  179.         return -1;
  180.     }else{
  181.         if (cnt[0] > cnt[1]){
  182.             s = cnt[0];
  183.             return 0;
  184.         }else{
  185.             s = cnt[1];
  186.             return 1;
  187.         }
  188.     }
  189. }
  190.  
  191. void solve(){
  192.     ll n;
  193.     cin >> n;
  194.     vector < ll > c[2];
  195.     for (ll i=0; i<n; i++){
  196.         ll x;
  197.         cin >> x;
  198.         c[x&1].emplace_back(i);
  199.     }
  200.     if (c[0].size()*2 == n){
  201.         cout << "0\n";
  202.         return;
  203.     }
  204.     ll winner = (c[0].size() > c[1].size() ? 0 : 1);
  205.     vector < pairll > ans;
  206.     for (ll i=1; i<=c[winner].size(); i++){
  207.         ll s = 0;
  208.         if (res(c, i, s) == winner){
  209.             ans.emplace_back(s, i);
  210.         }
  211.     }
  212.     cout << ans.size() << '\n';
  213.     sort(all(ans));
  214.     for (pairll p: ans) pairprint(p);
  215. }
  216.  
  217. int main(){
  218.     accelerate;
  219.     ll t = 1;
  220.     //cin >> t;
  221.     while(t --){
  222.         solve();
  223.     }
  224.     return 0;
  225. }
  226.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement