Submission #600414

# Submission time Handle Problem Language Result Execution time Memory
600414 2022-07-20T20:23:33 Z Plurm Crossing (JOI21_crossing) C++11
49 / 100
588 ms 12828 KB
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9+7;
const int B = 53;
const int invB = 788461544;
int bp[1 << 18];

string sa, sb, sc;
string s, t;

int templ;
void prep(){
  for(char c : s){
    templ = 1ll * templ * B % MOD;
    templ += c;
    templ %= MOD;
  }
}

int seg[1 << 19];
int lb[1 << 19];
int rb[1 << 19];
char lazy[1 << 19];

void build(int c, int l, int r){
  lb[c] = l;
  rb[c] = r;
  if(l == r){
    seg[c] = t[l];
    return;
  }
  int k = (l + r)/2;
  build(2*c, l, k);
  build(2*c+1, k+1, r);
  seg[c] = (1ll * seg[2*c] * bp[r-k] % MOD + seg[2*c+1] % MOD) % MOD;
}

void prop(int c){
  if(lazy[c]){
    seg[c] = 1ll * lazy[c] * ((bp[rb[c] - lb[c] + 1] + MOD - 1) % MOD) % MOD * invB % MOD;
    if(lb[c] != rb[c]){
      lazy[2*c] = lazy[c];
      lazy[2*c+1] = lazy[c];
    }
    lazy[c] = '\0';
  }
}

void update(int c, int l, int r, char x){
  if(lb[c] == l && rb[c] == r) lazy[c] = x;
  prop(c);
  if(lb[c] == l && rb[c] == r) return;
  int k = (lb[c] + rb[c]) /2;
  if(l <= k && k < r){
    update(2*c, l, k, x);
    update(2*c+1, k+1, r, x);
  }else if(r <= k){
    update(2*c, l, r, x);
    prop(2*c+1);
  }else{
    prop(2*c);
    update(2*c+1, l, r, x);
  }
  seg[c] = (1ll * seg[2*c] * bp[rb[c]-k] % MOD + seg[2*c+1] % MOD) % MOD;
}

bool check(){
  prop(1);
  return seg[1] == templ;
}

string cross(string x, string y){
  if(x.empty()) return y;
  else if(y.empty()) return x;
  int n = x.size();
  string ret;
  for(int i = 0; i < n; i++){
    if(x[i] == y[i]) ret.push_back(x[i]);
    else ret.push_back(x[i] ^ y[i] ^ 'J' ^ 'O' ^ 'I');
  }
  return ret;
}

