Submission #476505

# Submission time Handle Problem Language Result Execution time Memory
476505 2021-09-27T12:17:40 Z stat0r1c Crossing (JOI21_crossing) C++11
100 / 100
580 ms 26908 KB
#include <bits/stdc++.h>
/* #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
// using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned ll;
template<typename T> using vt = vector<T>;
using vi = vt<int>;
using vvi = vt<vi>;
using ii = pair<int, int>;
using vii = vt<ii>;
/* template<typename T>
using indexed_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; */
/* struct chash {
    static ull hash_f(ull x) {x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(ull x) const {static const ull RANDOM = chrono::steady_clock::now().time_since_epoch().count();returnash_f(x + RANDOM);}
};
struct iihash {
    template <class T1, class T2>
    size_t operator () (const pair<T1,T2> &p) const {auto h1 = hash<T1>{}(p.first);auto h2 = hash<T2>{}(p.second);return h1 ^ h2;}
};
template<class T1, class T2, class T3> using ii_umap = gp_hash_table<pair<T1,T2>,T3,iihash>;
template<class T1, class T2> using f_umap = gp_hash_table<T1,T2,chash>;
template<class T1, class T2> using o_umap = gp_hash_table<T1,T2>; */
#define sqr(x) (x)*(x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define debug(x) cerr << #x << " -> " << x << '\n'
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int inf = 1e9 + 7;
const ll infll = 1e18 + 10;
template <typename T> inline T fgcd(T a, T b) {while(b) swap(b, a %= b); return a;}
ll fpow(ll a, ll b) {ll o = 1; for(;b;b >>= 1) {if(b & 1) o = o * a;a = a * a;} return o;}
ll fpow(ll a, ll b, ll m) {ll o = 1; a %= m; for(;b;b >>= 1) {if(b & 1) o = o * a % m;a = a * a % m;} return o;}
template<class T> void uniq(vt<T> &a) {sort(all(a));a.resize(unique(all(a)) - a.begin());}
void setIO(string name = "", string inp = "inp", string out = "out") {
    cin.tie(0)->sync_with_stdio(0);
    if(sz(name)) {
        if(sz(inp)) freopen((name+"."+inp).c_str(), "r", stdin);
        if(sz(out)) freopen((name+"."+out).c_str(), "w", stdout);
    }
}
const int N = 200000, P = 'J' + 'I' + 'O', base = 2309;
ll n,q,x,y,ST[5 * N],laz[5 * N],pref[N + 1],M[N + 1];
char z;
string s;
void up(int id, int l, int mid, int r) {
    if(laz[id]) {
        ST[id * 2] = (pref[n - l] - (n - mid == 0 ? 0 : pref[n - mid - 1]) + inf) % inf * laz[id] % inf;
        ST[id * 2 + 1] = (pref[n - mid - 1] - (n - r == 0 ? 0 : pref[n - r - 1]) + inf) % inf * laz[id] % inf;
        laz[id * 2] = laz[id * 2 + 1] = laz[id];
        laz[id] = 0;
    }
}
void upd(int id, int l, int r, int u, int v, ll k) {
    if(r < u || l > v) return;
    if(l >= u && r <= v) {
        ST[id] = (pref[n - l] - (n - r == 0 ? 0 : pref[n - r - 1]) + inf) % inf * k % inf;
        laz[id] = k;
        return;
    }
    int mid = (l + r) / 2;
    up(id, l, mid, r);
    upd(id * 2, l, mid, u, v, k);
    upd(id * 2 + 1, mid + 1, r, u, v, k);
    ST[id] = (ST[id * 2] + ST[id * 2 + 1]) % inf;
}
string merge(const string &l, const string &r) {
    string t = "";
    for(int i = 0; i < n; i++) t.pb(l[i] == r[i] ? l[i] : char(P - r[i] - l[i]));
    return t;
}
int hbuild(const string &ss) {
    ll cur = 0;
    for(int i = 0; i < n; i++) {
        cur = (cur * base + ss[i]) % inf;
    }
    return cur;
}
int main() {
    setIO();
    cin >> n;
    M[0] = pref[0] = 1;
    for(int i = 1; i <= n; i++) {
        M[i] = M[i - 1] * base % inf;
        pref[i] = (pref[i - 1] + M[i]) % inf;
    }
    vt<string> a,b,c;
    map<int, bool> mpp;
    for(int i = 0; i < 3; i++) {
        cin >> s;
        int t = hbuild(s);
        if(!mpp[t]) {
            a.pb(s);
            b.pb(s);
            mpp[t] = 1;
        }
    }
    while(!a.empty()) {
        int k = sz(b);
        for(auto i : a) {
            for(int j = 0; j < k; j++) {
                string g = merge(i, b[j]);
                int t = hbuild(g);
                if(!mpp[t]) {
                    c.pb(g);
                    b.pb(g);
                    mpp[t] = 1;
                }
            }
        }
        a = c;
        c.clear();
    }
    cin >> q >> s;
    for(int i = 0; i < n; i++) {
        upd(1, 1, n, i + 1, i + 1, s[i]);
    }
    cout << (mpp[ST[1]] ? "Yes" : "No") << '\n';
    while(q--) {
        cin >> x >> y >> z;
        upd(1, 1, n, x, y, z);
        cout << (mpp[ST[1]] ? "Yes" : "No") << '\n';
    }
    return 0;
}

