Submission #476505

#TimeUsernameProblemLanguageResultExecution timeMemory
476505stat0r1cCrossing (JOI21_crossing)C++11
100 / 100
580 ms26908 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...