Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// https://codeforces.com/contest/496/problem/D
- #include<bits/stdc++.h>
- #pragma GCC optimize ("O3")
- #pragma GCC optimize ("Ofast")
- #pragma GCC optimize ("unroll-loops")
- #define y1 yy
- #define I first
- #define II second
- #define ver1 v*2+1
- #define ver2 ver1+1
- #define tm ((tl+tr)>>1)
- #define pb push_back
- #define accelerate ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
- #define vec2(type,row,col,name,val) vector<vector<type>> name((row), vector<type>((col), val))
- #define matrix(type,name,n,m) type **name; name = new type*[(n)]; for (int i = 0; i < (n); i++) *(name + i) = new type[m];
- #define pairprint(v) cout<<(v).I<<' '<<(v).II<<endl;
- #define vec(type,col,name,val) vector<type> name((col), val)
- #define pairrev(v) swap(v.I,v.II)
- #define all(NAME) (NAME).begin(),(NAME).end()
- #define rall(NAME) (NAME).rbegin(),(NAME).rend()
- #define square(x) ((x) * (x))
- #define dig(c) ((ll)(c)-'0')
- #define left lft
- #define right rght
- using namespace std;
- using ll = long long;
- using ld = long double;
- using pairll = pair<ll,ll>;
- using ull = unsigned long long;
- const ll DIM = 2e5+1;
- const ll MOD = 998244353;
- const ll LOG = 18;
- const ll INF = 1e9+7;
- const ld PI = 2*asin(1);
- const char *type = (sizeof(ll) == sizeof(long long) ? "%lld" : sizeof(ll) == sizeof(short) ? "%hd" : "%d");
- bool is_prime(ll &x){
- for (ll i=2; i*i<=x; i++) if (x%i == 0) return false;
- return true;
- }
- bool is_number(string &s){
- for (char c: s){
- if (c > '9' || c < '0') return false;
- }
- return true;
- }
- struct line{
- ll k, b, x, num;
- };
- struct segment{
- ll l, r, num;
- };
- void coutmod(ll x, ll mod = INF){
- cout << (x%mod + mod) % mod << '\n';
- }
- struct triple{
- ll I, II, III;
- };
- template<class T>
- void right_shift(T &a){
- auto tmp = a.back();
- for (ll i=a.size()-1; i>-1; i--){
- a[i] = a[i-1];
- }
- a[0] = tmp;
- }
- struct fraction{
- ll num, denum;
- fraction(ll a, ll b){
- num = a / __gcd(a, b);
- denum = b / __gcd(a, b);
- }
- bool operator==(const fraction b){
- return (num == b.num && denum == b.denum);
- }
- bool operator<(const fraction b){
- if (*this == b) return false;
- if (b.denum == 0 && denum == 0) return (num < b.num);
- if (b.denum == 0) return true;
- if (denum == 0) return false;
- ll n1 = num, n2 = b.num, m1 = denum, m2 = b.denum;
- ll m3 = m1 * m2 / __gcd(m1, m2);
- n1 *= (m3 / m1);
- n2 *= (m3 / m2);
- return (n1 < n2);
- }
- };
- fraction operator*(fraction a, fraction b){
- return fraction(a.num * b.num, a.denum * b.denum);
- }
- fraction operator+(fraction a, fraction b){
- return fraction(a.num * b.denum + b.num * a.denum, a.denum * b.denum);
- }
- ostream &operator<<(ostream &out, fraction &a){
- out << "( " << a.num << " / " << a.denum << " )";
- return out;
- }
- ll res(vector<ll>c[], ll t, ll &s){
- ll cnt[] = {0, 0};
- ll i = 0, j = 0;
- while(i < c[0].size() && j < c[1].size()){
- ll i1 = min(i+t-1, (ll)c[0].size()), j1 = min(j+t-1, (ll)c[1].size());
- if (i1 == c[0].size()){
- if (j1 == c[1].size()){
- return -1;
- }else{
- if ((c[1].size() - j) % t == 0){
- cnt[1] += (c[1].size() - j)/t;
- j = c[1].size();
- break;
- }else return -1;
- }
- }
- if (j1 == c[1].size()){
- if ((c[0].size() - i) % t == 0){
- cnt[0] += (c[0].size() - i)/t;
- i = c[0].size();
- break;
- }else return -1;
- }
- if (c[0][i1] < c[1][j1]){
- cnt[0] ++;
- i = i1 + 1;
- ll l = j, r = c[1].size(), m;
- while(l<r){
- m = (l+r) >> 1;
- if (c[1][m] > c[0][i1]) r = m;
- else l = m+1;
- }
- j = r;
- }else{
- cnt[1] ++;
- j = j1 + 1;
- ll l = i, r = c[0].size(), m;
- while(l<r){
- m = (l+r) >> 1;
- if (c[0][m] > c[1][j1]) r = m;
- else l = m+1;
- }
- i = r;
- }
- }
- if (j < c[1].size()){
- if ((c[1].size()-j)%t == 0){
- cnt[1] += (c[1].size()-j) / t;
- }else{
- return -1;
- }
- }else{
- if (i < c[0].size()){
- if ((c[0].size()-i)%t == 0){
- cnt[0] += (c[0].size()-i) / t;
- }else{
- return -1;
- }
- }
- }
- if (cnt[0] == cnt[1]){
- return -1;
- }else{
- if (cnt[0] > cnt[1]){
- s = cnt[0];
- return 0;
- }else{
- s = cnt[1];
- return 1;
- }
- }
- }
- void solve(){
- ll n;
- cin >> n;
- vector < ll > c[2];
- for (ll i=0; i<n; i++){
- ll x;
- cin >> x;
- c[x&1].emplace_back(i);
- }
- if (c[0].size()*2 == n){
- cout << "0\n";
- return;
- }
- ll winner = (c[0].size() > c[1].size() ? 0 : 1);
- vector < pairll > ans;
- for (ll i=1; i<=c[winner].size(); i++){
- ll s = 0;
- if (res(c, i, s) == winner){
- ans.emplace_back(s, i);
- }
- }
- cout << ans.size() << '\n';
- sort(all(ans));
- for (pairll p: ans) pairprint(p);
- }
- int main(){
- accelerate;
- ll t = 1;
- //cin >> t;
- while(t --){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement