답안 #513175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
513175 2022-01-17T03:04:13 Z czhang2718 Crossing (JOI21_crossing) C++17
100 / 100
6720 ms 508564 KB
#include "bits/stdc++.h"
using namespace std;

typedef vector<int> vi;

const int N=200001;
const int no_op=-1;

int n, q;
string a, b, c, t;

struct segtree{
  int n;
  string s;
  vector<vi> cnt;
  vector<int> lazy;
  vector<int> good;

  void build(int x, int lx, int rx){
    if(rx-lx==1){
      cnt[x][s[lx]-'0']=1;
      return;
    }
    int m=(lx+rx)/2;
    build(2*x+1, lx, m);
    build(2*x+2, m, rx);
    for(int i=0; i<3; i++){
      cnt[x][i]=cnt[2*x+1][i]+cnt[2*x+2][i];
    }
  }

  segtree(int n, string s){
    this->n=n, this->s=s;
    cnt.resize(4*n, vi(3));
    lazy.resize(4*n, no_op);
    good.resize(4*n); 
    build(0, 0, n);
  }

  void push(int x, int lx, int rx){
    if(rx-lx==1 || lazy[x]==no_op) return;
    int v=lazy[x];
    good[2*x+1]=cnt[2*x+1][v];
    good[2*x+2]=cnt[2*x+2][v];
    lazy[2*x+1]=lazy[2*x+2]=v;
    lazy[x]=no_op;
  }

  void upd(int l, int r, int v, int x, int lx, int rx){
    push(x, lx, rx);
    if(lx>=r || rx<=l) return;
    if(lx>=l && rx<=r){
      lazy[x]=v;
      good[x]=cnt[x][v];
      return;
    }
    int m=(lx+rx)/2;
    upd(l, r, v, 2*x+1, lx, m);
    upd(l, r, v, 2*x+2, m, rx);
    good[x]=good[2*x+1]+good[2*x+2];
  }

  void upd(int l, int r, int v){ upd(l, r, v, 0, 0, n); }
  bool query(){ return good[0]==n; }
};

