답안 #537843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537843 2022-03-15T16:40:34 Z cadmiumsky Crossing (JOI21_crossing) C++14
100 / 100
868 ms 44416 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

#define int long long
#define hash uhasfsfjha
const int nmax = 2e5 + 5;
const int mod = 998244353;
int p[2][nmax];
struct hash {
  int v[2] = {0, 0};
  int len = 0;
  hash() {;}
  hash(int ch) {v[0] = ch, v[1] = ch, len = 1;}
  hash(int a, int b, int c) {v[0] = a, v[1] = b, len = c;}
  hash operator +(const hash& x) const {
    return hash((v[0] * p[0][x.len] + x.v[0]) % mod, (v[1] * p[1][x.len] + x.v[1]) % mod, len + x.len);
  }
  ll operator()() const {
    return v[0] * mod + v[1];
  }
};
hash contr[3][nmax];
void inithash(int _0, int _1) {
  p[0][0] = p[0][1] = 1;
  p[0][1] = _0;
  p[1][1] = _1;
  for(int i = 2; i < nmax; i++) {
    p[0][i] = p[0][i - 1] * p[0][1] % mod;
    p[1][i] = p[1][i - 1] * p[1][1] % mod;
  }
  contr[0][1] = hash(0);
  contr[1][1] = hash(1);
  contr[2][1] = hash(2);
  for(int i = 2; i < nmax; i++) {
    for(int j = 0; j < 3; j++)
      contr[j][i] = contr[j][i - 1] + contr[j][1];
  }
}
#undef int

unordered_set<int> freq;
int code(tuple<int,int,int> pp) {
  int x, y, z;
  tie(x, y, z) = pp;
  return x * 3 * 3 + y * 3 + z;
}
void decode(int x, int *to) {
  to[0] = (x % 3), x /= 3, to[1] = (x % 3), x /= 3, to[2] = (x % 3);
  return; 
}
#define stack mata
vector<int> stack;
void insert(int x) { if(!freq.count(x)) freq.insert(x), stack.push_back(x); }
void start() {
  insert(9);
  insert(3);
  insert(1);
  while(stack.size()) {
    int a[3], b[3];
    decode(stack.back(), a);
    stack.pop_back();
    for(auto x : freq) {
      decode(x, b);
      insert(code({(-a[0] + -b[0] + 6) % 3, (-a[1] + -b[1] + 6) % 3, (-a[2] + -b[2] + 6) % 3}));
    }
  }
}

int starter[3][nmax];
int v[nmax];
unordered_set<ll> cine;
int n;

namespace AINT {
  hash aint[nmax * 4];
  int lazy[nmax * 4];
  void apply(int node, int cl, int cr) {
    if(lazy[node] == -1)
      return;
    aint[node] = contr[lazy[node]][cr - cl + 1];
    if(cl == cr)
      return;
    lazy[2 * node] = lazy[node];
    lazy[2 * node + 1] = lazy[node];
    lazy[node] = -1;
  } 
  void prop(int node, int cl, int cr) {
    apply(node, cl, cr);
    if(cl == cr)
      return;
    int mid = cl + cr >> 1;
    apply(2 * node, cl, mid);
    apply(2 * node + 1, mid + 1, cr);
  }
  void upd(int val, int l, int r, int node = 1, int cl = 1, int cr = n) {
    if(l <= cl && cr <= r) {
      lazy[node] = val;
      prop(node, cl, cr);
      return;
    }
    prop(node, cl, cr);
    if(r < cl || cr < l)
      return;
    int mid = cl + cr >> 1;
    upd(val, l, r, 2 * node, cl, mid);
    upd(val, l, r, 2 * node + 1, mid + 1, cr);
    aint[node] = aint[2 * node] + aint[2 * node + 1];
  }
  hash constr(int node = 1, int cl = 1, int cr = n) {
    lazy[node] = -1;
    if(cl == cr)
      return (aint[node] = v[cl]);
    int mid = cl + cr >> 1;
    return aint[node] = constr(node * 2, cl, mid) + constr(2 * node + 1, mid + 1, cr);
  }
  bool query() {
    //cerr << aint[1]() << '\n';
    return cine.count(aint[1]());
  }
};

int encr[256];

