Submission #1095370

# Submission time Handle Problem Language Result Execution time Memory
1095370 2024-10-02T02:22:29 Z cpptowin Crossing (JOI21_crossing) C++17
100 / 100
298 ms 160928 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define bitcount(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ss(x) (int)x.size()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
void add(int &x, int k)
{
    x += k;
    x %= mod;
    if (x < 0)
        x += mod;
}
void del(int &x, int k)
{
    x -= k;
    x %= mod;
    if (x < 0)
        x += mod;
}
const int base = 31;
int n, q;
map<int, bool> mp;
vi a[3];
int p[maxn];
void backtrack(vi v)
{
    int hsh = 0;
    fo(i, 0, n - 1) hsh = (hsh * base + v[i]) % mod;
    if (mp.count(hsh))
        return;
    mp[hsh] = 1;
    fo(j, 0, 2)
    {
        vi cur(n);
        fo(i, 0, n - 1)
        {
            if(v[i] != a[j][i])
            cur[i] = 3 - v[i] - a[j][i];
            else cur[i] = v[i];
        }
        backtrack(cur);
    }
}
struct node
{
    int h, len;
    node()
    {
        h = len = 0;
    }
    node operator+(const node b)
    {
        if(len == 0) return b;
        if(b.len == 0) return *this;
        node ans;
        ans.len = len + b.len;
        ans.h = (h * p[b.len] + b.h) % mod;
        return ans;
    }
} st[4 * maxn];
int lazy[4 * maxn];
int hh[maxn][3];
void down(int id, int l, int r)
{
    if (lazy[id] == -1)
        return;
    int mid = l + r >> 1;
    st[id << 1].h = hh[mid - l + 1][lazy[id]];
    st[id << 1 | 1].h = hh[r - mid][lazy[id]];
    lazy[id << 1] = lazy[id << 1 | 1] = lazy[id];
    lazy[id] = -1;
}
void update(int id, int l, int r, int u, int v, int val)
{
    if (u > r || l > v)
        return;
    if (u <= l && r <= v)
    {
        st[id].h = hh[r - l + 1][val];
        st[id].len = r - l + 1;
        lazy[id] = val;
        return;
    }
    down(id, l, r);
    int mid = (l + r) >> 1;
    update(id << 1, l, mid, u, v, val);
    update(id << 1 | 1, mid + 1, r, u, v, val);
    st[id] = st[id << 1] + st[id << 1 | 1];
}

node get(int id, int l, int r, int u, int v)
{
    if (l > v || u > r)
        return node();
    if (u <= l && r <= v)
        return st[id];
    down(id, l, r);
    int mid = (l + r) >> 1;
    return get(id << 1, l, mid, u, v) + get(id << 1 | 1, mid + 1, r, u, v);
}
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(lazy, -1, sizeof lazy);
    cin >> n;
    p[0] = 1;
    fo(i, 1, maxn - 1)
    {
        p[i] = p[i - 1] * base % mod;
        fo(j, 0, 2)
        {
            hh[i][j] = (hh[i - 1][j] * base + j) % mod;
        }
    }
    fo(i, 0, 2) a[i].resize(n);
    fo(i, 0, 2) for (int &it : a[i])
    {
        char t;
        cin >> t;
        if (t == 'J')
            it = 0;
        else if (t == 'O')
            it = 1;
        else if (t == 'I')
            it = 2;
    }
    fo(i, 0, 2)
    {
        backtrack(a[i]);
    }
    cin >> q;
    fo(i, 1, n)
    {
        int it;
        char t;
        cin >> t;
        if (t == 'J')
            it = 0;
        else if (t == 'O')
            it = 1;
        else if (t == 'I')
            it = 2;
        update(1, 1, n, i, i, it);
    }
    if(mp.count(st[1].h)) cout << "Yes";
    else cout << "No";
    en;
    while (q--)
    {
        int it;
        char t;
        int l, r;
        cin >> l >> r >> t;
        if (t == 'J')
            it = 0;
        else if (t == 'O')
            it = 1;
        else if (t == 'I')
            it = 2;
        update(1, 1, n, l, r, it);
        if(mp.count(st[1].h)) cout << "Yes";
        else cout << "No";
        en;
    }
}

