답안 #1037112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037112 2024-07-28T06:17:59 Z juicy Crossing (JOI21_crossing) C++17
26 / 100
116 ms 20924 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int N = 2e5 + 5, base = 13;
 
int n, q;
long long pw[N], pf[N], sum[4 * N], s[4 * N];
int lz[4 * N];
map<long long, bool> mp;
string S;
 
int conv(char c) {
  return c == 'J' ? 1 : (c == 'O' ? 2 : 3);
}
 
void bld(int id = 1, int l = 1, int r = n) {
  sum[id] = pf[r - l];
  if (l == r) {
    s[id] = conv(S[l - 1]);
    return;
  }
  int md = (l + r) / 2;
  bld(id * 2, l, md);
  bld(id * 2 + 1, md + 1, r);
  s[id] = s[id * 2] * pw[r - md] + s[id * 2 + 1];
}
 
void app(int id, int x) {
  s[id] = sum[id] * x;
  lz[id] = x;
}
 
void psh(int id) {
  if (lz[id]) {
    app(id * 2, lz[id]);
    app(id * 2 + 1, lz[id]);
    lz[id] = 0;
  }
}
 
void upd(int u, int v, int x, int id = 1, int l = 1, int r = n) {
  if (u <= l && r <= v) {
    app(id, x);
    return;
  }
  psh(id);
  int md = (l + r) / 2;
  if (u <= md) {
    upd(u, v, x, id * 2, l, md);
  } 
  if (md < v) {
    upd(u, v, x, id * 2 + 1, md + 1, r);
  }
  s[id] = s[id * 2] * pw[r - md] + s[id * 2 + 1];
}
 
string cross(const string &a, const string &b) {
  string res;
  for (int i = 0; i < n; ++i) {
    if (a[i] == b[i]) {
      res += a[i];
    } else {
      for (auto c : {'J', 'O', 'I'}) {
        if (c != a[i] && c != b[i]) {
          res += c;
        }
      }
    }
  }
  return res;
}
 
