Submission #601493

# Submission time Handle Problem Language Result Execution time Memory
601493 2022-07-22T05:49:37 Z MohammadAghil Crossing (JOI21_crossing) C++17
100 / 100
1922 ms 92076 KB
      #include <bits/stdc++.h>
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) begin(x), end(x)
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     // #ifndef ONLINE_JUDGE
     //      freopen("in.in", "r", stdin);
     //      freopen("out.out", "w", stdout);
     // #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 5e5 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
 
struct SEG{
     vector<int> s, t; int n;
     vector<int> exp, laz;
     vector<bool> seg;

     SEG(){}

     SEG(vector<int> s, vector<int> t): s(s), t(t){
          n = sz(s);
          exp.resize(n<<2), seg.resize(n<<2);
          laz.assign(n<<2, -1);
          build(1, 0, n);
     }

     void build(int x, int lx, int rx){
          if(lx + 1 == rx){
               exp[x] = s[lx], seg[x] = s[lx] == t[lx];
               return;
          }
          int mid = (lx + rx)>>1;
          build(x<<1, lx, mid), build(x<<1|1, mid, rx);
          seg[x] = seg[x<<1]&seg[x<<1|1];
          if(exp[x<<1] == -1 || exp[x<<1|1] == -1 || exp[x<<1] - exp[x<<1|1]) exp[x] = -1;
          else exp[x] = exp[x<<1];
     }

     void updNode(int x, int k){
          seg[x] = exp[x] == k;
          laz[x] = k;
     }

     void shift(int x){
          if(laz[x] + 1){
               updNode(x<<1, laz[x]), updNode(x<<1|1, laz[x]);
               laz[x] = -1;
          }
     }

     void upd(int l, int r, int k, int x, int lx, int rx){
          if(l <= lx && r >= rx){
               updNode(x, k);
               return;
          }
          shift(x);
          int mid = (lx + rx)>>1;
          if(l < mid) upd(l, r, k, x<<1, lx, mid);
          if(mid < r) upd(l, r, k, x<<1|1, mid, rx);
          seg[x] = seg[x<<1]&seg[x<<1|1];
     }

     void upd(int l, int r, int k){ upd(l, r, k, 1, 0, n); }

     bool get(){
          return seg[1];
     }

     vector<int> gt, tg;
     void dfs(int x, int lx, int rx){
          if(lx + 1 == rx) {
               gt.pb(laz[x]), tg.pb(exp[x]);
               return;
          }
          shift(x);
          int mid = (lx + rx)>>1;
          dfs(x<<1, lx, mid), dfs(x<<1|1, mid, rx);
     }
     void dfs(){
          gt.clear(), tg.clear();
          dfs(1, 0, n);
     }
};

vector<int> comb(vector<int> a, vector<int> b){
     vector<int> res = a;
     rep(i,0,sz(a)) res[i] = (6 - a[i] - b[i])%3;
     return res;
}
 
int ID(char c){
     if(c == 'J') return 0;
     if(c == 'O') return 1;
     return 2;
}

string inv(vector<int> t){
     string res;
     for(int c: t){
          if(c == 0) res.pb('J');
          if(c == 1) res.pb('O');
          if(c == 2) res.pb('I');
     }
     return res;
}

