답안 #551530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551530 2022-04-21T00:55:38 Z dungnguyenn_05 Crossing (JOI21_crossing) C++17
100 / 100
302 ms 18292 KB
#include<bits/stdc++.h>
#define fs first
#define sc second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const ll mod=1e9+3,N=200005;

ll n,q,h[10],t[N<<2],lz[N<<2],p[N],pre[N];
string s[10],cur;
char c[5]={'J','O','I'};

string xr(string a,string b)
{
    string res="";
    for(int i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            res+=a[i];
            continue;
        }
        for(int j=0;j<3;j++)
            if(c[j]!=a[i] and c[j]!=b[i])
            {
                res+=c[j];
                break;
            }
    }
    return res;
}

void process()
{

    pre[0]=p[0]=1;
    for(int i=1;i<=n;i++)
    {
        p[i]=(p[i-1]*31)%mod;
        pre[i]=(pre[i-1]+p[i])%mod;
    }

    for(int pos=1;pos<=9;pos++)
        for(int i=0;i<n;i++)
            h[pos]=(h[pos]+(s[pos][i]-'A')*p[i])%mod;

}

void down(int node,int l,int r)
{
    if(!lz[node]) return;
    t[node]=(pre[r-l]*lz[node])%mod;
    if(l!=r)
    {
        lz[node<<1]=lz[node];
        lz[node<<1|1]=lz[node];
    }
    lz[node]=0;
}

void upd(int u,int v,int val,int node=1,int l=1,int r=n)
{
    down(node,l,r);
    if(u>r or v<l or l>r) return;
    if(u<=l and r<=v)
    {
        lz[node]=val;
        down(node,l,r);
        return;
    }
    int mid=(l+r)>>1;
    upd(u,v,val,node<<1,l,mid);
    upd(u,v,val,node<<1|1,mid+1,r);
    t[node]=(t[node<<1]+t[node<<1|1]*p[mid-l+1])%mod;
}

ll get()
{
    down(1,1,n);
    return t[1];
}

bool avail()
{
    ll val=get();
    for(int pos=1;pos<=9;pos++)
        if(val==h[pos])
            return 1;

    return 0;
}