Compilation message

Main.cpp: In function 'void down(long long int, long long int, long long int)':
Main.cpp:106:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |     int mid = l + r >> 1;
      |               ~~^~~
Main.cpp: At global scope:
Main.cpp:140:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  140 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:145:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:146:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  146 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:206:15: warning: 'it' may be used uninitialized in this function [-Wmaybe-uninitialized]
  206 |         update(1, 1, n, l, r, it);
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:189:15: warning: 'it' may be used uninitialized in this function [-Wmaybe-uninitialized]
  189 |         update(1, 1, n, i, i, it);
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 113 ms 127568 KB Output is correct
2 Correct 114 ms 127736 KB Output is correct
3 Correct 105 ms 127568 KB Output is correct
4 Correct 100 ms 127572 KB Output is correct
5 Correct 105 ms 127572 KB Output is correct
6 Correct 100 ms 127528 KB Output is correct
7 Correct 107 ms 127564 KB Output is correct
8 Correct 105 ms 127656 KB Output is correct
9 Correct 104 ms 127828 KB Output is correct
10 Correct 106 ms 127720 KB Output is correct
11 Correct 102 ms 127824 KB Output is correct
12 Correct 109 ms 127740 KB Output is correct
13 Correct 103 ms 127732 KB Output is correct
14 Correct 103 ms 127756 KB Output is correct
15 Correct 100 ms 127824 KB Output is correct
16 Correct 99 ms 127832 KB Output is correct
17 Correct 99 ms 127828 KB Output is correct
18 Correct 103 ms 127608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 127568 KB Output is correct
2 Correct 114 ms 127736 KB Output is correct
3 Correct 105 ms 127568 KB Output is correct
4 Correct 100 ms 127572 KB Output is correct
5 Correct 105 ms 127572 KB Output is correct
6 Correct 100 ms 127528 KB Output is correct
7 Correct 107 ms 127564 KB Output is correct
8 Correct 105 ms 127656 KB Output is correct
9 Correct 104 ms 127828 KB Output is correct
10 Correct 106 ms 127720 KB Output is correct
11 Correct 102 ms 127824 KB Output is correct
12 Correct 109 ms 127740 KB Output is correct
13 Correct 103 ms 127732 KB Output is correct
14 Correct 103 ms 127756 KB Output is correct
15 Correct 100 ms 127824 KB Output is correct
16 Correct 99 ms 127832 KB Output is correct
17 Correct 99 ms 127828 KB Output is correct
18 Correct 103 ms 127608 KB Output is correct
19 Correct 260 ms 136064 KB Output is correct
20 Correct 257 ms 136060 KB Output is correct
21 Correct 225 ms 135436 KB Output is correct
22 Correct 198 ms 134700 KB Output is correct
23 Correct 146 ms 128980 KB Output is correct
24 Correct 135 ms 129076 KB Output is correct
25 Correct 216 ms 136056 KB Output is correct
26 Correct 217 ms 136192 KB Output is correct
27 Correct 216 ms 136044 KB Output is correct
28 Correct 235 ms 136068 KB Output is correct
29 Correct 226 ms 135792 KB Output is correct
30 Correct 139 ms 129008 KB Output is correct
31 Correct 229 ms 136156 KB Output is correct
32 Correct 221 ms 135488 KB Output is correct
33 Correct 134 ms 129012 KB Output is correct
34 Correct 221 ms 136060 KB Output is correct
35 Correct 193 ms 134000 KB Output is correct
36 Correct 145 ms 129020 KB Output is correct
37 Correct 134 ms 129008 KB Output is correct
38 Correct 222 ms 136064 KB Output is correct
39 Correct 201 ms 136060 KB Output is correct
40 Correct 201 ms 133508 KB Output is correct
41 Correct 257 ms 136316 KB Output is correct
42 Correct 139 ms 135784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 127568 KB Output is correct
2 Correct 114 ms 127736 KB Output is correct
3 Correct 105 ms 127568 KB Output is correct
4 Correct 100 ms 127572 KB Output is correct
5 Correct 105 ms 127572 KB Output is correct
6 Correct 100 ms 127528 KB Output is correct
7 Correct 107 ms 127564 KB Output is correct
8 Correct 105 ms 127656 KB Output is correct
9 Correct 104 ms 127828 KB Output is correct
10 Correct 106 ms 127720 KB Output is correct
11 Correct 102 ms 127824 KB Output is correct
12 Correct 109 ms 127740 KB Output is correct
13 Correct 103 ms 127732 KB Output is correct
14 Correct 103 ms 127756 KB Output is correct
15 Correct 100 ms 127824 KB Output is correct
16 Correct 99 ms 127832 KB Output is correct
17 Correct 99 ms 127828 KB Output is correct
18 Correct 103 ms 127608 KB Output is correct
19 Correct 115 ms 127572 KB Output is correct
20 Correct 110 ms 127568 KB Output is correct
21 Correct 105 ms 127824 KB Output is correct
22 Correct 100 ms 127480 KB Output is correct
23 Correct 104 ms 127620 KB Output is correct
24 Correct 104 ms 127572 KB Output is correct
25 Correct 101 ms 127828 KB Output is correct
26 Correct 102 ms 127572 KB Output is correct
27 Correct 102 ms 127828 KB Output is correct
28 Correct 96 ms 127568 KB Output is correct
29 Correct 103 ms 127764 KB Output is correct
30 Correct 111 ms 127568 KB Output is correct
31 Correct 105 ms 127828 KB Output is correct
32 Correct 108 ms 127568 KB Output is correct
33 Correct 105 ms 127828 KB Output is correct
34 Correct 105 ms 127604 KB Output is correct
35 Correct 103 ms 127828 KB Output is correct
36 Correct 104 ms 127628 KB Output is correct
37 Correct 108 ms 127824 KB Output is correct
38 Correct 112 ms 127844 KB Output is correct
39 Correct 106 ms 127768 KB Output is correct
40 Correct 111 ms 127612 KB Output is correct
41 Correct 105 ms 127824 KB Output is correct
42 Correct 112 ms 127772 KB Output is correct
43 Correct 102 ms 127556 KB Output is correct
44 Correct 106 ms 127684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 127568 KB Output is correct
2 Correct 114 ms 127736 KB Output is correct
3 Correct 105 ms 127568 KB Output is correct
4 Correct 100 ms 127572 KB Output is correct
5 Correct 105 ms 127572 KB Output is correct
6 Correct 100 ms 127528 KB Output is correct
7 Correct 107 ms 127564 KB Output is correct
8 Correct 105 ms 127656 KB Output is correct
9 Correct 104 ms 127828 KB Output is correct
10 Correct 106 ms 127720 KB Output is correct
11 Correct 102 ms 127824 KB Output is correct
12 Correct 109 ms 127740 KB Output is correct
13 Correct 103 ms 127732 KB Output is correct
14 Correct 103 ms 127756 KB Output is correct
15 Correct 100 ms 127824 KB Output is correct
16 Correct 99 ms 127832 KB Output is correct
17 Correct 99 ms 127828 KB Output is correct
18 Correct 103 ms 127608 KB Output is correct
19 Correct 260 ms 136064 KB Output is correct
20 Correct 257 ms 136060 KB Output is correct
21 Correct 225 ms 135436 KB Output is correct
22 Correct 198 ms 134700 KB Output is correct
23 Correct 146 ms 128980 KB Output is correct
24 Correct 135 ms 129076 KB Output is correct
25 Correct 216 ms 136056 KB Output is correct
26 Correct 217 ms 136192 KB Output is correct
27 Correct 216 ms 136044 KB Output is correct
28 Correct 235 ms 136068 KB Output is correct
29 Correct 226 ms 135792 KB Output is correct
30 Correct 139 ms 129008 KB Output is correct
31 Correct 229 ms 136156 KB Output is correct
32 Correct 221 ms 135488 KB Output is correct
33 Correct 134 ms 129012 KB Output is correct
34 Correct 221 ms 136060 KB Output is correct
35 Correct 193 ms 134000 KB Output is correct
36 Correct 145 ms 129020 KB Output is correct
37 Correct 134 ms 129008 KB Output is correct
38 Correct 222 ms 136064 KB Output is correct
39 Correct 201 ms 136060 KB Output is correct
40 Correct 201 ms 133508 KB Output is correct
41 Correct 257 ms 136316 KB Output is correct
42 Correct 139 ms 135784 KB Output is correct
43 Correct 115 ms 127572 KB Output is correct
44 Correct 110 ms 127568 KB Output is correct
45 Correct 105 ms 127824 KB Output is correct
46 Correct 100 ms 127480 KB Output is correct
47 Correct 104 ms 127620 KB Output is correct
48 Correct 104 ms 127572 KB Output is correct
49 Correct 101 ms 127828 KB Output is correct
50 Correct 102 ms 127572 KB Output is correct
51 Correct 102 ms 127828 KB Output is correct
52 Correct 96 ms 127568 KB Output is correct
53 Correct 103 ms 127764 KB Output is correct
54 Correct 111 ms 127568 KB Output is correct
55 Correct 105 ms 127828 KB Output is correct
56 Correct 108 ms 127568 KB Output is correct
57 Correct 105 ms 127828 KB Output is correct
58 Correct 105 ms 127604 KB Output is correct
59 Correct 103 ms 127828 KB Output is correct
60 Correct 104 ms 127628 KB Output is correct
61 Correct 108 ms 127824 KB Output is correct
62 Correct 112 ms 127844 KB Output is correct
63 Correct 106 ms 127768 KB Output is correct
64 Correct 111 ms 127612 KB Output is correct
65 Correct 105 ms 127824 KB Output is correct
66 Correct 112 ms 127772 KB Output is correct
67 Correct 102 ms 127556 KB Output is correct
68 Correct 106 ms 127684 KB Output is correct
69 Correct 269 ms 155092 KB Output is correct
70 Correct 298 ms 160912 KB Output is correct
71 Correct 132 ms 129264 KB Output is correct
72 Correct 135 ms 129340 KB Output is correct
73 Correct 133 ms 129220 KB Output is correct
74 Correct 208 ms 139376 KB Output is correct
75 Correct 133 ms 129236 KB Output is correct
76 Correct 228 ms 142104 KB Output is correct
77 Correct 213 ms 139372 KB Output is correct
78 Correct 138 ms 129292 KB Output is correct
79 Correct 131 ms 129324 KB Output is correct
80 Correct 219 ms 150704 KB Output is correct
81 Correct 147 ms 130092 KB Output is correct
82 Correct 261 ms 160916 KB Output is correct
83 Correct 266 ms 158708 KB Output is correct
84 Correct 137 ms 130244 KB Output is correct
85 Correct 138 ms 130160 KB Output is correct
86 Correct 240 ms 152424 KB Output is correct
87 Correct 261 ms 160912 KB Output is correct
88 Correct 137 ms 130216 KB Output is correct
89 Correct 246 ms 156808 KB Output is correct
90 Correct 261 ms 160908 KB Output is correct
91 Correct 140 ms 130140 KB Output is correct
92 Correct 238 ms 152024 KB Output is correct
93 Correct 139 ms 130160 KB Output is correct
94 Correct 140 ms 130148 KB Output is correct
95 Correct 142 ms 130332 KB Output is correct
96 Correct 222 ms 135812 KB Output is correct
97 Correct 247 ms 160928 KB Output is correct
98 Correct 226 ms 149180 KB Output is correct
99 Correct 290 ms 160908 KB Output is correct
100 Correct 172 ms 160916 KB Output is correct