302A - Eugeny and Array - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

from sys import stdin
n,p = map(int, stdin.readline()[:-1].split(" "))
c=stdin.readline()[:-1]
a=0
for i in range(len(c)):
    if(c[i]=="-"):
        a+=1
out = ""
for i in range(p):
    k,l = map(int, input().split(" "))
    dist = l-k+1
    if(dist%2==0 and dist/2<=a and dist/2<=n-a):
        out += "1\n"
    else:
        out += "0\n"

print(out)

C++ Code:

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m;
    cin >> n >> m;

    vector<int> arr(n);

    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    int minus1 = count(arr.begin(), arr.end(), -1);
    int plus1 = n - minus1;
    int minreq = min(minus1, plus1);

    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;

        int numbers = r - l + 1;

        if (numbers % 2 != 0) {
            cout << 0 << endl;
        } else {
            if (numbers <= 2 * minreq && numbers <= (minus1 + plus1)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

1354B - Ternary String
122B - Lucky Substring
266B - Queue at the School
1490A - Dense Array
1650B - DIV + MOD
1549B - Gregor and the Pawn Game
553A - Kyoya and Colored Balls
1364A - XXXXX
1499B - Binary Removals
1569C - Jury Meeting
108A - Palindromic Times
46A - Ball Game
114A - Cifera
776A - A Serial Killer
25B - Phone numbers
1633C - Kill the Monster
1611A - Make Even
1030B - Vasya and Cornfield
1631A - Min Max Swap
1296B - Food Buying
133A - HQ9+
1650D - Twist the Permutation
1209A - Paint the Numbers
1234A - Equalize Prices Again
1613A - Long Comparison
1624B - Make AP
660B - Seating On Bus
405A - Gravity Flip
499B - Lecture
709A - Juicer