Submission #847526

# Submission time Handle Problem Language Result Execution time Memory
847526 2023-09-09T19:24:29 Z Mr_Ph Crossing (JOI21_crossing) C++14
100 / 100
2456 ms 42940 KB
///Never gonna give you up.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
const ll mod=(ll)1e9+7;
const ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
string cross(string a,string b)
{
    string ans;
    for(int i=0; i<a.sz; i++)
    {
        if(a[i]==b[i])
            ans+=a[i];
        else
        {
            set<char>st;
            st.insert('J');
            st.insert('O');
            st.insert('I');
            st.erase(a[i]);
            st.erase(b[i]);
            ans+=*st.begin();
        }
    }
    return ans;
}
int n;
string a,b;
vector<int>prfo;
vector<int>prfi;
vector<int>prfj;
struct segtree
{
    vi vals;
    int siz=1;
    vector<char>lazy;
    void init(int n)
    {
        while(siz<n)
            siz*=2;
        vals.resize(2*siz);
        lazy.resize(2*siz);
    }
    void check(int l,int r,int x)
    {
        //cout<<l<<" "<<r<<" "<<lazy[x]<<" "<<vals[x]<<endl;
        if(lazy[x]!='-')
        {
            int p=0;
            if(lazy[x]=='O')p=prfo[r]-(l==0?0:prfo[l-1]);
            if(lazy[x]=='I')p=prfi[r]-(l==0?0:prfi[l-1]);
            if(lazy[x]=='J')p=prfj[r]-(l==0?0:prfj[l-1]);
            if(l!=r){
                lazy[2*x+1]=lazy[x];
                lazy[2*x+2]=lazy[x];
            }
            vals[x]=p;
            lazy[x]='-';
        }
    }
    void build(int x,int lx,int rx)
    {
        lazy[x]='-';
        if(lx==rx)
        {
            if(lx>=a.sz)vals[x]=0;
            else
            vals[x]=(a[lx]==b[lx]);
            return;
        }
        int mid=(lx+rx+1)/2;
        build(2*x+1,lx,mid-1);
        build(2*x+2,mid,rx);
        vals[x]=vals[2*x+1]+vals[2*x+2];
    }
    void build()
    {
        build(0,0,siz-1);
    }
    void updrange(int l,int r,char v,int x,int lx,int rx)
    {
        check(lx,rx,x);
        if(lx>r||rx<l)return;
        //cout<<lx<<" "<<rx<<" "<<x<<endl;
        if(rx<=r&&lx>=l)
        {
            int p=0;
            if(v=='O')p=prfo[rx]-(lx==0?0:prfo[lx-1]);
            if(v=='I')p=prfi[rx]-(lx==0?0:prfi[lx-1]);
            if(v=='J')p=prfj[rx]-(lx==0?0:prfj[lx-1]);
            vals[x]=p;
            if(lx!=rx)lazy[2*x+1]=v,lazy[2*x+2]=v,lazy[x]='-';
            return;
        }
        int mid=(lx+rx+1)/2;
        updrange(l,r,v,2*x+1,lx,mid-1);
        updrange(l,r,v,2*x+2,mid,rx);
        vals[x]=vals[2*x+1]+vals[2*x+2];
    }
    void updrange(int l,int r,char x)
    {
        updrange(l,r,x,0,0,siz-1);
    }

};
void preprocess() {}
void solve()
{
    cin>>n;
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    set<string>st;
    st.insert(s1);
    st.insert(s2);
    st.insert(s3);
    while(true)
    {
        int x=st.sz;
        for(auto i:st)
            for(auto j:st)
                st.insert(cross(i,j));
        if(x==st.sz)
            break;
    }
    int q;
    cin>>q;
    string t;
    cin>>t;
    if(st.find(t)!=st.end())cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    vector<pair<pair<int,int>,char>>arr(q);
    for(int i=0;i<q;i++)cin>>arr[i].first.first>>arr[i].first.second>>arr[i].second;
    vi ans(q);
    segtree sg;
    sg.init(n);
    prfi.resize(5*n);
    prfj.resize(5*n);
    prfo.resize(5*n);
    for(auto i:st)
    {
        a=i;
        b=t;
        int sumo=0,sumi=0,sumj=0;
        for(int j=0;j<a.sz;j++)
        {
            sumo+=(a[j]=='O');
            sumi+=(a[j]=='I');
            sumj+=(a[j]=='J');
            prfo[j]=sumo;
            prfi[j]=sumi;
            prfj[j]=sumj;
        }
       // cout<<sumo<<" "<<sumi<<" "<<sumj<<endl;
        sg.build();
        for(int j=0;j<arr.sz;j++)
        {
            sg.updrange(arr[j].first.first-1,arr[j].first.second-1,arr[j].second);
           // cout<<sg.vals[0]<<" "<<j<<" amsdiomas"<<endl;
            if(sg.vals[0]==n)ans[j]=1;
        }
    }
    for(auto i:ans)
    {
        if(i==1)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}
signed main()
{
    // freopen("div7.in","r",stdin);
    //freopen("div7.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    preprocess();
    //bla();
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}

Compilation message

Main.cpp: In function 'std::string cross(std::string, std::string)':
Main.cpp:26:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0; i<a.sz; i++)
      |                   ^