long long get(const string &s) {
  long long h = 0;
  for (char c : s) {
    h = h * base + conv(c);
  }
  return h;
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
 
  cin >> n;
  vector<string> st;
  for (int i = 0; i < 3; ++i) {
    string s; cin >> s;
    st.push_back(s);
    mp[get(s)] = 1;
  }  
  for (int i = 0; i < 3; ++i) {
    for (int j = i + 1; j < 3; ++j) {
      auto mix = cross(st[i], st[j]);
      auto h = get(mix);
      if (!mp.count(h)) {
        mp[h] = 1;
        st.push_back(mix);
      }
    }
  }
  bool flg = 1;
  while (flg) {
    flg = 0;
    for (int i = 0; i + 1 < st.size(); ++i) {
      auto mix = cross(st[i], st.back());
      auto h = get(mix);
      if (!mp.count(h)) {
        st.push_back(mix);
        mp[h] = 1;
        flg = 1;
        break;
      }
    }
  }
  pw[0] = pf[0] = 1;
  for (int i = 1; i <= n; ++i) {
    pw[i] = pw[i - 1] * base;
    pf[i] = pf[i - 1] + pw[i];
  }
  cin >> q >> S;
  bld();
  auto qry = [&]() {
    cout << (mp.count(s[1]) ? "Yes" : "No") << "\n";
  };
  qry();
  while (q--) {
    int l, r; char c; cin >> l >> r >> c;
    upd(l, r, conv(c));
    qry();
  }
  return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:111:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for (int i = 0; i + 1 < st.size(); ++i) {
      |                     ~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 9196 KB Output is correct
2 Correct 47 ms 9108 KB Output is correct
3 Correct 46 ms 9040 KB Output is correct
4 Correct 44 ms 9048 KB Output is correct
5 Correct 40 ms 9052 KB Output is correct
6 Correct 38 ms 8992 KB Output is correct
7 Correct 46 ms 9132 KB Output is correct
8 Correct 43 ms 9052 KB Output is correct
9 Correct 41 ms 9240 KB Output is correct
10 Correct 41 ms 9040 KB Output is correct
11 Correct 42 ms 9296 KB Output is correct
12 Correct 41 ms 9148 KB Output is correct
13 Correct 42 ms 9040 KB Output is correct
14 Correct 41 ms 9044 KB Output is correct
15 Correct 42 ms 9044 KB Output is correct
16 Correct 42 ms 9248 KB Output is correct
17 Correct 41 ms 9148 KB Output is correct
18 Correct 41 ms 9052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 9196 KB Output is correct
2 Correct 47 ms 9108 KB Output is correct
3 Correct 46 ms 9040 KB Output is correct
4 Correct 44 ms 9048 KB Output is correct
5 Correct 40 ms 9052 KB Output is correct
6 Correct 38 ms 8992 KB Output is correct
7 Correct 46 ms 9132 KB Output is correct
8 Correct 43 ms 9052 KB Output is correct
9 Correct 41 ms 9240 KB Output is correct
10 Correct 41 ms 9040 KB Output is correct
11 Correct 42 ms 9296 KB Output is correct
12 Correct 41 ms 9148 KB Output is correct
13 Correct 42 ms 9040 KB Output is correct
14 Correct 41 ms 9044 KB Output is correct
15 Correct 42 ms 9044 KB Output is correct
16 Correct 42 ms 9248 KB Output is correct
17 Correct 41 ms 9148 KB Output is correct
18 Correct 41 ms 9052 KB Output is correct
19 Correct 106 ms 20564 KB Output is correct
20 Correct 116 ms 19028 KB Output is correct
21 Correct 84 ms 20580 KB Output is correct
22 Correct 90 ms 20528 KB Output is correct
23 Correct 64 ms 9296 KB Output is correct
24 Correct 62 ms 9300 KB Output is correct
25 Correct 89 ms 20820 KB Output is correct
26 Correct 90 ms 20784 KB Output is correct
27 Correct 96 ms 20816 KB Output is correct
28 Correct 94 ms 20824 KB Output is correct
29 Correct 92 ms 20692 KB Output is correct
30 Correct 72 ms 9228 KB Output is correct
31 Correct 95 ms 20820 KB Output is correct
32 Correct 97 ms 20592 KB Output is correct
33 Correct 68 ms 9552 KB Output is correct
34 Correct 102 ms 20924 KB Output is correct
35 Correct 81 ms 20280 KB Output is correct
36 Correct 62 ms 9384 KB Output is correct
37 Correct 63 ms 9300 KB Output is correct
38 Correct 93 ms 20820 KB Output is correct
39 Correct 68 ms 18516 KB Output is correct
40 Incorrect 74 ms 16240 KB Output isn't correct
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 9196 KB Output is correct
2 Correct 47 ms 9108 KB Output is correct
3 Correct 46 ms 9040 KB Output is correct
4 Correct 44 ms 9048 KB Output is correct
5 Correct 40 ms 9052 KB Output is correct
6 Correct 38 ms 8992 KB Output is correct
7 Correct 46 ms 9132 KB Output is correct
8 Correct 43 ms 9052 KB Output is correct
9 Correct 41 ms 9240 KB Output is correct
10 Correct 41 ms 9040 KB Output is correct
11 Correct 42 ms 9296 KB Output is correct
12 Correct 41 ms 9148 KB Output is correct
13 Correct 42 ms 9040 KB Output is correct
14 Correct 41 ms 9044 KB Output is correct
15 Correct 42 ms 9044 KB Output is correct
16 Correct 42 ms 9248 KB Output is correct
17 Correct 41 ms 9148 KB Output is correct
18 Correct 41 ms 9052 KB Output is correct
19 Correct 47 ms 9040 KB Output is correct
20 Correct 47 ms 9048 KB Output is correct
21 Correct 44 ms 9032 KB Output is correct
22 Correct 39 ms 9040 KB Output is correct
23 Correct 38 ms 9236 KB Output is correct
24 Correct 38 ms 9044 KB Output is correct
25 Correct 42 ms 9040 KB Output is correct
26 Correct 40 ms 9044 KB Output is correct
27 Correct 43 ms 9172 KB Output is correct
28 Correct 39 ms 9024 KB Output is correct
29 Correct 38 ms 9112 KB Output is correct
30 Correct 37 ms 9040 KB Output is correct
31 Correct 52 ms 9044 KB Output is correct
32 Correct 45 ms 9044 KB Output is correct
33 Correct 46 ms 9052 KB Output is correct
34 Correct 39 ms 9044 KB Output is correct
35 Correct 42 ms 9080 KB Output is correct
36 Correct 45 ms 9052 KB Output is correct
37 Correct 45 ms 9136 KB Output is correct
38 Correct 44 ms 9040 KB Output is correct
39 Correct 44 ms 9168 KB Output is correct
40 Correct 45 ms 9068 KB Output is correct
41 Correct 43 ms 9236 KB Output is correct
42 Correct 46 ms 9040 KB Output is correct
43 Correct 43 ms 9172 KB Output is correct
44 Correct 45 ms 9232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 9196 KB Output is correct
2 Correct 47 ms 9108 KB Output is correct
3 Correct 46 ms 9040 KB Output is correct
4 Correct 44 ms 9048 KB Output is correct
5 Correct 40 ms 9052 KB Output is correct
6 Correct 38 ms 8992 KB Output is correct
7 Correct 46 ms 9132 KB Output is correct
8 Correct 43 ms 9052 KB Output is correct
9 Correct 41 ms 9240 KB Output is correct
10 Correct 41 ms 9040 KB Output is correct
11 Correct 42 ms 9296 KB Output is correct
12 Correct 41 ms 9148 KB Output is correct
13 Correct 42 ms 9040 KB Output is correct
14 Correct 41 ms 9044 KB Output is correct
15 Correct 42 ms 9044 KB Output is correct
16 Correct 42 ms 9248 KB Output is correct
17 Correct 41 ms 9148 KB Output is correct
18 Correct 41 ms 9052 KB Output is correct
19 Correct 106 ms 20564 KB Output is correct
20 Correct 116 ms 19028 KB Output is correct
21 Correct 84 ms 20580 KB Output is correct
22 Correct 90 ms 20528 KB Output is correct
23 Correct 64 ms 9296 KB Output is correct
24 Correct 62 ms 9300 KB Output is correct
25 Correct 89 ms 20820 KB Output is correct
26 Correct 90 ms 20784 KB Output is correct
27 Correct 96 ms 20816 KB Output is correct
28 Correct 94 ms 20824 KB Output is correct
29 Correct 92 ms 20692 KB Output is correct
30 Correct 72 ms 9228 KB Output is correct
31 Correct 95 ms 20820 KB Output is correct
32 Correct 97 ms 20592 KB Output is correct
33 Correct 68 ms 9552 KB Output is correct
34 Correct 102 ms 20924 KB Output is correct
35 Correct 81 ms 20280 KB Output is correct
36 Correct 62 ms 9384 KB Output is correct
37 Correct 63 ms 9300 KB Output is correct
38 Correct 93 ms 20820 KB Output is correct
39 Correct 68 ms 18516 KB Output is correct
40 Incorrect 74 ms 16240 KB Output isn't correct
41 Halted 0 ms 0 KB -