Submission #1015527

# Submission time Handle Problem Language Result Execution time Memory
1015527 2024-07-06T13:18:42 Z daffuwu Crossing (JOI21_crossing) C++14
0 / 100
67 ms 928 KB
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

long long n, sz, q, l, r, pw3[200069][2], ps[200069][2], sm[2];
const long long dv[] = {1000000007, 1000000009};
pair<long long, long long> ans;
bool bad;
char ch;
string s[3], cs, t0;
vector<string> ls;
map<char, long long> conv;
map<string, bool> ex;
map<pair<long long, long long>, bool> hsh;

char crot(char a, char b)
{
    if (a>b) swap(a, b);
    if (a == b) return a;
    if (a == 'I' && b == 'J') return 'O';
    if (a == 'I' && b == 'O') return 'J';
    return 'I';
}

string cross(string a, string b)
{
    int i;
    string c = "";
    for (i=0; i<n; i++)
    {
        c += crot(a[i], b[i]);
    }
    return c;
}

long long calc(long long l, long long r, long long id)
{
    //3^l+3^(l+1)+...+3^r
    if (l == 0) return ps[r][id];
    return (ps[r][id]-ps[l-1][id]+dv[id])%dv[id];
}

struct segtree
{
    long long l, r, val[2], lz = -1;
    segtree *le, *ri;

    void bd(long long cl, long long cr)
    {
        l = cl;
        r = cr;
        if (cl == cr)
        {
            val[0] = conv[t0[cl-1]]*pw3[cl-1][0]%dv[0];
            val[1] = conv[t0[cl-1]]*pw3[cl-1][1]%dv[1];
            return;
        }
        long long md = (cl+cr)/2;
        le = new segtree();
        ri = new segtree();
        le->bd(cl, md);
        ri->bd(md+1, cr);
        val[0] = (le->val[0]+ri->val[0])%dv[0];
        val[1] = (le->val[1]+ri->val[1])%dv[1];
    }

    void prop()
    {
        if (lz != -1)
        {
            val[0] = calc(l-1, r-1, 0)*lz%dv[0];
            val[1] = calc(l-1, r-1, 1)*lz%dv[1];
            if (l != r)
            {
                le->lz = lz;
                ri->lz = lz;
            }
            lz = -1;
        }
    }

    void upd(long long ql, long long qr, long long x)
    {
        prop();
        if (l>qr || r<ql) return;
        if (l>=ql && r<=qr)
        {
            lz = x;
            prop();
            return;
        }
        le->upd(ql, qr, x);
        ri->upd(ql, qr, x);
        val[0] = (le->val[0]+ri->val[0])%dv[0];
        val[1] = (le->val[1]+ri->val[1])%dv[1];
    }

    pair<long long, long long> qry(long long ql, long long qr)
    {
        prop();
        if (l>qr || r<ql) return {0, 0};
        if (l>=ql && r<=qr) return {val[0], val[1]};
        pair<long long, long long> pl = le->qry(ql, qr), pr = ri->qry(ql, qr);
        return {(pl.fr+pr.fr)%dv[0], (pl.sc+pr.sc)%dv[1]};
    }
} *rt;

int main() 
{
    long long i, j, rr;
    scanf("%lld", &n);
    pw3[0][0] = pw3[0][1] = ps[0][0] = ps[0][1] = 1;
    conv['I'] = 0;
    conv['J'] = 1;
    conv['O'] = 2;
    for (i=1; i<n; i++)
    {
        for (j=0; j<=1; j++)
        {
            pw3[i][j] = pw3[i-1][j]*3%dv[j];
            ps[i][j] = (ps[i-1][j]+pw3[i][j])%dv[j];
        }
    } 
    cin >> s[0] >> s[1] >> s[2]; 
    ex[s[0]] = ex[s[1]] = ex[s[2]] = 1;
    for (auto [ky, _]:ex) ls.push_back(ky);
    for (; 1;)
    {
        sz = ls.size();
        bad = 1;
        for (i=0; i<sz; i++)
        {
            for (j=i+1; j<sz; j++)
            {
                cs = cross(ls[i], ls[j]);
                if (!ex.count(cs))
                {
                    ex[cs] = 1;
                    bad = 0;
                    i = sz+1;
                    break;
                }
            }
        }
        if (bad) break;
        ls.push_back(cs);
    }
    for (auto el:ls)
    {
        for (j=0; j<=1; j++)
        {
            sm[j] = 0;
            for (i=0; i<n; i++)
            {
                sm[j] += pw3[i][j]*conv[el[i]];
                sm[j] %= dv[j];
            }
        }
        hsh[{sm[0], sm[1]}] = 1;
    }
    rt = new segtree();
    scanf("%lld", &q);
    for (rr=0; rr<=q; rr++)
    {
        if (rr == 0)
        {
            cin >> t0;
            rt->bd(1, n);
        }
        else 
        {
            scanf("%lld%lld %c", &l, &r, &ch);
            rt->upd(l, r, conv[ch]);
        }
        ans = rt->qry(1, n);
        if (hsh.count(ans)) printf("Yes\n");
        else printf("No\n");
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:128:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  128 |     for (auto [ky, _]:ex) ls.push_back(ky);
      |               ^
Main.cpp:113:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
Main.cpp:164:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  164 |     scanf("%lld", &q);
      |     ~~~~~^~~~~~~~~~~~
Main.cpp:174:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  174 |             scanf("%lld%lld %c", &l, &r, &ch);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 57 ms 852 KB Output is correct
2 Correct 67 ms 800 KB Output is correct
3 Correct 67 ms 804 KB Output is correct
4 Correct 51 ms 852 KB Output is correct
5 Correct 52 ms 916 KB Output is correct
6 Correct 51 ms 808 KB Output is correct
7 Correct 52 ms 848 KB Output is correct
8 Correct 54 ms 928 KB Output is correct
9 Correct 56 ms 848 KB Output is correct
10 Incorrect 53 ms 848 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 852 KB Output is correct
2 Correct 67 ms 800 KB Output is correct
3 Correct 67 ms 804 KB Output is correct
4 Correct 51 ms 852 KB Output is correct
5 Correct 52 ms 916 KB Output is correct
6 Correct 51 ms 808 KB Output is correct
7 Correct 52 ms 848 KB Output is correct
8 Correct 54 ms 928 KB Output is correct
9 Correct 56 ms 848 KB Output is correct
10 Incorrect 53 ms 848 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 852 KB Output is correct
2 Correct 67 ms 800 KB Output is correct
3 Correct 67 ms 804 KB Output is correct
4 Correct 51 ms 852 KB Output is correct
5 Correct 52 ms 916 KB Output is correct
6 Correct 51 ms 808 KB Output is correct
7 Correct 52 ms 848 KB Output is correct
8 Correct 54 ms 928 KB Output is correct
9 Correct 56 ms 848 KB Output is correct
10 Incorrect 53 ms 848 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 852 KB Output is correct
2 Correct 67 ms 800 KB Output is correct
3 Correct 67 ms 804 KB Output is correct
4 Correct 51 ms 852 KB Output is correct
5 Correct 52 ms 916 KB Output is correct
6 Correct 51 ms 808 KB Output is correct
7 Correct 52 ms 848 KB Output is correct
8 Correct 54 ms 928 KB Output is correct
9 Correct 56 ms 848 KB Output is correct
10 Incorrect 53 ms 848 KB Output isn't correct
11 Halted 0 ms 0 KB -