제출 #533170

#제출 시각아이디문제언어결과실행 시간메모리
5331704fectaCrossing (JOI21_crossing)C++17
100 / 100
3247 ms76652 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
#define mid ((l + r) / 2)

const int MN = 200005;

int n, a[MN], d[MN], q, l[MN], r[MN], lzy[MN * 4], st[MN * 4][3][3], ans[MN];
char ch, t[MN];
vector<string> poss;
string x, y, z;

int g(char x) {
    if (x == 'J') return 0;
    if (x == 'O') return 1;
    return 2;
}

void push_down(int l, int r, int idx) {
    if (lzy[idx] == -1) return;
    for (int i = 0; i < 3; i++) {
        int cnt = 0;
        for (int j = 0; j < 3; j++) {
            cnt += st[idx][i][j];
            st[idx][i][j] = 0;
        }
        st[idx][i][lzy[idx]] = cnt;
    }
    if (l != r) lzy[idx * 2] = lzy[idx * 2 + 1] = lzy[idx];
    lzy[idx] = -1;
}

void build(int l, int r, int idx) {
    lzy[idx] = -1;
    if (l == r) {
        st[idx][a[l]][d[l]]++;
        return;
    }
    build(l, mid, idx * 2), build(mid + 1, r, idx * 2 + 1);
    for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) st[idx][i][j] = st[idx * 2][i][j] + st[idx * 2 + 1][i][j];
}

void upd(int l, int r, int x, int y, int val, int idx) {
    push_down(l, r, idx);
    if (r < x || l > y) return;
    if (r <= y && l >= x) {
        lzy[idx] = val;
        push_down(l, r, idx);
        return;
    }
    upd(l, mid, x, y, val, idx * 2), upd(mid + 1, r, x, y, val, idx * 2 + 1);
    for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) st[idx][i][j] = st[idx * 2][i][j] + st[idx * 2 + 1][i][j];
}

void check(int i) {
    if (st[1][0][0] + st[1][1][1] + st[1][2][2] == n) ans[i] = 1;
}

string c(string x, string y) {
    string ret;
    for (int i = 0; i < x.size(); i++) {
        if (x[i] == y[i]) ret += x[i];
        else {
            if (x[i] == 'J' && y[i] == 'O') ret += 'I';
            if (x[i] == 'O' && y[i] == 'J') ret += 'I';
            if (x[i] == 'I' && y[i] == 'O') ret += 'J';
            if (x[i] == 'O' && y[i] == 'I') ret += 'J';
            if (x[i] == 'J' && y[i] == 'I') ret += 'O';
            if (x[i] == 'I' && y[i] == 'J') ret += 'O';
        }
    }
    return ret;
}

int32_t main() {
    boost();

    cin >> n >> x >> y >> z;
    poss.push_back(x);
    poss.push_back(y);
    poss.push_back(z);
    poss.push_back(c(x, y));
    poss.push_back(c(x, z));
    poss.push_back(c(y, z));
    poss.push_back(c(c(x, y), z));
    poss.push_back(c(c(x, z), y));
    poss.push_back(c(c(y, z), x));
    cin >> q;
    for (int i = 1; i <= n; i++) {
        cin >> ch;
        d[i] = g(ch);
    }
    for (int i = 1; i <= q; i++) cin >> l[i] >> r[i] >> t[i];
    for (string s : poss) {
        memset(st, 0, sizeof(st));
        for (int i = 1; i <= n; i++) a[i] = g(s[i - 1]);
        build(1, n, 1);
        check(0);
        for (int i = 1; i <= q; i++) {
            int val = g(t[i]);
            upd(1, n, l[i], r[i], val, 1);
            check(i);
        }
    }
    for (int i = 0; i <= q; i++) {
        if (ans[i]) printf("Yes\n");
        else printf("No\n");
    }

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'std::string c(std::string, std::string)':
Main.cpp:67:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for (int i = 0; i < x.size(); i++) {
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...