Main.cpp: In member function 'void segtree::build(long long int, long long int, long long int)':
Main.cpp:82:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |             if(lx>=a.sz)vals[x]=0;
      |                  ^
Main.cpp: In function 'void solve()':
Main.cpp:138:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::set<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |         if(x==st.sz)
      |             ^
Main.cpp:160:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  160 |         for(int j=0;j<a.sz;j++)
      |                      ^
Main.cpp:171:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  171 |         for(int j=0;j<arr.sz;j++)
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 58 ms 6736 KB Output is correct
2 Correct 63 ms 7296 KB Output is correct
3 Correct 59 ms 7244 KB Output is correct
4 Correct 55 ms 6992 KB Output is correct
5 Correct 52 ms 6896 KB Output is correct
6 Correct 53 ms 6900 KB Output is correct
7 Correct 54 ms 6992 KB Output is correct
8 Correct 54 ms 7252 KB Output is correct
9 Correct 57 ms 7236 KB Output is correct
10 Correct 56 ms 7244 KB Output is correct
11 Correct 64 ms 7188 KB Output is correct
12 Correct 59 ms 7248 KB Output is correct
13 Correct 58 ms 7248 KB Output is correct
14 Correct 56 ms 7244 KB Output is correct
15 Correct 58 ms 7248 KB Output is correct
16 Correct 57 ms 7240 KB Output is correct
17 Correct 55 ms 7240 KB Output is correct
18 Correct 56 ms 7244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 6736 KB Output is correct
2 Correct 63 ms 7296 KB Output is correct
3 Correct 59 ms 7244 KB Output is correct
4 Correct 55 ms 6992 KB Output is correct
5 Correct 52 ms 6896 KB Output is correct
6 Correct 53 ms 6900 KB Output is correct
7 Correct 54 ms 6992 KB Output is correct
8 Correct 54 ms 7252 KB Output is correct
9 Correct 57 ms 7236 KB Output is correct
10 Correct 56 ms 7244 KB Output is correct
11 Correct 64 ms 7188 KB Output is correct
12 Correct 59 ms 7248 KB Output is correct
13 Correct 58 ms 7248 KB Output is correct
14 Correct 56 ms 7244 KB Output is correct
15 Correct 58 ms 7248 KB Output is correct
16 Correct 57 ms 7240 KB Output is correct
17 Correct 55 ms 7240 KB Output is correct
18 Correct 56 ms 7244 KB Output is correct
19 Correct 157 ms 36936 KB Output is correct
20 Correct 163 ms 38636 KB Output is correct
21 Correct 104 ms 38544 KB Output is correct
22 Correct 111 ms 35748 KB Output is correct
23 Correct 83 ms 11188 KB Output is correct
24 Correct 83 ms 11088 KB Output is correct
25 Correct 126 ms 40632 KB Output is correct
26 Correct 115 ms 40628 KB Output is correct
27 Correct 137 ms 40632 KB Output is correct
28 Correct 130 ms 40628 KB Output is correct
29 Correct 124 ms 39740 KB Output is correct
30 Correct 93 ms 11348 KB Output is correct
31 Correct 130 ms 40608 KB Output is correct
32 Correct 130 ms 37980 KB Output is correct
33 Correct 83 ms 11088 KB Output is correct
34 Correct 125 ms 40500 KB Output is correct
35 Correct 108 ms 33248 KB Output is correct
36 Correct 85 ms 11088 KB Output is correct
37 Correct 86 ms 11344 KB Output is correct
38 Correct 145 ms 40372 KB Output is correct
39 Correct 87 ms 40668 KB Output is correct
40 Correct 109 ms 29212 KB Output is correct
41 Correct 164 ms 40884 KB Output is correct
42 Correct 63 ms 40056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 6736 KB Output is correct
2 Correct 63 ms 7296 KB Output is correct
3 Correct 59 ms 7244 KB Output is correct
4 Correct 55 ms 6992 KB Output is correct
5 Correct 52 ms 6896 KB Output is correct
6 Correct 53 ms 6900 KB Output is correct
7 Correct 54 ms 6992 KB Output is correct
8 Correct 54 ms 7252 KB Output is correct
9 Correct 57 ms 7236 KB Output is correct
10 Correct 56 ms 7244 KB Output is correct
11 Correct 64 ms 7188 KB Output is correct
12 Correct 59 ms 7248 KB Output is correct
13 Correct 58 ms 7248 KB Output is correct
14 Correct 56 ms 7244 KB Output is correct
15 Correct 58 ms 7248 KB Output is correct
16 Correct 57 ms 7240 KB Output is correct
17 Correct 55 ms 7240 KB Output is correct
18 Correct 56 ms 7244 KB Output is correct
19 Correct 337 ms 6952 KB Output is correct
20 Correct 324 ms 7236 KB Output is correct
21 Correct 114 ms 7244 KB Output is correct
22 Correct 102 ms 6740 KB Output is correct
23 Correct 110 ms 7244 KB Output is correct
24 Correct 115 ms 6992 KB Output is correct
25 Correct 113 ms 7252 KB Output is correct
26 Correct 111 ms 7016 KB Output is correct
27 Correct 120 ms 7248 KB Output is correct
28 Correct 104 ms 6692 KB Output is correct
29 Correct 117 ms 7204 KB Output is correct
30 Correct 109 ms 6736 KB Output is correct
31 Correct 292 ms 7232 KB Output is correct
32 Correct 282 ms 7736 KB Output is correct
33 Correct 292 ms 7232 KB Output is correct
34 Correct 262 ms 6860 KB Output is correct
35 Correct 285 ms 7240 KB Output is correct
36 Correct 295 ms 7236 KB Output is correct
37 Correct 287 ms 7248 KB Output is correct
38 Correct 294 ms 7244 KB Output is correct
39 Correct 283 ms 7244 KB Output is correct
40 Correct 295 ms 7232 KB Output is correct
41 Correct 284 ms 7248 KB Output is correct
42 Correct 291 ms 7244 KB Output is correct
43 Correct 280 ms 7448 KB Output is correct
44 Correct 295 ms 7240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 6736 KB Output is correct
2 Correct 63 ms 7296 KB Output is correct
3 Correct 59 ms 7244 KB Output is correct
4 Correct 55 ms 6992 KB Output is correct
5 Correct 52 ms 6896 KB Output is correct
6 Correct 53 ms 6900 KB Output is correct
7 Correct 54 ms 6992 KB Output is correct
8 Correct 54 ms 7252 KB Output is correct
9 Correct 57 ms 7236 KB Output is correct
10 Correct 56 ms 7244 KB Output is correct
11 Correct 64 ms 7188 KB Output is correct
12 Correct 59 ms 7248 KB Output is correct
13 Correct 58 ms 7248 KB Output is correct
14 Correct 56 ms 7244 KB Output is correct
15 Correct 58 ms 7248 KB Output is correct
16 Correct 57 ms 7240 KB Output is correct
17 Correct 55 ms 7240 KB Output is correct
18 Correct 56 ms 7244 KB Output is correct
19 Correct 157 ms 36936 KB Output is correct
20 Correct 163 ms 38636 KB Output is correct
21 Correct 104 ms 38544 KB Output is correct
22 Correct 111 ms 35748 KB Output is correct
23 Correct 83 ms 11188 KB Output is correct
24 Correct 83 ms 11088 KB Output is correct
25 Correct 126 ms 40632 KB Output is correct
26 Correct 115 ms 40628 KB Output is correct
27 Correct 137 ms 40632 KB Output is correct
28 Correct 130 ms 40628 KB Output is correct
29 Correct 124 ms 39740 KB Output is correct
30 Correct 93 ms 11348 KB Output is correct
31 Correct 130 ms 40608 KB Output is correct
32 Correct 130 ms 37980 KB Output is correct
33 Correct 83 ms 11088 KB Output is correct
34 Correct 125 ms 40500 KB Output is correct
35 Correct 108 ms 33248 KB Output is correct
36 Correct 85 ms 11088 KB Output is correct
37 Correct 86 ms 11344 KB Output is correct
38 Correct 145 ms 40372 KB Output is correct
39 Correct 87 ms 40668 KB Output is correct
40 Correct 109 ms 29212 KB Output is correct
41 Correct 164 ms 40884 KB Output is correct
42 Correct 63 ms 40056 KB Output is correct
43 Correct 337 ms 6952 KB Output is correct
44 Correct 324 ms 7236 KB Output is correct
45 Correct 114 ms 7244 KB Output is correct
46 Correct 102 ms 6740 KB Output is correct
47 Correct 110 ms 7244 KB Output is correct
48 Correct 115 ms 6992 KB Output is correct
49 Correct 113 ms 7252 KB Output is correct
50 Correct 111 ms 7016 KB Output is correct
51 Correct 120 ms 7248 KB Output is correct
52 Correct 104 ms 6692 KB Output is correct
53 Correct 117 ms 7204 KB Output is correct
54 Correct 109 ms 6736 KB Output is correct
55 Correct 292 ms 7232 KB Output is correct
56 Correct 282 ms 7736 KB Output is correct
57 Correct 292 ms 7232 KB Output is correct
58 Correct 262 ms 6860 KB Output is correct
59 Correct 285 ms 7240 KB Output is correct
60 Correct 295 ms 7236 KB Output is correct
61 Correct 287 ms 7248 KB Output is correct
62 Correct 294 ms 7244 KB Output is correct
63 Correct 283 ms 7244 KB Output is correct
64 Correct 295 ms 7232 KB Output is correct
65 Correct 284 ms 7248 KB Output is correct
66 Correct 291 ms 7244 KB Output is correct
67 Correct 280 ms 7448 KB Output is correct
68 Correct 295 ms 7240 KB Output is correct
69 Correct 2376 ms 37352 KB Output is correct
70 Correct 2375 ms 42716 KB Output is correct
71 Correct 195 ms 11192 KB Output is correct
72 Correct 193 ms 11088 KB Output is correct
73 Correct 194 ms 11244 KB Output is correct
74 Correct 302 ms 35964 KB Output is correct
75 Correct 190 ms 11344 KB Output is correct
76 Correct 334 ms 41152 KB Output is correct
77 Correct 333 ms 36392 KB Output is correct
78 Correct 195 ms 11176 KB Output is correct
79 Correct 195 ms 11216 KB Output is correct
80 Correct 1809 ms 34012 KB Output is correct
81 Correct 571 ms 11244 KB Output is correct
82 Correct 2395 ms 42512 KB Output is correct
83 Correct 2275 ms 40668 KB Output is correct
84 Correct 591 ms 11260 KB Output is correct
85 Correct 554 ms 11244 KB Output is correct
86 Correct 2100 ms 35544 KB Output is correct
87 Correct 2456 ms 42652 KB Output is correct
88 Correct 636 ms 11252 KB Output is correct
89 Correct 2090 ms 38780 KB Output is correct
90 Correct 2197 ms 42652 KB Output is correct
91 Correct 638 ms 11112 KB Output is correct
92 Correct 1932 ms 35152 KB Output is correct
93 Correct 563 ms 11236 KB Output is correct
94 Correct 605 ms 11236 KB Output is correct
95 Correct 579 ms 11284 KB Output is correct
96 Correct 157 ms 40508 KB Output is correct
97 Correct 498 ms 42696 KB Output is correct
98 Correct 1482 ms 30816 KB Output is correct
99 Correct 2404 ms 42940 KB Output is correct
100 Correct 1711 ms 41948 KB Output is correct