Submission #847529

# Submission time Handle Problem Language Result Execution time Memory
847529 2023-09-09T19:27:47 Z Mr_Ph Crossing (JOI21_crossing) C++17
100 / 100
2459 ms 31948 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;
    string t;
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]==t[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){
                    if(i!=j)
                st.insert(cross(i,j));
            }
        if(x==st.sz)
            break;
    }
    int q;
    cin>>q;
    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(3*n);
    prfj.resize(3*n);
    prfo.resize(3*n);
    for(auto i:st)
    {
        a=i;
        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:83: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]
   83 |             if(lx>=a.sz)vals[x]=0;
      |                  ^
Main.cpp: In function 'void solve()':
Main.cpp:141: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]
  141 |         if(x==st.sz)
      |             ^
Main.cpp:161: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]
  161 |         for(int j=0;j<a.sz;j++)
      |                      ^
Main.cpp:172: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]
  172 |         for(int j=0;j<arr.sz;j++)
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 56 ms 7796 KB Output is correct
2 Correct 62 ms 8272 KB Output is correct
3 Correct 61 ms 8260 KB Output is correct
4 Correct 53 ms 8016 KB Output is correct
5 Correct 53 ms 8016 KB Output is correct
6 Correct 53 ms 7916 KB Output is correct
7 Correct 54 ms 8016 KB Output is correct
8 Correct 55 ms 8272 KB Output is correct
9 Correct 71 ms 8252 KB Output is correct
10 Correct 56 ms 8272 KB Output is correct
11 Correct 56 ms 8272 KB Output is correct
12 Correct 55 ms 8264 KB Output is correct
13 Correct 60 ms 8272 KB Output is correct
14 Correct 55 ms 8256 KB Output is correct
15 Correct 57 ms 8276 KB Output is correct
16 Correct 60 ms 8272 KB Output is correct
17 Correct 56 ms 8276 KB Output is correct
18 Correct 59 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 7796 KB Output is correct
2 Correct 62 ms 8272 KB Output is correct
3 Correct 61 ms 8260 KB Output is correct
4 Correct 53 ms 8016 KB Output is correct
5 Correct 53 ms 8016 KB Output is correct
6 Correct 53 ms 7916 KB Output is correct
7 Correct 54 ms 8016 KB Output is correct
8 Correct 55 ms 8272 KB Output is correct
9 Correct 71 ms 8252 KB Output is correct
10 Correct 56 ms 8272 KB Output is correct
11 Correct 56 ms 8272 KB Output is correct
12 Correct 55 ms 8264 KB Output is correct
13 Correct 60 ms 8272 KB Output is correct
14 Correct 55 ms 8256 KB Output is correct
15 Correct 57 ms 8276 KB Output is correct
16 Correct 60 ms 8272 KB Output is correct
17 Correct 56 ms 8276 KB Output is correct
18 Correct 59 ms 8272 KB Output is correct
19 Correct 150 ms 29296 KB Output is correct
20 Correct 169 ms 29552 KB Output is correct
21 Correct 107 ms 28048 KB Output is correct
22 Correct 104 ms 26212 KB Output is correct
23 Correct 84 ms 10068 KB Output is correct
24 Correct 100 ms 9852 KB Output is correct
25 Correct 115 ms 29296 KB Output is correct
26 Correct 111 ms 29364 KB Output is correct
27 Correct 132 ms 29300 KB Output is correct
28 Correct 133 ms 29296 KB Output is correct
29 Correct 129 ms 28828 KB Output is correct
30 Correct 90 ms 9832 KB Output is correct
31 Correct 139 ms 29432 KB Output is correct
32 Correct 132 ms 27816 KB Output is correct
33 Correct 84 ms 9808 KB Output is correct
34 Correct 144 ms 29208 KB Output is correct
35 Correct 102 ms 24760 KB Output is correct
36 Correct 83 ms 9808 KB Output is correct
37 Correct 83 ms 9844 KB Output is correct
38 Correct 146 ms 29360 KB Output is correct
39 Correct 84 ms 29296 KB Output is correct
40 Correct 103 ms 21420 KB Output is correct
41 Correct 163 ms 29552 KB Output is correct
42 Correct 60 ms 29292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 7796 KB Output is correct
2 Correct 62 ms 8272 KB Output is correct
3 Correct 61 ms 8260 KB Output is correct
4 Correct 53 ms 8016 KB Output is correct
5 Correct 53 ms 8016 KB Output is correct
6 Correct 53 ms 7916 KB Output is correct
7 Correct 54 ms 8016 KB Output is correct
8 Correct 55 ms 8272 KB Output is correct
9 Correct 71 ms 8252 KB Output is correct
10 Correct 56 ms 8272 KB Output is correct
11 Correct 56 ms 8272 KB Output is correct
12 Correct 55 ms 8264 KB Output is correct
13 Correct 60 ms 8272 KB Output is correct
14 Correct 55 ms 8256 KB Output is correct
15 Correct 57 ms 8276 KB Output is correct
16 Correct 60 ms 8272 KB Output is correct
17 Correct 56 ms 8276 KB Output is correct
18 Correct 59 ms 8272 KB Output is correct
19 Correct 336 ms 7972 KB Output is correct
20 Correct 326 ms 8272 KB Output is correct
21 Correct 111 ms 8272 KB Output is correct
22 Correct 101 ms 7736 KB Output is correct
23 Correct 112 ms 8272 KB Output is correct
24 Correct 110 ms 8016 KB Output is correct
25 Correct 115 ms 8272 KB Output is correct
26 Correct 107 ms 8272 KB Output is correct
27 Correct 112 ms 8256 KB Output is correct
28 Correct 105 ms 7552 KB Output is correct
29 Correct 118 ms 8272 KB Output is correct
30 Correct 103 ms 7820 KB Output is correct
31 Correct 283 ms 8272 KB Output is correct
32 Correct 282 ms 8240 KB Output is correct
33 Correct 286 ms 8272 KB Output is correct
34 Correct 270 ms 7892 KB Output is correct
35 Correct 280 ms 8256 KB Output is correct
36 Correct 288 ms 8272 KB Output is correct
37 Correct 283 ms 8272 KB Output is correct
38 Correct 290 ms 8272 KB Output is correct
39 Correct 300 ms 8256 KB Output is correct
40 Correct 299 ms 8272 KB Output is correct
41 Correct 279 ms 8272 KB Output is correct
42 Correct 290 ms 8272 KB Output is correct
43 Correct 279 ms 8176 KB Output is correct
44 Correct 301 ms 8340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 7796 KB Output is correct
2 Correct 62 ms 8272 KB Output is correct
3 Correct 61 ms 8260 KB Output is correct
4 Correct 53 ms 8016 KB Output is correct
5 Correct 53 ms 8016 KB Output is correct
6 Correct 53 ms 7916 KB Output is correct
7 Correct 54 ms 8016 KB Output is correct
8 Correct 55 ms 8272 KB Output is correct
9 Correct 71 ms 8252 KB Output is correct
10 Correct 56 ms 8272 KB Output is correct
11 Correct 56 ms 8272 KB Output is correct
12 Correct 55 ms 8264 KB Output is correct
13 Correct 60 ms 8272 KB Output is correct
14 Correct 55 ms 8256 KB Output is correct
15 Correct 57 ms 8276 KB Output is correct
16 Correct 60 ms 8272 KB Output is correct
17 Correct 56 ms 8276 KB Output is correct
18 Correct 59 ms 8272 KB Output is correct
19 Correct 150 ms 29296 KB Output is correct
20 Correct 169 ms 29552 KB Output is correct
21 Correct 107 ms 28048 KB Output is correct
22 Correct 104 ms 26212 KB Output is correct
23 Correct 84 ms 10068 KB Output is correct
24 Correct 100 ms 9852 KB Output is correct
25 Correct 115 ms 29296 KB Output is correct
26 Correct 111 ms 29364 KB Output is correct
27 Correct 132 ms 29300 KB Output is correct
28 Correct 133 ms 29296 KB Output is correct
29 Correct 129 ms 28828 KB Output is correct
30 Correct 90 ms 9832 KB Output is correct
31 Correct 139 ms 29432 KB Output is correct
32 Correct 132 ms 27816 KB Output is correct
33 Correct 84 ms 9808 KB Output is correct
34 Correct 144 ms 29208 KB Output is correct
35 Correct 102 ms 24760 KB Output is correct
36 Correct 83 ms 9808 KB Output is correct
37 Correct 83 ms 9844 KB Output is correct
38 Correct 146 ms 29360 KB Output is correct
39 Correct 84 ms 29296 KB Output is correct
40 Correct 103 ms 21420 KB Output is correct
41 Correct 163 ms 29552 KB Output is correct
42 Correct 60 ms 29292 KB Output is correct
43 Correct 336 ms 7972 KB Output is correct
44 Correct 326 ms 8272 KB Output is correct
45 Correct 111 ms 8272 KB Output is correct
46 Correct 101 ms 7736 KB Output is correct
47 Correct 112 ms 8272 KB Output is correct
48 Correct 110 ms 8016 KB Output is correct
49 Correct 115 ms 8272 KB Output is correct
50 Correct 107 ms 8272 KB Output is correct
51 Correct 112 ms 8256 KB Output is correct
52 Correct 105 ms 7552 KB Output is correct
53 Correct 118 ms 8272 KB Output is correct
54 Correct 103 ms 7820 KB Output is correct
55 Correct 283 ms 8272 KB Output is correct
56 Correct 282 ms 8240 KB Output is correct
57 Correct 286 ms 8272 KB Output is correct
58 Correct 270 ms 7892 KB Output is correct
59 Correct 280 ms 8256 KB Output is correct
60 Correct 288 ms 8272 KB Output is correct
61 Correct 283 ms 8272 KB Output is correct
62 Correct 290 ms 8272 KB Output is correct
63 Correct 300 ms 8256 KB Output is correct
64 Correct 299 ms 8272 KB Output is correct
65 Correct 279 ms 8272 KB Output is correct
66 Correct 290 ms 8272 KB Output is correct
67 Correct 279 ms 8176 KB Output is correct
68 Correct 301 ms 8340 KB Output is correct
69 Correct 2342 ms 28236 KB Output is correct
70 Correct 2422 ms 31684 KB Output is correct
71 Correct 195 ms 9888 KB Output is correct
72 Correct 193 ms 10180 KB Output is correct
73 Correct 193 ms 9808 KB Output is correct
74 Correct 334 ms 26732 KB Output is correct
75 Correct 191 ms 9884 KB Output is correct
76 Correct 379 ms 30084 KB Output is correct
77 Correct 317 ms 27176 KB Output is correct
78 Correct 191 ms 9808 KB Output is correct
79 Correct 204 ms 9808 KB Output is correct
80 Correct 1836 ms 26104 KB Output is correct
81 Correct 595 ms 9960 KB Output is correct
82 Correct 2373 ms 31808 KB Output is correct
83 Correct 2321 ms 30580 KB Output is correct
84 Correct 606 ms 10200 KB Output is correct
85 Correct 559 ms 10208 KB Output is correct
86 Correct 2088 ms 26792 KB Output is correct
87 Correct 2459 ms 31780 KB Output is correct
88 Correct 629 ms 10012 KB Output is correct
89 Correct 2071 ms 29412 KB Output is correct
90 Correct 2155 ms 31612 KB Output is correct
91 Correct 639 ms 9984 KB Output is correct
92 Correct 1986 ms 26736 KB Output is correct
93 Correct 568 ms 9952 KB Output is correct
94 Correct 570 ms 9956 KB Output is correct
95 Correct 581 ms 10064 KB Output is correct
96 Correct 143 ms 29380 KB Output is correct
97 Correct 494 ms 31948 KB Output is correct
98 Correct 1495 ms 23028 KB Output is correct
99 Correct 2443 ms 31940 KB Output is correct
100 Correct 1704 ms 31780 KB Output is correct