int main(){
  cin.tie(0)->sync_with_stdio(0);

  cin >> n >> a >> b >> c;
  map<char, char> mp={{'J', '0'}, {'O', '1'}, {'I', '2'}};
  for(int i=0; i<n; i++){
    a[i]=mp[a[i]];
    b[i]=mp[b[i]];
    c[i]=mp[c[i]];
  }

  vector<segtree> seg;
  vector<int> h(3);
  h[0]=h[1]=h[2]=1;
  for(int z=0; z<3; z++){
    h[z]=-1;
    string s="";
    for(int p=0; p<n; p++){
      int A=a[p]-'0';
      int B=b[p]-'0';
      int C=c[p]-'0';
      int d=(h[0]*A+h[1]*B+h[2]*C+9)%3;
      s+=static_cast<char>('0'+d);
    }
    segtree st(n, s);
    seg.push_back(st);
    h[z]=1;
  }

  h[0]=h[1]=h[2]=-1;
  for(int z=0; z<3; z++){
    h[z]=0;
    string s="";
    for(int p=0; p<n; p++){
      int A=a[p]-'0';
      int B=b[p]-'0';
      int C=c[p]-'0';
      int d=(h[0]*A+h[1]*B+h[2]*C+9)%3;
      s+=static_cast<char>('0'+d);
    }
    segtree st(n, s);
    seg.push_back(st);
    h[z]=-1;
  }

  h[0]=h[1]=h[2]=0;
  for(int z=0; z<3; z++){
    h[z]=1;
    string s="";
    for(int p=0; p<n; p++){
      int A=a[p]-'0';
      int B=b[p]-'0';
      int C=c[p]-'0';
      int d=(h[0]*A+h[1]*B+h[2]*C+9)%3;
      s+=static_cast<char>('0'+d);
    }
    segtree st(n, s);
    seg.push_back(st);
    h[z]=0;
  }

  auto upd=[&](int l, int r, int v){
    for(int i=0; i<9; i++){
      seg[i].upd(l, r, v);
    }
  };

  auto any=[&]()->bool{
    for(int i=0; i<9; i++){
      if(seg[i].query()) return 1;
    }
    return 0;
  };

  cin >> q >> t;
  for(int i=0; i<n; i++){
    upd(i, i+1, mp[t[i]]-'0');
  }
  cout << (any()?"Yes":"No") << "\n";
  while(q--){
    int l, r; char c; cin >> l >> r >> c;
    l--, r--;
    int v=mp[c]-'0';
    upd(l, r+1, v);
    cout << (any()?"Yes":"No") << "\n";
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 972 KB Output is correct
2 Correct 376 ms 2668 KB Output is correct
3 Correct 405 ms 2500 KB Output is correct
4 Correct 309 ms 2512 KB Output is correct
5 Correct 246 ms 2460 KB Output is correct
6 Correct 255 ms 2484 KB Output is correct
7 Correct 262 ms 2668 KB Output is correct
8 Correct 328 ms 2744 KB Output is correct
9 Correct 274 ms 2652 KB Output is correct
10 Correct 293 ms 2684 KB Output is correct
11 Correct 270 ms 2612 KB Output is correct
12 Correct 312 ms 2608 KB Output is correct
13 Correct 289 ms 2636 KB Output is correct
14 Correct 324 ms 2616 KB Output is correct
15 Correct 285 ms 2616 KB Output is correct
16 Correct 290 ms 2652 KB Output is correct
17 Correct 315 ms 2684 KB Output is correct
18 Correct 372 ms 2500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 972 KB Output is correct
2 Correct 376 ms 2668 KB Output is correct
3 Correct 405 ms 2500 KB Output is correct
4 Correct 309 ms 2512 KB Output is correct
5 Correct 246 ms 2460 KB Output is correct
6 Correct 255 ms 2484 KB Output is correct
7 Correct 262 ms 2668 KB Output is correct
8 Correct 328 ms 2744 KB Output is correct
9 Correct 274 ms 2652 KB Output is correct
10 Correct 293 ms 2684 KB Output is correct
11 Correct 270 ms 2612 KB Output is correct
12 Correct 312 ms 2608 KB Output is correct
13 Correct 289 ms 2636 KB Output is correct
14 Correct 324 ms 2616 KB Output is correct
15 Correct 285 ms 2616 KB Output is correct
16 Correct 290 ms 2652 KB Output is correct
17 Correct 315 ms 2684 KB Output is correct
18 Correct 372 ms 2500 KB Output is correct
19 Correct 6272 ms 508320 KB Output is correct
20 Correct 6288 ms 508376 KB Output is correct
21 Correct 3508 ms 478456 KB Output is correct
22 Correct 3417 ms 429416 KB Output is correct
23 Correct 1092 ms 29220 KB Output is correct
24 Correct 1128 ms 28876 KB Output is correct
25 Correct 3703 ms 508388 KB Output is correct
26 Correct 3798 ms 508376 KB Output is correct
27 Correct 4696 ms 508292 KB Output is correct
28 Correct 4675 ms 508480 KB Output is correct
29 Correct 4535 ms 494156 KB Output is correct
30 Correct 1242 ms 29284 KB Output is correct
31 Correct 4604 ms 508352 KB Output is correct
32 Correct 4330 ms 463744 KB Output is correct
33 Correct 1135 ms 28548 KB Output is correct
34 Correct 4743 ms 508300 KB Output is correct
35 Correct 2825 ms 379532 KB Output is correct
36 Correct 1098 ms 28624 KB Output is correct
37 Correct 1378 ms 28752 KB Output is correct
38 Correct 4172 ms 508156 KB Output is correct
39 Correct 1966 ms 508424 KB Output is correct
40 Correct 2877 ms 334460 KB Output is correct
41 Correct 6720 ms 508564 KB Output is correct
42 Correct 1454 ms 507792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 972 KB Output is correct
2 Correct 376 ms 2668 KB Output is correct
3 Correct 405 ms 2500 KB Output is correct
4 Correct 309 ms 2512 KB Output is correct
5 Correct 246 ms 2460 KB Output is correct
6 Correct 255 ms 2484 KB Output is correct
7 Correct 262 ms 2668 KB Output is correct
8 Correct 328 ms 2744 KB Output is correct
9 Correct 274 ms 2652 KB Output is correct
10 Correct 293 ms 2684 KB Output is correct
11 Correct 270 ms 2612 KB Output is correct
12 Correct 312 ms 2608 KB Output is correct
13 Correct 289 ms 2636 KB Output is correct
14 Correct 324 ms 2616 KB Output is correct
15 Correct 285 ms 2616 KB Output is correct
16 Correct 290 ms 2652 KB Output is correct
17 Correct 315 ms 2684 KB Output is correct
18 Correct 372 ms 2500 KB Output is correct
19 Correct 320 ms 2488 KB Output is correct
20 Correct 398 ms 2480 KB Output is correct
21 Correct 279 ms 2628 KB Output is correct
22 Correct 249 ms 2540 KB Output is correct
23 Correct 279 ms 2652 KB Output is correct
24 Correct 278 ms 2552 KB Output is correct
25 Correct 274 ms 2632 KB Output is correct
26 Correct 251 ms 2528 KB Output is correct
27 Correct 262 ms 2568 KB Output is correct
28 Correct 260 ms 2380 KB Output is correct
29 Correct 265 ms 2752 KB Output is correct
30 Correct 223 ms 2372 KB Output is correct
31 Correct 274 ms 2668 KB Output is correct
32 Correct 269 ms 2536 KB Output is correct
33 Correct 274 ms 2644 KB Output is correct
34 Correct 234 ms 2384 KB Output is correct
35 Correct 284 ms 2684 KB Output is correct
36 Correct 267 ms 2628 KB Output is correct
37 Correct 314 ms 2776 KB Output is correct
38 Correct 279 ms 2628 KB Output is correct
39 Correct 268 ms 2876 KB Output is correct
40 Correct 271 ms 2580 KB Output is correct
41 Correct 266 ms 2636 KB Output is correct
42 Correct 268 ms 2628 KB Output is correct
43 Correct 257 ms 2596 KB Output is correct
44 Correct 265 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 972 KB Output is correct
2 Correct 376 ms 2668 KB Output is correct
3 Correct 405 ms 2500 KB Output is correct
4 Correct 309 ms 2512 KB Output is correct
5 Correct 246 ms 2460 KB Output is correct
6 Correct 255 ms 2484 KB Output is correct
7 Correct 262 ms 2668 KB Output is correct
8 Correct 328 ms 2744 KB Output is correct
9 Correct 274 ms 2652 KB Output is correct
10 Correct 293 ms 2684 KB Output is correct
11 Correct 270 ms 2612 KB Output is correct
12 Correct 312 ms 2608 KB Output is correct
13 Correct 289 ms 2636 KB Output is correct
14 Correct 324 ms 2616 KB Output is correct
15 Correct 285 ms 2616 KB Output is correct
16 Correct 290 ms 2652 KB Output is correct
17 Correct 315 ms 2684 KB Output is correct
18 Correct 372 ms 2500 KB Output is correct
19 Correct 6272 ms 508320 KB Output is correct
20 Correct 6288 ms 508376 KB Output is correct
21 Correct 3508 ms 478456 KB Output is correct
22 Correct 3417 ms 429416 KB Output is correct
23 Correct 1092 ms 29220 KB Output is correct
24 Correct 1128 ms 28876 KB Output is correct
25 Correct 3703 ms 508388 KB Output is correct
26 Correct 3798 ms 508376 KB Output is correct
27 Correct 4696 ms 508292 KB Output is correct
28 Correct 4675 ms 508480 KB Output is correct
29 Correct 4535 ms 494156 KB Output is correct
30 Correct 1242 ms 29284 KB Output is correct
31 Correct 4604 ms 508352 KB Output is correct
32 Correct 4330 ms 463744 KB Output is correct
33 Correct 1135 ms 28548 KB Output is correct
34 Correct 4743 ms 508300 KB Output is correct
35 Correct 2825 ms 379532 KB Output is correct
36 Correct 1098 ms 28624 KB Output is correct
37 Correct 1378 ms 28752 KB Output is correct
38 Correct 4172 ms 508156 KB Output is correct
39 Correct 1966 ms 508424 KB Output is correct
40 Correct 2877 ms 334460 KB Output is correct
41 Correct 6720 ms 508564 KB Output is correct
42 Correct 1454 ms 507792 KB Output is correct
43 Correct 320 ms 2488 KB Output is correct
44 Correct 398 ms 2480 KB Output is correct
45 Correct 279 ms 2628 KB Output is correct
46 Correct 249 ms 2540 KB Output is correct
47 Correct 279 ms 2652 KB Output is correct
48 Correct 278 ms 2552 KB Output is correct
49 Correct 274 ms 2632 KB Output is correct
50 Correct 251 ms 2528 KB Output is correct
51 Correct 262 ms 2568 KB Output is correct
52 Correct 260 ms 2380 KB Output is correct
53 Correct 265 ms 2752 KB Output is correct
54 Correct 223 ms 2372 KB Output is correct
55 Correct 274 ms 2668 KB Output is correct
56 Correct 269 ms 2536 KB Output is correct
57 Correct 274 ms 2644 KB Output is correct
58 Correct 234 ms 2384 KB Output is correct
59 Correct 284 ms 2684 KB Output is correct
60 Correct 267 ms 2628 KB Output is correct
61 Correct 314 ms 2776 KB Output is correct
62 Correct 279 ms 2628 KB Output is correct
63 Correct 268 ms 2876 KB Output is correct
64 Correct 271 ms 2580 KB Output is correct
65 Correct 266 ms 2636 KB Output is correct
66 Correct 268 ms 2628 KB Output is correct
67 Correct 257 ms 2596 KB Output is correct
68 Correct 265 ms 2648 KB Output is correct
69 Correct 5146 ms 425780 KB Output is correct
70 Correct 5228 ms 508184 KB Output is correct
71 Correct 1166 ms 28936 KB Output is correct
72 Correct 1061 ms 29392 KB Output is correct
73 Correct 1188 ms 29792 KB Output is correct
74 Correct 3061 ms 424424 KB Output is correct
75 Correct 1083 ms 28584 KB Output is correct
76 Correct 3414 ms 508432 KB Output is correct
77 Correct 3581 ms 424908 KB Output is correct
78 Correct 1058 ms 28840 KB Output is correct
79 Correct 1157 ms 29140 KB Output is correct
80 Correct 2847 ms 362652 KB Output is correct
81 Correct 1113 ms 28468 KB Output is correct
82 Correct 3497 ms 508556 KB Output is correct
83 Correct 3623 ms 477980 KB Output is correct
84 Correct 1018 ms 28640 KB Output is correct
85 Correct 1032 ms 28544 KB Output is correct
86 Correct 4070 ms 387080 KB Output is correct
87 Correct 4785 ms 508356 KB Output is correct
88 Correct 1261 ms 29252 KB Output is correct
89 Correct 4118 ms 448292 KB Output is correct
90 Correct 4307 ms 508376 KB Output is correct
91 Correct 1264 ms 28776 KB Output is correct
92 Correct 2950 ms 380840 KB Output is correct
93 Correct 1174 ms 28516 KB Output is correct
94 Correct 1100 ms 28548 KB Output is correct
95 Correct 1064 ms 29128 KB Output is correct
96 Correct 4957 ms 508184 KB Output is correct
97 Correct 1973 ms 508436 KB Output is correct
98 Correct 2764 ms 334448 KB Output is correct
99 Correct 6695 ms 508548 KB Output is correct
100 Correct 1485 ms 507784 KB Output is correct