답안 #423379

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423379 2021-06-11T04:32:35 Z 반딧불(#7610) Crossing (JOI21_crossing) C++17
100 / 100
3356 ms 96856 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct segTree{
    int ans[800002][3], tree[800002], lazy[800002];

    void init(int i, int l, int r, int *A){
        tree[i] = 0, lazy[i] = -1;
        if(l==r){
            ans[i][A[l]] = 1;
            return;
        }
        int m = (l+r)>>1;
        init(i*2, l, m, A);
        init(i*2+1, m+1, r, A);
        for(int j=0; j<3; j++) ans[i][j] = ans[i*2][j] + ans[i*2+1][j];
    }

    void propagate(int i, int l, int r){
        if(lazy[i] == -1) return;
        tree[i] = ans[i][lazy[i]];
        if(l!=r) lazy[i*2] = lazy[i*2+1] = lazy[i];
        lazy[i] = -1;
    }

    void rangeUpdate(int i, int l, int r, int s, int e, int val){
        propagate(i, l, r);
        if(r<s || e<l) return;
        if(s<=l && r<=e){
            lazy[i] = val;
            propagate(i, l, r);
            return;
        }
        int m = (l+r)>>1;
        rangeUpdate(i*2, l, m, s, e, val);
        rangeUpdate(i*2+1, m+1, r, s, e, val);
        tree[i] = tree[i*2] + tree[i*2+1];
    }
} tree[9];

const char state[9][30] = {
    "000000000111111111222222222",
    "000111222000111222000111222",
    "012012012012012012012012012",
    "000222111222111000111000222",
    "021021021210210210102102102",
    "021210102021210102021210102",
    "021102210102210021210021102",
    "012201120120012201201120012",
    "012120201201012120120201012"
};

int n, q;
int s[3][200002];
int targ[200002];

void print(){
    for(int d=0; d<9; d++){
        if(tree[d].tree[1] == n){
            printf("Yes\n");
            return;
        }
    }
    printf("No\n");
}

int main(){
    scanf("%d", &n);
    for(int i=0; i<3; i++){
        for(int j=1; j<=n; j++){
            char c;
            scanf(" %c", &c);
            if(c == 'J') s[i][j] = 0;
            else if(c == 'O') s[i][j] = 1;
            else s[i][j] = 2;
        }
    }

    for(int d=0; d<9; d++){
        for(int i=1; i<=n; i++){
            int key = s[0][i] * 9 + s[1][i] * 3 + s[2][i];
            targ[i] = state[d][key] - '0';
        }
        tree[d].init(1, 1, n, targ);
    }

    scanf("%d", &q);
    for(int i=1; i<=n; i++){
        char c;
        scanf(" %c", &c);
        for(int d=0; d<9; d++){
            tree[d].rangeUpdate(1, 1, n, i, i, c=='J'?0:c=='O'?1:2);
        }
    }
    print();

    for(int i=1; i<=q; i++){
        int l, r; char c;
        scanf("%d %d %c", &l, &r, &c);
        for(int d=0; d<9; d++){
            tree[d].rangeUpdate(1, 1, n, l, r, c=='J'?0:c=='O'?1:2);
        }
        print();
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:75:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |             scanf(" %c", &c);
      |             ~~~~~^~~~~~~~~~~
Main.cpp:90:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
Main.cpp:93:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         scanf(" %c", &c);
      |         ~~~~~^~~~~~~~~~~
Main.cpp:102:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         scanf("%d %d %c", &l, &r, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 1120 KB Output is correct
2 Correct 268 ms 1156 KB Output is correct
3 Correct 268 ms 1092 KB Output is correct
4 Correct 205 ms 1140 KB Output is correct
5 Correct 206 ms 1100 KB Output is correct
6 Correct 209 ms 1108 KB Output is correct
7 Correct 207 ms 1244 KB Output is correct
8 Correct 221 ms 1136 KB Output is correct
9 Correct 225 ms 1092 KB Output is correct
10 Correct 219 ms 1200 KB Output is correct
11 Correct 224 ms 1092 KB Output is correct
12 Correct 217 ms 1164 KB Output is correct
13 Correct 226 ms 1092 KB Output is correct
14 Correct 217 ms 1092 KB Output is correct
15 Correct 225 ms 1092 KB Output is correct
16 Correct 221 ms 1092 KB Output is correct
17 Correct 223 ms 1136 KB Output is correct
18 Correct 239 ms 1084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 1120 KB Output is correct
2 Correct 268 ms 1156 KB Output is correct
3 Correct 268 ms 1092 KB Output is correct
4 Correct 205 ms 1140 KB Output is correct
5 Correct 206 ms 1100 KB Output is correct
6 Correct 209 ms 1108 KB Output is correct
7 Correct 207 ms 1244 KB Output is correct
8 Correct 221 ms 1136 KB Output is correct
9 Correct 225 ms 1092 KB Output is correct
10 Correct 219 ms 1200 KB Output is correct
11 Correct 224 ms 1092 KB Output is correct
12 Correct 217 ms 1164 KB Output is correct
13 Correct 226 ms 1092 KB Output is correct
14 Correct 217 ms 1092 KB Output is correct
15 Correct 225 ms 1092 KB Output is correct
16 Correct 221 ms 1092 KB Output is correct
17 Correct 223 ms 1136 KB Output is correct
18 Correct 239 ms 1084 KB Output is correct
19 Correct 2869 ms 96632 KB Output is correct
20 Correct 2295 ms 96668 KB Output is correct
21 Correct 1656 ms 96348 KB Output is correct
22 Correct 1710 ms 96100 KB Output is correct
23 Correct 561 ms 7160 KB Output is correct
24 Correct 526 ms 6980 KB Output is correct
25 Correct 1758 ms 96480 KB Output is correct
26 Correct 1891 ms 96648 KB Output is correct
27 Correct 2231 ms 96828 KB Output is correct
28 Correct 2320 ms 96620 KB Output is correct
29 Correct 2285 ms 96356 KB Output is correct
30 Correct 606 ms 6964 KB Output is correct
31 Correct 2149 ms 96780 KB Output is correct
32 Correct 2081 ms 96400 KB Output is correct
33 Correct 548 ms 6992 KB Output is correct
34 Correct 2218 ms 96536 KB Output is correct
35 Correct 1536 ms 95600 KB Output is correct
36 Correct 517 ms 7036 KB Output is correct
37 Correct 537 ms 7124 KB Output is correct
38 Correct 1946 ms 96544 KB Output is correct
39 Correct 859 ms 96436 KB Output is correct
40 Correct 1505 ms 49472 KB Output is correct
41 Correct 3151 ms 96780 KB Output is correct
42 Correct 536 ms 96688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 1120 KB Output is correct
2 Correct 268 ms 1156 KB Output is correct
3 Correct 268 ms 1092 KB Output is correct
4 Correct 205 ms 1140 KB Output is correct
5 Correct 206 ms 1100 KB Output is correct
6 Correct 209 ms 1108 KB Output is correct
7 Correct 207 ms 1244 KB Output is correct
8 Correct 221 ms 1136 KB Output is correct
9 Correct 225 ms 1092 KB Output is correct
10 Correct 219 ms 1200 KB Output is correct
11 Correct 224 ms 1092 KB Output is correct
12 Correct 217 ms 1164 KB Output is correct
13 Correct 226 ms 1092 KB Output is correct
14 Correct 217 ms 1092 KB Output is correct
15 Correct 225 ms 1092 KB Output is correct
16 Correct 221 ms 1092 KB Output is correct
17 Correct 223 ms 1136 KB Output is correct
18 Correct 239 ms 1084 KB Output is correct
19 Correct 257 ms 1016 KB Output is correct
20 Correct 260 ms 1292 KB Output is correct
21 Correct 218 ms 1144 KB Output is correct
22 Correct 182 ms 1008 KB Output is correct
23 Correct 223 ms 1092 KB Output is correct
24 Correct 210 ms 1136 KB Output is correct
25 Correct 225 ms 1140 KB Output is correct
26 Correct 195 ms 1128 KB Output is correct
27 Correct 220 ms 1144 KB Output is correct
28 Correct 192 ms 1092 KB Output is correct
29 Correct 224 ms 1084 KB Output is correct
30 Correct 186 ms 1036 KB Output is correct
31 Correct 221 ms 1212 KB Output is correct
32 Correct 213 ms 1296 KB Output is correct
33 Correct 222 ms 1096 KB Output is correct
34 Correct 192 ms 1168 KB Output is correct
35 Correct 219 ms 1120 KB Output is correct
36 Correct 221 ms 1064 KB Output is correct
37 Correct 221 ms 1088 KB Output is correct
38 Correct 237 ms 1088 KB Output is correct
39 Correct 223 ms 1096 KB Output is correct
40 Correct 221 ms 1128 KB Output is correct
41 Correct 217 ms 1104 KB Output is correct
42 Correct 225 ms 1172 KB Output is correct
43 Correct 218 ms 1220 KB Output is correct
44 Correct 229 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 1120 KB Output is correct
2 Correct 268 ms 1156 KB Output is correct
3 Correct 268 ms 1092 KB Output is correct
4 Correct 205 ms 1140 KB Output is correct
5 Correct 206 ms 1100 KB Output is correct
6 Correct 209 ms 1108 KB Output is correct
7 Correct 207 ms 1244 KB Output is correct
8 Correct 221 ms 1136 KB Output is correct
9 Correct 225 ms 1092 KB Output is correct
10 Correct 219 ms 1200 KB Output is correct
11 Correct 224 ms 1092 KB Output is correct
12 Correct 217 ms 1164 KB Output is correct
13 Correct 226 ms 1092 KB Output is correct
14 Correct 217 ms 1092 KB Output is correct
15 Correct 225 ms 1092 KB Output is correct
16 Correct 221 ms 1092 KB Output is correct
17 Correct 223 ms 1136 KB Output is correct
18 Correct 239 ms 1084 KB Output is correct
19 Correct 2869 ms 96632 KB Output is correct
20 Correct 2295 ms 96668 KB Output is correct
21 Correct 1656 ms 96348 KB Output is correct
22 Correct 1710 ms 96100 KB Output is correct
23 Correct 561 ms 7160 KB Output is correct
24 Correct 526 ms 6980 KB Output is correct
25 Correct 1758 ms 96480 KB Output is correct
26 Correct 1891 ms 96648 KB Output is correct
27 Correct 2231 ms 96828 KB Output is correct
28 Correct 2320 ms 96620 KB Output is correct
29 Correct 2285 ms 96356 KB Output is correct
30 Correct 606 ms 6964 KB Output is correct
31 Correct 2149 ms 96780 KB Output is correct
32 Correct 2081 ms 96400 KB Output is correct
33 Correct 548 ms 6992 KB Output is correct
34 Correct 2218 ms 96536 KB Output is correct
35 Correct 1536 ms 95600 KB Output is correct
36 Correct 517 ms 7036 KB Output is correct
37 Correct 537 ms 7124 KB Output is correct
38 Correct 1946 ms 96544 KB Output is correct
39 Correct 859 ms 96436 KB Output is correct
40 Correct 1505 ms 49472 KB Output is correct
41 Correct 3151 ms 96780 KB Output is correct
42 Correct 536 ms 96688 KB Output is correct
43 Correct 257 ms 1016 KB Output is correct
44 Correct 260 ms 1292 KB Output is correct
45 Correct 218 ms 1144 KB Output is correct
46 Correct 182 ms 1008 KB Output is correct
47 Correct 223 ms 1092 KB Output is correct
48 Correct 210 ms 1136 KB Output is correct
49 Correct 225 ms 1140 KB Output is correct
50 Correct 195 ms 1128 KB Output is correct
51 Correct 220 ms 1144 KB Output is correct
52 Correct 192 ms 1092 KB Output is correct
53 Correct 224 ms 1084 KB Output is correct
54 Correct 186 ms 1036 KB Output is correct
55 Correct 221 ms 1212 KB Output is correct
56 Correct 213 ms 1296 KB Output is correct
57 Correct 222 ms 1096 KB Output is correct
58 Correct 192 ms 1168 KB Output is correct
59 Correct 219 ms 1120 KB Output is correct
60 Correct 221 ms 1064 KB Output is correct
61 Correct 221 ms 1088 KB Output is correct
62 Correct 237 ms 1088 KB Output is correct
63 Correct 223 ms 1096 KB Output is correct
64 Correct 221 ms 1128 KB Output is correct
65 Correct 217 ms 1104 KB Output is correct
66 Correct 225 ms 1172 KB Output is correct
67 Correct 218 ms 1220 KB Output is correct
68 Correct 229 ms 1144 KB Output is correct
69 Correct 2528 ms 96220 KB Output is correct
70 Correct 2278 ms 96624 KB Output is correct
71 Correct 578 ms 6976 KB Output is correct
72 Correct 537 ms 7160 KB Output is correct
73 Correct 549 ms 7180 KB Output is correct
74 Correct 1551 ms 96068 KB Output is correct
75 Correct 578 ms 6952 KB Output is correct
76 Correct 1745 ms 96512 KB Output is correct
77 Correct 1796 ms 96096 KB Output is correct
78 Correct 534 ms 7040 KB Output is correct
79 Correct 529 ms 7044 KB Output is correct
80 Correct 1526 ms 95704 KB Output is correct
81 Correct 539 ms 7056 KB Output is correct
82 Correct 1754 ms 96560 KB Output is correct
83 Correct 1839 ms 96532 KB Output is correct
84 Correct 536 ms 7044 KB Output is correct
85 Correct 525 ms 6944 KB Output is correct
86 Correct 2148 ms 95964 KB Output is correct
87 Correct 2314 ms 96760 KB Output is correct
88 Correct 606 ms 7100 KB Output is correct
89 Correct 1976 ms 96104 KB Output is correct
90 Correct 2139 ms 96592 KB Output is correct
91 Correct 659 ms 7056 KB Output is correct
92 Correct 1479 ms 95848 KB Output is correct
93 Correct 554 ms 7016 KB Output is correct
94 Correct 604 ms 7036 KB Output is correct
95 Correct 554 ms 7196 KB Output is correct
96 Correct 2009 ms 96720 KB Output is correct
97 Correct 868 ms 96684 KB Output is correct
98 Correct 1483 ms 49508 KB Output is correct
99 Correct 3356 ms 96856 KB Output is correct
100 Correct 532 ms 96692 KB Output is correct