set<string> rec(int left, string cur = ""){
  if(left == 0) return {cur};
  set<string> s = {cur}, t;
  t = rec(left-1, cross(cur, sa));
  s.insert(t.begin(), t.end());
  t = rec(left-1, cross(cur, sb));
  s.insert(t.begin(), t.end());
  t = rec(left-1, cross(cur, sc));
  s.insert(t.begin(), t.end());
  return s;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n >> sa >> sb >> sc;
  int q;
  cin >> q;
  cin >> t;
  if(n <= 100){
    set<string> pool = rec(4);
    cout << (pool.count(t) ? "Yes" : "No") << endl;
    while(q--){
      int l, r;
      char c;
      cin >> l >> r >> c;
      for(int i = l; i <= r; i++){
        t[i-1] = c;
      }
      cout << (pool.count(t) ? "Yes" : "No") << endl;
    }
  }else{
    s = sa;
    bp[0] = 1;
    for(int i = 1; i <= n; i++){
      bp[i] = 1ll * bp[i-1] * B % MOD;
    }
    prep();
    build(1, 0, n-1);
    cout << (check() ? "Yes" : "No") << endl;
    while(q--){
      int l, r;
      char c;
      cin >> l >> r >> c;
      update(1, l-1, r-1, c);
      cout << (check() ? "Yes" : "No") << endl;
    }
  }
  
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 242 ms 816 KB Output is correct
2 Correct 288 ms 880 KB Output is correct
3 Correct 293 ms 896 KB Output is correct
4 Correct 270 ms 880 KB Output is correct
5 Correct 263 ms 936 KB Output is correct
6 Correct 258 ms 788 KB Output is correct
7 Correct 283 ms 904 KB Output is correct
8 Correct 270 ms 908 KB Output is correct
9 Correct 275 ms 836 KB Output is correct
10 Correct 270 ms 1116 KB Output is correct
11 Correct 296 ms 876 KB Output is correct
12 Correct 283 ms 796 KB Output is correct
13 Correct 292 ms 860 KB Output is correct
14 Correct 298 ms 876 KB Output is correct
15 Correct 278 ms 912 KB Output is correct
16 Correct 310 ms 844 KB Output is correct
17 Correct 290 ms 892 KB Output is correct
18 Correct 340 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 242 ms 816 KB Output is correct
2 Correct 288 ms 880 KB Output is correct
3 Correct 293 ms 896 KB Output is correct
4 Correct 270 ms 880 KB Output is correct
5 Correct 263 ms 936 KB Output is correct
6 Correct 258 ms 788 KB Output is correct
7 Correct 283 ms 904 KB Output is correct
8 Correct 270 ms 908 KB Output is correct
9 Correct 275 ms 836 KB Output is correct
10 Correct 270 ms 1116 KB Output is correct
11 Correct 296 ms 876 KB Output is correct
12 Correct 283 ms 796 KB Output is correct
13 Correct 292 ms 860 KB Output is correct
14 Correct 298 ms 876 KB Output is correct
15 Correct 278 ms 912 KB Output is correct
16 Correct 310 ms 844 KB Output is correct
17 Correct 290 ms 892 KB Output is correct
18 Correct 340 ms 848 KB Output is correct
19 Correct 588 ms 9428 KB Output is correct
20 Correct 513 ms 9072 KB Output is correct
21 Correct 376 ms 9292 KB Output is correct
22 Correct 385 ms 9128 KB Output is correct
23 Correct 325 ms 1392 KB Output is correct
24 Correct 341 ms 1460 KB Output is correct
25 Correct 398 ms 9452 KB Output is correct
26 Correct 416 ms 9572 KB Output is correct
27 Correct 417 ms 9472 KB Output is correct
28 Correct 452 ms 9408 KB Output is correct
29 Correct 428 ms 9284 KB Output is correct
30 Correct 347 ms 1420 KB Output is correct
31 Correct 440 ms 9492 KB Output is correct
32 Correct 420 ms 9240 KB Output is correct
33 Correct 341 ms 1528 KB Output is correct
34 Correct 435 ms 9456 KB Output is correct
35 Correct 365 ms 8968 KB Output is correct
36 Correct 333 ms 1440 KB Output is correct
37 Correct 338 ms 1488 KB Output is correct
38 Correct 458 ms 9168 KB Output is correct
39 Correct 351 ms 9060 KB Output is correct
40 Correct 388 ms 5500 KB Output is correct
41 Correct 553 ms 9716 KB Output is correct
42 Correct 270 ms 9156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 242 ms 816 KB Output is correct
2 Correct 288 ms 880 KB Output is correct
3 Correct 293 ms 896 KB Output is correct
4 Correct 270 ms 880 KB Output is correct
5 Correct 263 ms 936 KB Output is correct
6 Correct 258 ms 788 KB Output is correct
7 Correct 283 ms 904 KB Output is correct
8 Correct 270 ms 908 KB Output is correct
9 Correct 275 ms 836 KB Output is correct
10 Correct 270 ms 1116 KB Output is correct
11 Correct 296 ms 876 KB Output is correct
12 Correct 283 ms 796 KB Output is correct
13 Correct 292 ms 860 KB Output is correct
14 Correct 298 ms 876 KB Output is correct
15 Correct 278 ms 912 KB Output is correct
16 Correct 310 ms 844 KB Output is correct
17 Correct 290 ms 892 KB Output is correct
18 Correct 340 ms 848 KB Output is correct
19 Correct 292 ms 916 KB Output is correct
20 Correct 296 ms 980 KB Output is correct
21 Correct 276 ms 896 KB Output is correct
22 Correct 241 ms 956 KB Output is correct
23 Correct 269 ms 876 KB Output is correct
24 Correct 260 ms 836 KB Output is correct
25 Correct 267 ms 908 KB Output is correct
26 Correct 261 ms 864 KB Output is correct
27 Correct 259 ms 912 KB Output is correct
28 Correct 239 ms 792 KB Output is correct
29 Correct 261 ms 880 KB Output is correct
30 Correct 248 ms 980 KB Output is correct
31 Correct 273 ms 944 KB Output is correct
32 Correct 264 ms 872 KB Output is correct
33 Correct 266 ms 944 KB Output is correct
34 Correct 244 ms 928 KB Output is correct
35 Correct 266 ms 932 KB Output is correct
36 Correct 267 ms 900 KB Output is correct
37 Correct 267 ms 792 KB Output is correct
38 Correct 268 ms 812 KB Output is correct
39 Correct 271 ms 824 KB Output is correct
40 Correct 270 ms 844 KB Output is correct
41 Correct 263 ms 820 KB Output is correct
42 Correct 264 ms 844 KB Output is correct
43 Correct 257 ms 884 KB Output is correct
44 Correct 267 ms 936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 242 ms 816 KB Output is correct
2 Correct 288 ms 880 KB Output is correct
3 Correct 293 ms 896 KB Output is correct
4 Correct 270 ms 880 KB Output is correct
5 Correct 263 ms 936 KB Output is correct
6 Correct 258 ms 788 KB Output is correct
7 Correct 283 ms 904 KB Output is correct
8 Correct 270 ms 908 KB Output is correct
9 Correct 275 ms 836 KB Output is correct
10 Correct 270 ms 1116 KB Output is correct
11 Correct 296 ms 876 KB Output is correct
12 Correct 283 ms 796 KB Output is correct
13 Correct 292 ms 860 KB Output is correct
14 Correct 298 ms 876 KB Output is correct
15 Correct 278 ms 912 KB Output is correct
16 Correct 310 ms 844 KB Output is correct
17 Correct 290 ms 892 KB Output is correct
18 Correct 340 ms 848 KB Output is correct
19 Correct 588 ms 9428 KB Output is correct
20 Correct 513 ms 9072 KB Output is correct
21 Correct 376 ms 9292 KB Output is correct
22 Correct 385 ms 9128 KB Output is correct
23 Correct 325 ms 1392 KB Output is correct
24 Correct 341 ms 1460 KB Output is correct
25 Correct 398 ms 9452 KB Output is correct
26 Correct 416 ms 9572 KB Output is correct
27 Correct 417 ms 9472 KB Output is correct
28 Correct 452 ms 9408 KB Output is correct
29 Correct 428 ms 9284 KB Output is correct
30 Correct 347 ms 1420 KB Output is correct
31 Correct 440 ms 9492 KB Output is correct
32 Correct 420 ms 9240 KB Output is correct
33 Correct 341 ms 1528 KB Output is correct
34 Correct 435 ms 9456 KB Output is correct
35 Correct 365 ms 8968 KB Output is correct
36 Correct 333 ms 1440 KB Output is correct
37 Correct 338 ms 1488 KB Output is correct
38 Correct 458 ms 9168 KB Output is correct
39 Correct 351 ms 9060 KB Output is correct
40 Correct 388 ms 5500 KB Output is correct
41 Correct 553 ms 9716 KB Output is correct
42 Correct 270 ms 9156 KB Output is correct
43 Correct 292 ms 916 KB Output is correct
44 Correct 296 ms 980 KB Output is correct
45 Correct 276 ms 896 KB Output is correct
46 Correct 241 ms 956 KB Output is correct
47 Correct 269 ms 876 KB Output is correct
48 Correct 260 ms 836 KB Output is correct
49 Correct 267 ms 908 KB Output is correct
50 Correct 261 ms 864 KB Output is correct
51 Correct 259 ms 912 KB Output is correct
52 Correct 239 ms 792 KB Output is correct
53 Correct 261 ms 880 KB Output is correct
54 Correct 248 ms 980 KB Output is correct
55 Correct 273 ms 944 KB Output is correct
56 Correct 264 ms 872 KB Output is correct
57 Correct 266 ms 944 KB Output is correct
58 Correct 244 ms 928 KB Output is correct
59 Correct 266 ms 932 KB Output is correct
60 Correct 267 ms 900 KB Output is correct
61 Correct 267 ms 792 KB Output is correct
62 Correct 268 ms 812 KB Output is correct
63 Correct 271 ms 824 KB Output is correct
64 Correct 270 ms 844 KB Output is correct
65 Correct 263 ms 820 KB Output is correct
66 Correct 264 ms 844 KB Output is correct
67 Correct 257 ms 884 KB Output is correct
68 Correct 267 ms 936 KB Output is correct
69 Correct 458 ms 12364 KB Output is correct
70 Incorrect 494 ms 12828 KB Output isn't correct
71 Halted 0 ms 0 KB -