【題解】Codeforces 1252C. Even Path

【題目敘述】http://codeforces.com/contest/1252/problem/C

#include <iostream>
using namespace std;
 
int n, q, x[100005], y[100005], a, b, c, d;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    x[0] = 0;
    for (int i = 1; i <= n; i++){
        cin >> x[i];
        if (x[i] % 2 == 0) x[i] = x[i-1]+1;
        else x[i] = x[i-1];
    }
    y[0] = 0;
    for (int i = 1; i <= n; i++){
        cin >> y[i];
        if (y[i] % 2 == 0) y[i] = y[i-1]+1;
        else y[i] = y[i-1];
    }
    for (int i = 0; i < q; i++){
        cin >> a >> b >> c >> d;
        if (a > c) swap(a, c);
        if (b > d) swap(b, d);
        if (x[c]-x[a-1] == c-a+1 && y[d]-y[b-1] == d-b+1) cout << "YES\n";
        else if (x[c]-x[a-1] == 0 && y[d]-y[b-1] == 0) cout << "YES\n";
        else cout << "NO\n";
    }
}
分享本文 Share with friends