int main(){ IOS();
     int n; cin >> n;
     vector<int> s[4];
     rep(i,0,3){
          string t; cin >> t;
          for(char c: t) s[i].pb(ID(c));
     }
     
     int q; cin >> q;
     vector<int> t;
     string tmp; cin >> tmp;
     for(char c: tmp) t.pb(ID(c));

     set<vector<int>> st;
     vector<SEG> sg;
     
     vector<vector<int>> dq;
     rep(i,0,3) st.insert(s[i]), dq.pb(s[i]), sg.pb(SEG(s[i], t));

     while(sz(dq)){
          vector<int> r = dq.back(); dq.pop_back();
          rep(i,0,3){
               vector<int> x = comb(r, s[i]);
               if(st.find(x) == end(st)) st.insert(x), dq.pb(x), sg.pb(SEG(x, t));
          }
     }


     bool ans = false;
     rep(i,0,sz(sg)) ans |= sg[i].get();
     cout << (ans? "Yes\n": "No\n");

     while(q--){
          int l, r; char c; cin >> l >> r >> c; l--;
          int id = ID(c);

          bool ans = false;
          rep(i,0,sz(sg)) sg[i].upd(l, r, id), ans |= sg[i].get();
          
          cout << (ans? "Yes\n": "No\n");
     }
     return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 126 ms 800 KB Output is correct
2 Correct 148 ms 2384 KB Output is correct
3 Correct 145 ms 2436 KB Output is correct
4 Correct 111 ms 2356 KB Output is correct
5 Correct 131 ms 2252 KB Output is correct
6 Correct 106 ms 2288 KB Output is correct
7 Correct 108 ms 2500 KB Output is correct
8 Correct 119 ms 2412 KB Output is correct
9 Correct 112 ms 2448 KB Output is correct
10 Correct 116 ms 2360 KB Output is correct
11 Correct 118 ms 2360 KB Output is correct
12 Correct 113 ms 2408 KB Output is correct
13 Correct 114 ms 2432 KB Output is correct
14 Correct 114 ms 2368 KB Output is correct
15 Correct 120 ms 2460 KB Output is correct
16 Correct 111 ms 2372 KB Output is correct
17 Correct 112 ms 2420 KB Output is correct
18 Correct 124 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 800 KB Output is correct
2 Correct 148 ms 2384 KB Output is correct
3 Correct 145 ms 2436 KB Output is correct
4 Correct 111 ms 2356 KB Output is correct
5 Correct 131 ms 2252 KB Output is correct
6 Correct 106 ms 2288 KB Output is correct
7 Correct 108 ms 2500 KB Output is correct
8 Correct 119 ms 2412 KB Output is correct
9 Correct 112 ms 2448 KB Output is correct
10 Correct 116 ms 2360 KB Output is correct
11 Correct 118 ms 2360 KB Output is correct
12 Correct 113 ms 2408 KB Output is correct
13 Correct 114 ms 2432 KB Output is correct
14 Correct 114 ms 2368 KB Output is correct
15 Correct 120 ms 2460 KB Output is correct
16 Correct 111 ms 2372 KB Output is correct
17 Correct 112 ms 2420 KB Output is correct
18 Correct 124 ms 2296 KB Output is correct
19 Correct 521 ms 36560 KB Output is correct
20 Correct 488 ms 36388 KB Output is correct
21 Correct 309 ms 34356 KB Output is correct
22 Correct 381 ms 31056 KB Output is correct
23 Correct 191 ms 5004 KB Output is correct
24 Correct 204 ms 4964 KB Output is correct
25 Correct 346 ms 36416 KB Output is correct
26 Correct 373 ms 36380 KB Output is correct
27 Correct 402 ms 36476 KB Output is correct
28 Correct 475 ms 36348 KB Output is correct
29 Correct 403 ms 35412 KB Output is correct
30 Correct 226 ms 4976 KB Output is correct
31 Correct 474 ms 36420 KB Output is correct
32 Correct 427 ms 33360 KB Output is correct
33 Correct 198 ms 4944 KB Output is correct
34 Correct 493 ms 36468 KB Output is correct
35 Correct 302 ms 27840 KB Output is correct
36 Correct 216 ms 4852 KB Output is correct
37 Correct 199 ms 4972 KB Output is correct
38 Correct 420 ms 36268 KB Output is correct
39 Correct 257 ms 36496 KB Output is correct
40 Correct 321 ms 25068 KB Output is correct
41 Correct 560 ms 36664 KB Output is correct
42 Correct 74 ms 35812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 800 KB Output is correct
2 Correct 148 ms 2384 KB Output is correct
3 Correct 145 ms 2436 KB Output is correct
4 Correct 111 ms 2356 KB Output is correct
5 Correct 131 ms 2252 KB Output is correct
6 Correct 106 ms 2288 KB Output is correct
7 Correct 108 ms 2500 KB Output is correct
8 Correct 119 ms 2412 KB Output is correct
9 Correct 112 ms 2448 KB Output is correct
10 Correct 116 ms 2360 KB Output is correct
11 Correct 118 ms 2360 KB Output is correct
12 Correct 113 ms 2408 KB Output is correct
13 Correct 114 ms 2432 KB Output is correct
14 Correct 114 ms 2368 KB Output is correct
15 Correct 120 ms 2460 KB Output is correct
16 Correct 111 ms 2372 KB Output is correct
17 Correct 112 ms 2420 KB Output is correct
18 Correct 124 ms 2296 KB Output is correct
19 Correct 293 ms 2472 KB Output is correct
20 Correct 353 ms 2328 KB Output is correct
21 Correct 138 ms 2420 KB Output is correct
22 Correct 120 ms 2256 KB Output is correct
23 Correct 133 ms 2396 KB Output is correct
24 Correct 130 ms 2312 KB Output is correct
25 Correct 142 ms 2452 KB Output is correct
26 Correct 128 ms 2372 KB Output is correct
27 Correct 114 ms 2380 KB Output is correct
28 Correct 104 ms 2324 KB Output is correct
29 Correct 118 ms 2436 KB Output is correct
30 Correct 102 ms 2272 KB Output is correct
31 Correct 243 ms 2404 KB Output is correct
32 Correct 235 ms 2416 KB Output is correct
33 Correct 239 ms 2436 KB Output is correct
34 Correct 208 ms 2360 KB Output is correct
35 Correct 241 ms 2484 KB Output is correct
36 Correct 240 ms 2492 KB Output is correct
37 Correct 239 ms 2464 KB Output is correct
38 Correct 243 ms 2384 KB Output is correct
39 Correct 244 ms 2464 KB Output is correct
40 Correct 247 ms 2456 KB Output is correct
41 Correct 237 ms 2416 KB Output is correct
42 Correct 235 ms 2464 KB Output is correct
43 Correct 224 ms 2508 KB Output is correct
44 Correct 235 ms 2480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 800 KB Output is correct
2 Correct 148 ms 2384 KB Output is correct
3 Correct 145 ms 2436 KB Output is correct
4 Correct 111 ms 2356 KB Output is correct
5 Correct 131 ms 2252 KB Output is correct
6 Correct 106 ms 2288 KB Output is correct
7 Correct 108 ms 2500 KB Output is correct
8 Correct 119 ms 2412 KB Output is correct
9 Correct 112 ms 2448 KB Output is correct
10 Correct 116 ms 2360 KB Output is correct
11 Correct 118 ms 2360 KB Output is correct
12 Correct 113 ms 2408 KB Output is correct
13 Correct 114 ms 2432 KB Output is correct
14 Correct 114 ms 2368 KB Output is correct
15 Correct 120 ms 2460 KB Output is correct
16 Correct 111 ms 2372 KB Output is correct
17 Correct 112 ms 2420 KB Output is correct
18 Correct 124 ms 2296 KB Output is correct
19 Correct 521 ms 36560 KB Output is correct
20 Correct 488 ms 36388 KB Output is correct
21 Correct 309 ms 34356 KB Output is correct
22 Correct 381 ms 31056 KB Output is correct
23 Correct 191 ms 5004 KB Output is correct
24 Correct 204 ms 4964 KB Output is correct
25 Correct 346 ms 36416 KB Output is correct
26 Correct 373 ms 36380 KB Output is correct
27 Correct 402 ms 36476 KB Output is correct
28 Correct 475 ms 36348 KB Output is correct
29 Correct 403 ms 35412 KB Output is correct
30 Correct 226 ms 4976 KB Output is correct
31 Correct 474 ms 36420 KB Output is correct
32 Correct 427 ms 33360 KB Output is correct
33 Correct 198 ms 4944 KB Output is correct
34 Correct 493 ms 36468 KB Output is correct
35 Correct 302 ms 27840 KB Output is correct
36 Correct 216 ms 4852 KB Output is correct
37 Correct 199 ms 4972 KB Output is correct
38 Correct 420 ms 36268 KB Output is correct
39 Correct 257 ms 36496 KB Output is correct
40 Correct 321 ms 25068 KB Output is correct
41 Correct 560 ms 36664 KB Output is correct
42 Correct 74 ms 35812 KB Output is correct
43 Correct 293 ms 2472 KB Output is correct
44 Correct 353 ms 2328 KB Output is correct
45 Correct 138 ms 2420 KB Output is correct
46 Correct 120 ms 2256 KB Output is correct
47 Correct 133 ms 2396 KB Output is correct
48 Correct 130 ms 2312 KB Output is correct
49 Correct 142 ms 2452 KB Output is correct
50 Correct 128 ms 2372 KB Output is correct
51 Correct 114 ms 2380 KB Output is correct
52 Correct 104 ms 2324 KB Output is correct
53 Correct 118 ms 2436 KB Output is correct
54 Correct 102 ms 2272 KB Output is correct
55 Correct 243 ms 2404 KB Output is correct
56 Correct 235 ms 2416 KB Output is correct
57 Correct 239 ms 2436 KB Output is correct
58 Correct 208 ms 2360 KB Output is correct
59 Correct 241 ms 2484 KB Output is correct
60 Correct 240 ms 2492 KB Output is correct
61 Correct 239 ms 2464 KB Output is correct
62 Correct 243 ms 2384 KB Output is correct
63 Correct 244 ms 2464 KB Output is correct
64 Correct 247 ms 2456 KB Output is correct
65 Correct 237 ms 2416 KB Output is correct
66 Correct 235 ms 2464 KB Output is correct
67 Correct 224 ms 2508 KB Output is correct
68 Correct 235 ms 2480 KB Output is correct
69 Correct 1425 ms 77176 KB Output is correct
70 Correct 1398 ms 91928 KB Output is correct
71 Correct 244 ms 5404 KB Output is correct
72 Correct 239 ms 5540 KB Output is correct
73 Correct 255 ms 5612 KB Output is correct
74 Correct 315 ms 32076 KB Output is correct
75 Correct 197 ms 4952 KB Output is correct
76 Correct 400 ms 38028 KB Output is correct
77 Correct 348 ms 32168 KB Output is correct
78 Correct 202 ms 5044 KB Output is correct
79 Correct 196 ms 5068 KB Output is correct
80 Correct 874 ms 66056 KB Output is correct
81 Correct 516 ms 7740 KB Output is correct
82 Correct 1053 ms 92004 KB Output is correct
83 Correct 1040 ms 86500 KB Output is correct
84 Correct 504 ms 7744 KB Output is correct
85 Correct 472 ms 7740 KB Output is correct
86 Correct 1224 ms 70452 KB Output is correct
87 Correct 1434 ms 91916 KB Output is correct
88 Correct 561 ms 7932 KB Output is correct
89 Correct 1218 ms 81220 KB Output is correct
90 Correct 1314 ms 92012 KB Output is correct
91 Correct 534 ms 7760 KB Output is correct
92 Correct 892 ms 69992 KB Output is correct
93 Correct 465 ms 7692 KB Output is correct
94 Correct 476 ms 7700 KB Output is correct
95 Correct 503 ms 7756 KB Output is correct
96 Correct 425 ms 36252 KB Output is correct
97 Correct 622 ms 91940 KB Output is correct
98 Correct 924 ms 61464 KB Output is correct
99 Correct 1922 ms 92076 KB Output is correct
100 Correct 138 ms 91404 KB Output is correct