int main() {
  encr['O'] = 0;
  encr['J'] = 1;
  encr['I'] = 2;
  char ch;
  inithash(29, 101);
  start();
  cin >> n;
  for(int t = 0; t < 3; t++) {
    for(int i = 1; i <= n; i++) {
      cin >> ch;
      starter[t][i] = encr[ch];
    }
  }
  for(auto x : freq) {
    int aggr[3];
    aggr[0] = x % 3;
    x /= 3;
    aggr[1] = x % 3;
    x /= 3;
    aggr[2] = x % 3;
    hash rez;
    for(int i = 1; i <= n; i++) {
      int y = 0;
      for(int t = 0; t < 3; t++)
        y += aggr[t] * starter[t][i];
      y = (y % 3 + 9) % 3;
      rez = rez + hash(y);
    }
    cine.insert(rez());
  }
  int q;
  cin >> q;
  for(int i = 1; i <= n; i++)
    cin >> ch, v[i] = encr[ch];
  AINT::constr();
  cout << (AINT::query()? "Yes\n" : "No\n");
  for(int i = 0, l, r; i < q; i++) {
    cin >> l >> r >> ch;
    AINT::upd(encr[ch], l, r);
    cout << (AINT::query()? "Yes\n" : "No\n");
  }
}

Compilation message

Main.cpp: In function 'void AINT::prop(int, int, int)':
Main.cpp:92:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   92 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
Main.cpp: In function 'void AINT::upd(int, int, int, int, int, int)':
Main.cpp:105:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  105 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
Main.cpp: In function 'uhasfsfjha AINT::constr(int, int, int)':
Main.cpp:114:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  114 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
Main.cpp: In function 'int main()':
Main.cpp:136:28: warning: array subscript has type 'char' [-Wchar-subscripts]
  136 |       starter[t][i] = encr[ch];
      |                            ^~
Main.cpp:159:28: warning: array subscript has type 'char' [-Wchar-subscripts]
  159 |     cin >> ch, v[i] = encr[ch];
      |                            ^~
Main.cpp:164:20: warning: array subscript has type 'char' [-Wchar-subscripts]
  164 |     AINT::upd(encr[ch], l, r);
      |                    ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 362 ms 36864 KB Output is correct