Compilation message

Main.cpp: In function 'void setIO(std::string, std::string, std::string)':
Main.cpp:45:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         if(sz(inp)) freopen((name+"."+inp).c_str(), "r", stdin);
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:46:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         if(sz(out)) freopen((name+"."+out).c_str(), "w", stdout);
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 162 ms 9356 KB Output is correct
2 Correct 182 ms 10020 KB Output is correct
3 Correct 127 ms 5060 KB Output is correct
4 Correct 194 ms 10000 KB Output is correct
5 Correct 169 ms 10184 KB Output is correct
6 Correct 172 ms 9424 KB Output is correct
7 Correct 172 ms 9668 KB Output is correct
8 Correct 185 ms 10308 KB Output is correct
9 Correct 242 ms 9924 KB Output is correct
10 Correct 200 ms 11036 KB Output is correct
11 Correct 192 ms 10568 KB Output is correct
12 Correct 196 ms 11076 KB Output is correct
13 Correct 184 ms 10564 KB Output is correct
14 Correct 179 ms 11116 KB Output is correct
15 Correct 183 ms 10580 KB Output is correct
16 Correct 174 ms 11060 KB Output is correct
17 Correct 172 ms 10564 KB Output is correct
18 Correct 106 ms 3748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 9356 KB Output is correct
2 Correct 182 ms 10020 KB Output is correct
3 Correct 127 ms 5060 KB Output is correct
4 Correct 194 ms 10000 KB Output is correct
5 Correct 169 ms 10184 KB Output is correct
6 Correct 172 ms 9424 KB Output is correct
7 Correct 172 ms 9668 KB Output is correct
8 Correct 185 ms 10308 KB Output is correct
9 Correct 242 ms 9924 KB Output is correct
10 Correct 200 ms 11036 KB Output is correct
11 Correct 192 ms 10568 KB Output is correct
12 Correct 196 ms 11076 KB Output is correct
13 Correct 184 ms 10564 KB Output is correct
14 Correct 179 ms 11116 KB Output is correct
15 Correct 183 ms 10580 KB Output is correct
16 Correct 174 ms 11060 KB Output is correct
17 Correct 172 ms 10564 KB Output is correct
18 Correct 106 ms 3748 KB Output is correct
19 Correct 580 ms 23680 KB Output is correct
20 Correct 479 ms 23304 KB Output is correct
21 Correct 380 ms 24352 KB Output is correct
22 Correct 351 ms 22380 KB Output is correct
23 Correct 269 ms 13324 KB Output is correct
24 Correct 224 ms 12368 KB Output is correct
25 Correct 386 ms 25360 KB Output is correct
26 Correct 437 ms 24104 KB Output is correct
27 Correct 420 ms 25600 KB Output is correct
28 Correct 414 ms 23840 KB Output is correct
29 Correct 410 ms 25268 KB Output is correct
30 Correct 239 ms 13204 KB Output is correct
31 Correct 454 ms 25764 KB Output is correct
32 Correct 434 ms 23240 KB Output is correct
33 Correct 241 ms 12260 KB Output is correct
34 Correct 406 ms 23976 KB Output is correct
35 Correct 329 ms 22696 KB Output is correct
36 Correct 233 ms 12360 KB Output is correct
37 Correct 249 ms 12328 KB Output is correct
38 Correct 361 ms 21272 KB Output is correct
39 Correct 259 ms 20112 KB Output is correct
40 Correct 344 ms 18676 KB Output is correct
41 Correct 449 ms 16664 KB Output is correct
42 Correct 116 ms 14872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 9356 KB Output is correct
2 Correct 182 ms 10020 KB Output is correct
3 Correct 127 ms 5060 KB Output is correct
4 Correct 194 ms 10000 KB Output is correct
5 Correct 169 ms 10184 KB Output is correct
6 Correct 172 ms 9424 KB Output is correct
7 Correct 172 ms 9668 KB Output is correct
8 Correct 185 ms 10308 KB Output is correct
9 Correct 242 ms 9924 KB Output is correct
10 Correct 200 ms 11036 KB Output is correct
11 Correct 192 ms 10568 KB Output is correct
12 Correct 196 ms 11076 KB Output is correct
13 Correct 184 ms 10564 KB Output is correct
14 Correct 179 ms 11116 KB Output is correct
15 Correct 183 ms 10580 KB Output is correct
16 Correct 174 ms 11060 KB Output is correct
17 Correct 172 ms 10564 KB Output is correct
18 Correct 106 ms 3748 KB Output is correct
19 Correct 177 ms 9564 KB Output is correct
20 Correct 142 ms 5060 KB Output is correct
21 Correct 179 ms 10740 KB Output is correct
22 Correct 142 ms 8972 KB Output is correct
23 Correct 173 ms 10788 KB Output is correct
24 Correct 154 ms 9816 KB Output is correct
25 Correct 181 ms 10580 KB Output is correct
26 Correct 150 ms 9540 KB Output is correct
27 Correct 166 ms 10688 KB Output is correct
28 Correct 158 ms 9796 KB Output is correct
29 Correct 166 ms 10236 KB Output is correct
30 Correct 136 ms 9284 KB Output is correct
31 Correct 170 ms 10780 KB Output is correct
32 Correct 177 ms 10800 KB Output is correct
33 Correct 167 ms 10388 KB Output is correct
34 Correct 165 ms 9540 KB Output is correct
35 Correct 189 ms 11128 KB Output is correct
36 Correct 196 ms 10564 KB Output is correct
37 Correct 181 ms 11204 KB Output is correct
38 Correct 183 ms 10664 KB Output is correct
39 Correct 171 ms 11152 KB Output is correct
40 Correct 166 ms 10564 KB Output is correct
41 Correct 186 ms 11144 KB Output is correct
42 Correct 164 ms 10724 KB Output is correct
43 Correct 169 ms 10088 KB Output is correct
44 Correct 182 ms 10468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 9356 KB Output is correct
2 Correct 182 ms 10020 KB Output is correct
3 Correct 127 ms 5060 KB Output is correct
4 Correct 194 ms 10000 KB Output is correct
5 Correct 169 ms 10184 KB Output is correct
6 Correct 172 ms 9424 KB Output is correct
7 Correct 172 ms 9668 KB Output is correct
8 Correct 185 ms 10308 KB Output is correct
9 Correct 242 ms 9924 KB Output is correct
10 Correct 200 ms 11036 KB Output is correct
11 Correct 192 ms 10568 KB Output is correct
12 Correct 196 ms 11076 KB Output is correct
13 Correct 184 ms 10564 KB Output is correct
14 Correct 179 ms 11116 KB Output is correct
15 Correct 183 ms 10580 KB Output is correct
16 Correct 174 ms 11060 KB Output is correct
17 Correct 172 ms 10564 KB Output is correct
18 Correct 106 ms 3748 KB Output is correct
19 Correct 580 ms 23680 KB Output is correct
20 Correct 479 ms 23304 KB Output is correct
21 Correct 380 ms 24352 KB Output is correct
22 Correct 351 ms 22380 KB Output is correct
23 Correct 269 ms 13324 KB Output is correct
24 Correct 224 ms 12368 KB Output is correct
25 Correct 386 ms 25360 KB Output is correct
26 Correct 437 ms 24104 KB Output is correct
27 Correct 420 ms 25600 KB Output is correct
28 Correct 414 ms 23840 KB Output is correct
29 Correct 410 ms 25268 KB Output is correct
30 Correct 239 ms 13204 KB Output is correct
31 Correct 454 ms 25764 KB Output is correct
32 Correct 434 ms 23240 KB Output is correct
33 Correct 241 ms 12260 KB Output is correct
34 Correct 406 ms 23976 KB Output is correct
35 Correct 329 ms 22696 KB Output is correct
36 Correct 233 ms 12360 KB Output is correct
37 Correct 249 ms 12328 KB Output is correct
38 Correct 361 ms 21272 KB Output is correct
39 Correct 259 ms 20112 KB Output is correct
40 Correct 344 ms 18676 KB Output is correct
41 Correct 449 ms 16664 KB Output is correct
42 Correct 116 ms 14872 KB Output is correct
43 Correct 177 ms 9564 KB Output is correct
44 Correct 142 ms 5060 KB Output is correct
45 Correct 179 ms 10740 KB Output is correct
46 Correct 142 ms 8972 KB Output is correct
47 Correct 173 ms 10788 KB Output is correct
48 Correct 154 ms 9816 KB Output is correct
49 Correct 181 ms 10580 KB Output is correct
50 Correct 150 ms 9540 KB Output is correct
51 Correct 166 ms 10688 KB Output is correct
52 Correct 158 ms 9796 KB Output is correct
53 Correct 166 ms 10236 KB Output is correct
54 Correct 136 ms 9284 KB Output is correct
55 Correct 170 ms 10780 KB Output is correct
56 Correct 177 ms 10800 KB Output is correct
57 Correct 167 ms 10388 KB Output is correct
58 Correct 165 ms 9540 KB Output is correct
59 Correct 189 ms 11128 KB Output is correct
60 Correct 196 ms 10564 KB Output is correct
61 Correct 181 ms 11204 KB Output is correct
62 Correct 183 ms 10664 KB Output is correct
63 Correct 171 ms 11152 KB Output is correct
64 Correct 166 ms 10564 KB Output is correct
65 Correct 186 ms 11144 KB Output is correct
66 Correct 164 ms 10724 KB Output is correct
67 Correct 169 ms 10088 KB Output is correct
68 Correct 182 ms 10468 KB Output is correct
69 Correct 515 ms 23392 KB Output is correct
70 Correct 535 ms 24856 KB Output is correct
71 Correct 238 ms 12356 KB Output is correct
72 Correct 238 ms 12512 KB Output is correct
73 Correct 242 ms 12352 KB Output is correct
74 Correct 410 ms 23884 KB Output is correct
75 Correct 253 ms 13292 KB Output is correct
76 Correct 403 ms 25780 KB Output is correct
77 Correct 380 ms 22904 KB Output is correct
78 Correct 237 ms 12540 KB Output is correct
79 Correct 250 ms 12524 KB Output is correct
80 Correct 431 ms 23720 KB Output is correct
81 Correct 245 ms 13356 KB Output is correct
82 Correct 543 ms 26908 KB Output is correct
83 Correct 476 ms 24676 KB Output is correct
84 Correct 245 ms 12488 KB Output is correct
85 Correct 247 ms 12484 KB Output is correct
86 Correct 495 ms 23312 KB Output is correct
87 Correct 578 ms 25424 KB Output is correct
88 Correct 240 ms 11988 KB Output is correct
89 Correct 486 ms 24164 KB Output is correct
90 Correct 529 ms 25728 KB Output is correct
91 Correct 246 ms 11920 KB Output is correct
92 Correct 443 ms 23948 KB Output is correct
93 Correct 230 ms 12408 KB Output is correct
94 Correct 238 ms 12520 KB Output is correct
95 Correct 232 ms 12496 KB Output is correct
96 Correct 359 ms 21180 KB Output is correct
97 Correct 395 ms 22676 KB Output is correct
98 Correct 437 ms 19612 KB Output is correct
99 Correct 505 ms 19408 KB Output is correct
100 Correct 231 ms 17560 KB Output is correct