void solve()
{
    cin>>n>>s[1]>>s[2]>>s[3];
    s[4]=xr(s[1],s[2]);
    s[5]=xr(s[1],s[3]);
    s[6]=xr(s[2],s[3]);
    s[7]=xr(s[3],s[4]);
    s[8]=xr(s[2],s[5]);
    s[9]=xr(s[1],s[6]);

    process();

    cin>>q>>cur;
    cur=' '+cur;
    for(int i=1;i<=n;i++)
        upd(i,i,cur[i]-'A');

    if(avail())
        cout<<"Yes\n";
    else
        cout<<"No\n";

    while(q--)
    {
        int l,r; char c;
        cin>>l>>r>>c;
        upd(l,r,c-'A');
        if(avail())
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }



}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);  
    int test=1;
    // cin>>test;
    while(test--)
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 2228 KB Output is correct
2 Correct 71 ms 2476 KB Output is correct
3 Correct 84 ms 2308 KB Output is correct
4 Correct 65 ms 2320 KB Output is correct
5 Correct 59 ms 2328 KB Output is correct
6 Correct 61 ms 2232 KB Output is correct
7 Correct 62 ms 2380 KB Output is correct
8 Correct 69 ms 2452 KB Output is correct
9 Correct 66 ms 2492 KB Output is correct
10 Correct 63 ms 2468 KB Output is correct
11 Correct 71 ms 2472 KB Output is correct
12 Correct 66 ms 2420 KB Output is correct
13 Correct 63 ms 2448 KB Output is correct
14 Correct 66 ms 2556 KB Output is correct
15 Correct 63 ms 2464 KB Output is correct
16 Correct 68 ms 2372 KB Output is correct
17 Correct 64 ms 2432 KB Output is correct
18 Correct 65 ms 2376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 2228 KB Output is correct
2 Correct 71 ms 2476 KB Output is correct
3 Correct 84 ms 2308 KB Output is correct
4 Correct 65 ms 2320 KB Output is correct
5 Correct 59 ms 2328 KB Output is correct
6 Correct 61 ms 2232 KB Output is correct
7 Correct 62 ms 2380 KB Output is correct
8 Correct 69 ms 2452 KB Output is correct
9 Correct 66 ms 2492 KB Output is correct
10 Correct 63 ms 2468 KB Output is correct
11 Correct 71 ms 2472 KB Output is correct
12 Correct 66 ms 2420 KB Output is correct
13 Correct 63 ms 2448 KB Output is correct
14 Correct 66 ms 2556 KB Output is correct
15 Correct 63 ms 2464 KB Output is correct
16 Correct 68 ms 2372 KB Output is correct
17 Correct 64 ms 2432 KB Output is correct
18 Correct 65 ms 2376 KB Output is correct
19 Correct 257 ms 18116 KB Output is correct
20 Correct 259 ms 17132 KB Output is correct
21 Correct 224 ms 17444 KB Output is correct
22 Correct 222 ms 16828 KB Output is correct
23 Correct 101 ms 4212 KB Output is correct
24 Correct 105 ms 4032 KB Output is correct
25 Correct 229 ms 18088 KB Output is correct
26 Correct 216 ms 17992 KB Output is correct
27 Correct 231 ms 17976 KB Output is correct
28 Correct 236 ms 18052 KB Output is correct
29 Correct 240 ms 17868 KB Output is correct
30 Correct 107 ms 4068 KB Output is correct
31 Correct 254 ms 18020 KB Output is correct
32 Correct 216 ms 17252 KB Output is correct
33 Correct 105 ms 4080 KB Output is correct
34 Correct 247 ms 17944 KB Output is correct
35 Correct 180 ms 16156 KB Output is correct
36 Correct 106 ms 4196 KB Output is correct
37 Correct 109 ms 4220 KB Output is correct
38 Correct 243 ms 17096 KB Output is correct
39 Correct 184 ms 17128 KB Output is correct
40 Correct 176 ms 11980 KB Output is correct
41 Correct 302 ms 18292 KB Output is correct
42 Correct 115 ms 16444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 2228 KB Output is correct
2 Correct 71 ms 2476 KB Output is correct
3 Correct 84 ms 2308 KB Output is correct
4 Correct 65 ms 2320 KB Output is correct
5 Correct 59 ms 2328 KB Output is correct
6 Correct 61 ms 2232 KB Output is correct
7 Correct 62 ms 2380 KB Output is correct
8 Correct 69 ms 2452 KB Output is correct
9 Correct 66 ms 2492 KB Output is correct
10 Correct 63 ms 2468 KB Output is correct
11 Correct 71 ms 2472 KB Output is correct
12 Correct 66 ms 2420 KB Output is correct
13 Correct 63 ms 2448 KB Output is correct
14 Correct 66 ms 2556 KB Output is correct
15 Correct 63 ms 2464 KB Output is correct
16 Correct 68 ms 2372 KB Output is correct
17 Correct 64 ms 2432 KB Output is correct
18 Correct 65 ms 2376 KB Output is correct
19 Correct 73 ms 2392 KB Output is correct
20 Correct 79 ms 2276 KB Output is correct
21 Correct 64 ms 2464 KB Output is correct
22 Correct 55 ms 2252 KB Output is correct
23 Correct 65 ms 2472 KB Output is correct
24 Correct 64 ms 2312 KB Output is correct
25 Correct 63 ms 2380 KB Output is correct
26 Correct 59 ms 2384 KB Output is correct
27 Correct 64 ms 2432 KB Output is correct
28 Correct 56 ms 2216 KB Output is correct
29 Correct 66 ms 2528 KB Output is correct
30 Correct 56 ms 2256 KB Output is correct
31 Correct 63 ms 2388 KB Output is correct
32 Correct 62 ms 2380 KB Output is correct
33 Correct 62 ms 2468 KB Output is correct
34 Correct 59 ms 2228 KB Output is correct
35 Correct 63 ms 2432 KB Output is correct
36 Correct 63 ms 2440 KB Output is correct
37 Correct 64 ms 2400 KB Output is correct
38 Correct 64 ms 2416 KB Output is correct
39 Correct 65 ms 2472 KB Output is correct
40 Correct 64 ms 2380 KB Output is correct
41 Correct 63 ms 2380 KB Output is correct
42 Correct 68 ms 2436 KB Output is correct
43 Correct 60 ms 2380 KB Output is correct
44 Correct 65 ms 2436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 2228 KB Output is correct
2 Correct 71 ms 2476 KB Output is correct
3 Correct 84 ms 2308 KB Output is correct
4 Correct 65 ms 2320 KB Output is correct
5 Correct 59 ms 2328 KB Output is correct
6 Correct 61 ms 2232 KB Output is correct
7 Correct 62 ms 2380 KB Output is correct
8 Correct 69 ms 2452 KB Output is correct
9 Correct 66 ms 2492 KB Output is correct
10 Correct 63 ms 2468 KB Output is correct
11 Correct 71 ms 2472 KB Output is correct
12 Correct 66 ms 2420 KB Output is correct
13 Correct 63 ms 2448 KB Output is correct
14 Correct 66 ms 2556 KB Output is correct
15 Correct 63 ms 2464 KB Output is correct
16 Correct 68 ms 2372 KB Output is correct
17 Correct 64 ms 2432 KB Output is correct
18 Correct 65 ms 2376 KB Output is correct
19 Correct 257 ms 18116 KB Output is correct
20 Correct 259 ms 17132 KB Output is correct
21 Correct 224 ms 17444 KB Output is correct
22 Correct 222 ms 16828 KB Output is correct
23 Correct 101 ms 4212 KB Output is correct
24 Correct 105 ms 4032 KB Output is correct
25 Correct 229 ms 18088 KB Output is correct
26 Correct 216 ms 17992 KB Output is correct
27 Correct 231 ms 17976 KB Output is correct
28 Correct 236 ms 18052 KB Output is correct
29 Correct 240 ms 17868 KB Output is correct
30 Correct 107 ms 4068 KB Output is correct
31 Correct 254 ms 18020 KB Output is correct
32 Correct 216 ms 17252 KB Output is correct
33 Correct 105 ms 4080 KB Output is correct
34 Correct 247 ms 17944 KB Output is correct
35 Correct 180 ms 16156 KB Output is correct
36 Correct 106 ms 4196 KB Output is correct
37 Correct 109 ms 4220 KB Output is correct
38 Correct 243 ms 17096 KB Output is correct
39 Correct 184 ms 17128 KB Output is correct
40 Correct 176 ms 11980 KB Output is correct
41 Correct 302 ms 18292 KB Output is correct
42 Correct 115 ms 16444 KB Output is correct
43 Correct 73 ms 2392 KB Output is correct
44 Correct 79 ms 2276 KB Output is correct
45 Correct 64 ms 2464 KB Output is correct
46 Correct 55 ms 2252 KB Output is correct
47 Correct 65 ms 2472 KB Output is correct
48 Correct 64 ms 2312 KB Output is correct
49 Correct 63 ms 2380 KB Output is correct
50 Correct 59 ms 2384 KB Output is correct
51 Correct 64 ms 2432 KB Output is correct
52 Correct 56 ms 2216 KB Output is correct
53 Correct 66 ms 2528 KB Output is correct
54 Correct 56 ms 2256 KB Output is correct
55 Correct 63 ms 2388 KB Output is correct
56 Correct 62 ms 2380 KB Output is correct
57 Correct 62 ms 2468 KB Output is correct
58 Correct 59 ms 2228 KB Output is correct
59 Correct 63 ms 2432 KB Output is correct
60 Correct 63 ms 2440 KB Output is correct
61 Correct 64 ms 2400 KB Output is correct
62 Correct 64 ms 2416 KB Output is correct
63 Correct 65 ms 2472 KB Output is correct
64 Correct 64 ms 2380 KB Output is correct
65 Correct 63 ms 2380 KB Output is correct
66 Correct 68 ms 2436 KB Output is correct
67 Correct 60 ms 2380 KB Output is correct
68 Correct 65 ms 2436 KB Output is correct
69 Correct 242 ms 16504 KB Output is correct
70 Correct 275 ms 17168 KB Output is correct
71 Correct 104 ms 4104 KB Output is correct
72 Correct 101 ms 4044 KB Output is correct
73 Correct 102 ms 4164 KB Output is correct
74 Correct 188 ms 16824 KB Output is correct
75 Correct 102 ms 4048 KB Output is correct
76 Correct 228 ms 18044 KB Output is correct
77 Correct 201 ms 16756 KB Output is correct
78 Correct 101 ms 4080 KB Output is correct
79 Correct 104 ms 4044 KB Output is correct
80 Correct 181 ms 15832 KB Output is correct
81 Correct 100 ms 4044 KB Output is correct
82 Correct 229 ms 17992 KB Output is correct
83 Correct 214 ms 17572 KB Output is correct
84 Correct 110 ms 3992 KB Output is correct
85 Correct 99 ms 4020 KB Output is correct
86 Correct 198 ms 16232 KB Output is correct
87 Correct 228 ms 17976 KB Output is correct
88 Correct 108 ms 4044 KB Output is correct
89 Correct 210 ms 16988 KB Output is correct
90 Correct 224 ms 18032 KB Output is correct
91 Correct 106 ms 4044 KB Output is correct
92 Correct 188 ms 16096 KB Output is correct
93 Correct 98 ms 4032 KB Output is correct
94 Correct 101 ms 4068 KB Output is correct
95 Correct 105 ms 4076 KB Output is correct
96 Correct 227 ms 17116 KB Output is correct
97 Correct 182 ms 17004 KB Output is correct
98 Correct 182 ms 11976 KB Output is correct
99 Correct 287 ms 18240 KB Output is correct
100 Correct 121 ms 16484 KB Output is correct