2 Correct 435 ms 36884 KB Output is correct
3 Correct 409 ms 36844 KB Output is correct
4 Correct 436 ms 36940 KB Output is correct
5 Correct 421 ms 37840 KB Output is correct
6 Correct 404 ms 37836 KB Output is correct
7 Correct 444 ms 37876 KB Output is correct
8 Correct 407 ms 37912 KB Output is correct
9 Correct 421 ms 37872 KB Output is correct
10 Correct 386 ms 37872 KB Output is correct
11 Correct 464 ms 37888 KB Output is correct
12 Correct 391 ms 37836 KB Output is correct
13 Correct 424 ms 37860 KB Output is correct
14 Correct 390 ms 38092 KB Output is correct
15 Correct 426 ms 37872 KB Output is correct
16 Correct 396 ms 37836 KB Output is correct
17 Correct 439 ms 37852 KB Output is correct
18 Correct 401 ms 37900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 362 ms 36864 KB Output is correct
2 Correct 435 ms 36884 KB Output is correct
3 Correct 409 ms 36844 KB Output is correct
4 Correct 436 ms 36940 KB Output is correct
5 Correct 421 ms 37840 KB Output is correct
6 Correct 404 ms 37836 KB Output is correct
7 Correct 444 ms 37876 KB Output is correct
8 Correct 407 ms 37912 KB Output is correct
9 Correct 421 ms 37872 KB Output is correct
10 Correct 386 ms 37872 KB Output is correct
11 Correct 464 ms 37888 KB Output is correct
12 Correct 391 ms 37836 KB Output is correct
13 Correct 424 ms 37860 KB Output is correct
14 Correct 390 ms 38092 KB Output is correct
15 Correct 426 ms 37872 KB Output is correct
16 Correct 396 ms 37836 KB Output is correct
17 Correct 439 ms 37852 KB Output is correct
18 Correct 401 ms 37900 KB Output is correct
19 Correct 798 ms 43156 KB Output is correct
20 Correct 766 ms 43172 KB Output is correct
21 Correct 613 ms 42836 KB Output is correct
22 Correct 609 ms 42504 KB Output is correct
23 Correct 514 ms 38204 KB Output is correct
24 Correct 505 ms 38244 KB Output is correct
25 Correct 683 ms 43200 KB Output is correct
26 Correct 695 ms 43204 KB Output is correct
27 Correct 738 ms 43008 KB Output is correct
28 Correct 859 ms 43048 KB Output is correct
29 Correct 734 ms 42936 KB Output is correct
30 Correct 523 ms 38168 KB Output is correct
31 Correct 731 ms 43012 KB Output is correct
32 Correct 701 ms 42876 KB Output is correct
33 Correct 525 ms 38112 KB Output is correct
34 Correct 702 ms 43064 KB Output is correct
35 Correct 629 ms 42216 KB Output is correct
36 Correct 505 ms 38192 KB Output is correct
37 Correct 487 ms 38220 KB Output is correct
38 Correct 739 ms 43100 KB Output is correct
39 Correct 604 ms 43036 KB Output is correct
40 Correct 624 ms 40940 KB Output is correct
41 Correct 853 ms 43208 KB Output is correct
42 Correct 481 ms 43228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 362 ms 36864 KB Output is correct
2 Correct 435 ms 36884 KB Output is correct
3 Correct 409 ms 36844 KB Output is correct
4 Correct 436 ms 36940 KB Output is correct
5 Correct 421 ms 37840 KB Output is correct
6 Correct 404 ms 37836 KB Output is correct
7 Correct 444 ms 37876 KB Output is correct
8 Correct 407 ms 37912 KB Output is correct
9 Correct 421 ms 37872 KB Output is correct
10 Correct 386 ms 37872 KB Output is correct
11 Correct 464 ms 37888 KB Output is correct
12 Correct 391 ms 37836 KB Output is correct
13 Correct 424 ms 37860 KB Output is correct
14 Correct 390 ms 38092 KB Output is correct
15 Correct 426 ms 37872 KB Output is correct
16 Correct 396 ms 37836 KB Output is correct
17 Correct 439 ms 37852 KB Output is correct
18 Correct 401 ms 37900 KB Output is correct
19 Correct 445 ms 37784 KB Output is correct
20 Correct 427 ms 37924 KB Output is correct
21 Correct 412 ms 38068 KB Output is correct
22 Correct 406 ms 37864 KB Output is correct
23 Correct 392 ms 37940 KB Output is correct
24 Correct 432 ms 37972 KB Output is correct
25 Correct 414 ms 37800 KB Output is correct
26 Correct 389 ms 37940 KB Output is correct
27 Correct 405 ms 37864 KB Output is correct
28 Correct 379 ms 37864 KB Output is correct
29 Correct 410 ms 37880 KB Output is correct
30 Correct 393 ms 37868 KB Output is correct
31 Correct 390 ms 38076 KB Output is correct
32 Correct 407 ms 37996 KB Output is correct
33 Correct 419 ms 37876 KB Output is correct
34 Correct 389 ms 37964 KB Output is correct
35 Correct 408 ms 37988 KB Output is correct
36 Correct 412 ms 37964 KB Output is correct
37 Correct 397 ms 37992 KB Output is correct
38 Correct 409 ms 37888 KB Output is correct
39 Correct 411 ms 37880 KB Output is correct
40 Correct 402 ms 37836 KB Output is correct
41 Correct 428 ms 37848 KB Output is correct
42 Correct 413 ms 37832 KB Output is correct
43 Correct 429 ms 37956 KB Output is correct
44 Correct 438 ms 37888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 362 ms 36864 KB Output is correct
2 Correct 435 ms 36884 KB Output is correct
3 Correct 409 ms 36844 KB Output is correct
4 Correct 436 ms 36940 KB Output is correct
5 Correct 421 ms 37840 KB Output is correct
6 Correct 404 ms 37836 KB Output is correct
7 Correct 444 ms 37876 KB Output is correct
8 Correct 407 ms 37912 KB Output is correct
9 Correct 421 ms 37872 KB Output is correct
10 Correct 386 ms 37872 KB Output is correct
11 Correct 464 ms 37888 KB Output is correct
12 Correct 391 ms 37836 KB Output is correct
13 Correct 424 ms 37860 KB Output is correct
14 Correct 390 ms 38092 KB Output is correct
15 Correct 426 ms 37872 KB Output is correct
16 Correct 396 ms 37836 KB Output is correct
17 Correct 439 ms 37852 KB Output is correct
18 Correct 401 ms 37900 KB Output is correct
19 Correct 798 ms 43156 KB Output is correct
20 Correct 766 ms 43172 KB Output is correct
21 Correct 613 ms 42836 KB Output is correct
22 Correct 609 ms 42504 KB Output is correct
23 Correct 514 ms 38204 KB Output is correct
24 Correct 505 ms 38244 KB Output is correct
25 Correct 683 ms 43200 KB Output is correct
26 Correct 695 ms 43204 KB Output is correct
27 Correct 738 ms 43008 KB Output is correct
28 Correct 859 ms 43048 KB Output is correct
29 Correct 734 ms 42936 KB Output is correct
30 Correct 523 ms 38168 KB Output is correct
31 Correct 731 ms 43012 KB Output is correct
32 Correct 701 ms 42876 KB Output is correct
33 Correct 525 ms 38112 KB Output is correct
34 Correct 702 ms 43064 KB Output is correct
35 Correct 629 ms 42216 KB Output is correct
36 Correct 505 ms 38192 KB Output is correct
37 Correct 487 ms 38220 KB Output is correct
38 Correct 739 ms 43100 KB Output is correct
39 Correct 604 ms 43036 KB Output is correct
40 Correct 624 ms 40940 KB Output is correct
41 Correct 853 ms 43208 KB Output is correct
42 Correct 481 ms 43228 KB Output is correct
43 Correct 445 ms 37784 KB Output is correct
44 Correct 427 ms 37924 KB Output is correct
45 Correct 412 ms 38068 KB Output is correct
46 Correct 406 ms 37864 KB Output is correct
47 Correct 392 ms 37940 KB Output is correct
48 Correct 432 ms 37972 KB Output is correct
49 Correct 414 ms 37800 KB Output is correct
50 Correct 389 ms 37940 KB Output is correct
51 Correct 405 ms 37864 KB Output is correct
52 Correct 379 ms 37864 KB Output is correct
53 Correct 410 ms 37880 KB Output is correct
54 Correct 393 ms 37868 KB Output is correct
55 Correct 390 ms 38076 KB Output is correct
56 Correct 407 ms 37996 KB Output is correct
57 Correct 419 ms 37876 KB Output is correct
58 Correct 389 ms 37964 KB Output is correct
59 Correct 408 ms 37988 KB Output is correct
60 Correct 412 ms 37964 KB Output is correct
61 Correct 397 ms 37992 KB Output is correct
62 Correct 409 ms 37888 KB Output is correct
63 Correct 411 ms 37880 KB Output is correct
64 Correct 402 ms 37836 KB Output is correct
65 Correct 428 ms 37848 KB Output is correct
66 Correct 413 ms 37832 KB Output is correct
67 Correct 429 ms 37956 KB Output is correct
68 Correct 438 ms 37888 KB Output is correct
69 Correct 771 ms 42824 KB Output is correct
70 Correct 794 ms 43608 KB Output is correct
71 Correct 585 ms 39304 KB Output is correct
72 Correct 614 ms 39296 KB Output is correct
73 Correct 604 ms 39260 KB Output is correct
74 Correct 667 ms 43624 KB Output is correct
75 Correct 524 ms 39316 KB Output is correct
76 Correct 737 ms 44224 KB Output is correct
77 Correct 686 ms 43756 KB Output is correct
78 Correct 515 ms 39252 KB Output is correct
79 Correct 520 ms 39344 KB Output is correct
80 Correct 683 ms 43148 KB Output is correct
81 Correct 553 ms 39212 KB Output is correct
82 Correct 743 ms 44152 KB Output is correct
83 Correct 734 ms 43948 KB Output is correct
84 Correct 561 ms 39272 KB Output is correct
85 Correct 544 ms 39276 KB Output is correct
86 Correct 773 ms 43388 KB Output is correct
87 Correct 808 ms 44160 KB Output is correct
88 Correct 554 ms 39252 KB Output is correct
89 Correct 742 ms 43740 KB Output is correct
90 Correct 817 ms 44216 KB Output is correct
91 Correct 533 ms 39244 KB Output is correct
92 Correct 599 ms 43404 KB Output is correct
93 Correct 476 ms 39304 KB Output is correct
94 Correct 487 ms 39380 KB Output is correct
95 Correct 477 ms 39272 KB Output is correct
96 Correct 664 ms 44180 KB Output is correct
97 Correct 620 ms 44224 KB Output is correct
98 Correct 600 ms 42024 KB Output is correct
99 Correct 868 ms 44316 KB Output is correct
100 Correct 442 ms 44416 KB Output is correct