QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#299726#1207. Building 3wxhtzdy100 ✓54ms17044kbC++201.3kb2024-01-07 05:48:352024-01-07 05:48:35

Judging History

你现在查看的是最新测评结果

  • [2024-01-07 05:48:35]
  • 评测
  • 测评结果:100
  • 用时:54ms
  • 内存:17044kb
  • [2024-01-07 05:48:35]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> b[i];
  }
  vector<int> mx(n - 1);
  vector<bool> good(n - 1);
  for (int i = 0; i < n - 1; i++) {
    mx[i] = (i == 0 ? b[i] : max(mx[i - 1], b[i]));
    if (i == 0) {
      good[i] = (b[i] == 1); 
    } else {
      good[i] = (good[i - 1] & (b[i] <= mx[i - 1] + 1));
    }
  }
  long long ans = 0;
  {
    vector<int> seq;
    seq.push_back(1);
    for (int i = 0; i < n - 1; i++) {
      seq.push_back(b[i]);
    }
    bool ok = (seq[0] == 1);
    int mx = 1;
    for (int i = 1; i < n; i++) {
      if (seq[i] > mx + 1) {
        ok = false;
        break;
      }
      mx = max(mx, seq[i]);
    }
    ans += ok;
  }
  set<int> st;
  for (int i = n - 1; i >= 1; i--) {
    if (good[i - 1] && (int) st.size() < 2) {
      if ((int) st.size() == 1) {
        int x = *st.begin();
        if (b[i - 1] != x && x <= mx[i - 1] + 1) {
          ans += 1;
        }
      } else {
        int c = mx[i - 1] + 1;
        if (b[i - 1] <= c) {
          c -= 1;
        }
        ans += c;
      }
    }
    if (i > 1 && b[i - 1] > mx[i - 2] + 1) {
      st.insert(b[i - 1] - 1);
    }
  }
  cout << ans << '\n';
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 3480kb

input:

2
2

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3480kb

input:

2
1

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

8
1
1
3
3
4
4
6

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

8
1
4
2
2
2
2
2

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

8
1
1
1
1
3
4
4

output:

4

result:

ok single line: '4'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

8
1
2
3
4
5
6
7

output:

29

result:

ok single line: '29'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3520kb

input:

8
1
1
1
1
1
1
1

output:

8

result:

ok single line: '8'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

8
1
1
1
1
1
1
1

output:

8

result:

ok single line: '8'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

8
1
2
1
1
2
1
3

output:

15

result:

ok single line: '15'

Subtask #2:

score: 30
Accepted

Dependency #1:

100%
Accepted

Test #10:

score: 30
Accepted
time: 0ms
memory: 3796kb

input:

300
1
1
1
2
2
3
1
4
1
3
1
3
4
3
1
3
3
2
5
1
2
6
4
7
5
2
3
7
1
1
8
7
5
5
7
1
9
2
3
5
7
4
3
7
1
3
3
9
2
4
3
8
7
9
8
3
8
6
3
6
7
7
10
9
6
11
2
1
6
8
11
1
1
10
2
11
12
13
8
8
6
4
13
4
2
12
13
8
1
1
1
8
13
11
14
8
14
15
7
12
10
12
11
15
12
14
12
3
15
4
11
9
11
2
6
15
11
13
11
2
9
9
13
5
12
10
4
9
13
2
11...

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

300
1
1
2
2
3
4
5
4
2
3
4
2
5
4
3
2
1
6
4
5
1
2
3
7
8
4
1
5
1
6
5
2
9
4
9
3
3
9
1
5
1
3
1
9
5
1
10
2
40
6
2
7
9
1
6
11
6
9
10
7
6
5
5
11
10
6
11
3
2
2
1
5
7
5
12
4
9
5
6
8
5
2
1
13
1
1
6
4
1
14
2
5
7
5
7
7
9
12
2
10
6
10
7
14
1
9
11
8
11
2
12
2
13
2
14
7
13
11
7
8
1
14
12
3
7
3
12
5
5
5
8
8
10
3
4
1...

output:

0

result:

ok single line: '0'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

300
1
1
2
1
1
2
3
4
4
5
3
4
2
6
1
1
7
1
6
2
7
7
7
7
6
3
3
8
3
8
3
7
3
6
5
2
3
2
4
5
2
8
2
1
6
8
3
4
4
2
2
8
3
5
2
7
7
9
6
9
5
5
5
8
2
8
10
10
6
7
9
10
5
4
6
3
5
1
2
1
2
6
1
1
11
6
6
9
11
2
6
4
11
9
7
9
5
4
10
8
12
11
11
7
11
6
7
12
12
13
12
4
12
7
12
2
7
10
3
10
9
9
4
6
7
7
5
10
7
11
7
1
4
8
10
9
5
...

output:

58

result:

ok single line: '58'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

300
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
...

output:

44851

result:

ok single line: '44851'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

300
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
10...

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

300
1
2
3
4
5
6
7
8
9
10
11
11
12
13
14
15
16
17
18
19
19
20
21
22
23
19
24
25
26
27
28
29
30
31
32
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
89
90
91
92
93
94
95
96...

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3520kb

input:

300
1
1
2
2
1
3
2
3
3
4
5
3
4
5
7
6
7
7
8
8
7
8
9
6
9
10
11
12
11
11
12
11
13
12
12
12
13
14
13
13
14
15
16
11
17
18
18
19
6
18
19
20
18
21
1
21
12
11
22
20
2
22
19
20
20
21
22
22
23
9
24
22
18
23
24
24
24
25
26
20
25
26
27
27
28
27
27
28
17
29
19
30
17
29
29
30
30
31
32
33
31
33
32
33
33
33
34
33
3...

output:

4

result:

ok single line: '4'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

300
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

300

result:

ok single line: '300'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

300
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

output:

741

result:

ok single line: '741'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

300
1
1
1
2
3
1
3
3
4
2
5
3
3
2
3
4
3
5
2
6
7
5
4
5
3
5
4
8
9
4
5
3
6
8
9
1
7
6
7
10
2
7
10
3
9
4
3
4
4
10
5
4
11
6
1
8
9
5
9
6
10
10
11
10
3
7
12
8
10
13
11
6
11
11
13
11
12
13
7
14
8
6
8
9
11
7
13
12
14
10
12
10
9
15
5
13
13
13
3
8
14
13
9
15
11
6
15
10
6
16
9
10
11
17
14
15
7
12
7
1
17
14
15
17
9...

output:

5575

result:

ok single line: '5575'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

300
1
1
2
1
2
2
3
2
4
2
4
3
5
3
6
7
8
9
4
7
1
9
5
10
4
6
5
9
2
10
11
1
6
6
3
12
4
12
13
2
3
4
7
14
4
5
13
5
8
11
12
11
6
10
9
14
7
4
12
4
4
10
11
6
14
13
2
9
15
8
5
12
7
7
9
10
5
14
15
2
12
7
8
6
11
11
12
2
13
5
14
8
9
10
10
15
16
11
11
11
15
16
5
6
16
17
11
9
17
12
17
6
18
5
18
15
16
7
12
13
3
10
1...

output:

6095

result:

ok single line: '6095'

Subtask #3:

score: 60
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #21:

score: 60
Accepted
time: 47ms
memory: 16940kb

input:

1000000
1
1
1
1
1
1
1
2
3
3
1
3
1
3
3
3
2
3
4
4
2
1
4
4
1
5
6
5
3
2
3
2
4
7
7
2
4
3
7
5
6
2
5
8
9
10
7
10
10
4
10
6
5
10
7
3
4
10
11
12
4
3
1
10
8
1
3
5
10
5
11
7
11
1
8
11
2
11
9
1
9
1
9
2
11
8
6
7
12
2
8
10
10
8
2
3
2
6
4
8
5
8
12
13
2
6
14
6
15
5
2
10
7
16
5
17
15
14
1
4
3
11
11
12
17
7
8
17
8
1
...

output:

0

result:

ok single line: '0'

Test #22:

score: 0
Accepted
time: 39ms
memory: 15420kb

input:

1000000
1
2
3
3
4
5
2
4
1
4
4
3
6
3
6
2
5
4
6
2
7
1
8
5
4
1
7
2
5
7
8
2
2
9
4
3
9
1
9
4
10
6
4
11
7
10
1
5
5
12
4
12
4
2
6
12
12
9
5
5
3
8
4
10
8
2
3
11
8
11
6
2
10
11
1
2
9
7
11
7
4
11
2
1
1
8
5
11
5
6
2
4
1
4
2
6
9
13
3
10
13
12
14
10
2
6
4
8
5
10
9
3
12
13
10
2
10
7
3
11
9
9
5
2
8
2
1
8
2
4
7
11
...

output:

0

result:

ok single line: '0'

Test #23:

score: 0
Accepted
time: 41ms
memory: 15416kb

input:

1000000
1
2
2
2
2
3
2
3
1
3
4
5
1
1
1
3
6
7
1
2
7
7
8
6
1
8
8
2
3
2
6
9
8
2
4
4
6
7
9
3
3
2
7
10
7
5
7
6
7
4
9
5
8
9
7
9
7
6
1
6
6
2
11
9
11
7
5
5
12
7
2
10
7
10
13
1
13
3
11
10
13
9
12
6
5
5
3
8
9
3
9
5
5
8
7
1
2
5
7
3
7
6
9
1
4
7
8
11
8
11
3
9
3
6
4
8
9
11
10
1
11
11
7
4
13
7
4
9
8
7
3
12
8
8
6
2
...

output:

1837

result:

ok single line: '1837'

Test #24:

score: 0
Accepted
time: 52ms
memory: 15376kb

input:

1000000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...

output:

499999500001

result:

ok single line: '499999500001'

Test #25:

score: 0
Accepted
time: 46ms
memory: 16996kb

input:

1000000
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
10...

output:

1

result:

ok single line: '1'

Test #26:

score: 0
Accepted
time: 50ms
memory: 15652kb

input:

1000000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...

output:

1

result:

ok single line: '1'

Test #27:

score: 0
Accepted
time: 54ms
memory: 17000kb

input:

1000000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...

output:

1

result:

ok single line: '1'

Test #28:

score: 0
Accepted
time: 46ms
memory: 16568kb

input:

1000000
1
2
3
4
5
6
7
8
9
10
10
11
12
13
14
15
16
17
18
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
95
96
97
9...

output:

1

result:

ok single line: '1'

Test #29:

score: 0
Accepted
time: 38ms
memory: 16844kb

input:

1000000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

1000000

result:

ok single line: '1000000'

Test #30:

score: 0
Accepted
time: 43ms
memory: 16552kb

input:

1000000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

output:

182852191

result:

ok single line: '182852191'

Test #31:

score: 0
Accepted
time: 46ms
memory: 17044kb

input:

1000000
1
2
3
4
1
5
4
1
5
2
3
4
5
4
6
3
4
7
6
6
7
3
2
3
4
8
5
6
8
9
4
2
7
3
5
4
5
4
5
4
6
5
7
9
6
7
9
2
7
8
9
7
10
11
11
3
4
9
8
11
11
10
8
5
5
6
9
4
11
12
7
12
10
12
4
13
14
8
5
8
15
10
10
14
16
9
11
12
11
5
12
3
14
7
16
6
10
15
6
4
12
13
14
15
14
11
13
16
16
17
12
8
18
19
19
10
19
6
11
14
13
15
19...

output:

1316160898

result:

ok single line: '1316160898'

Test #32:

score: 0
Accepted
time: 45ms
memory: 15948kb

input:

1000000
1
1
1
2
1
3
3
3
4
4
3
2
4
5
6
6
3
4
7
7
7
3
8
9
1
9
2
10
4
11
5
6
5
7
11
11
8
3
5
9
6
7
8
11
12
8
1
2
2
6
3
4
5
8
9
10
7
12
13
8
9
13
9
4
10
5
13
1
11
6
7
2
12
12
13
11
10
13
14
11
3
5
12
8
12
10
4
15
13
6
11
5
16
7
6
7
14
9
15
16
5
12
13
15
8
17
17
18
16
9
8
19
6
13
7
9
14
6
10
20
10
7
11
7...

output:

1316585741

result:

ok single line: '1316585741'

Test #33:

score: 0
Accepted
time: 50ms
memory: 16740kb

input:

1000000
1
1
1
2
1
3
3
1
2
2
3
3
4
5
4
4
5
6
1
2
3
5
4
3
4
5
6
6
7
6
5
5
8
8
7
9
3
6
10
9
4
11
2
12
10
5
7
7
8
5
8
8
13
9
10
10
14
1
12
6
7
9
11
12
6
7
12
13
10
8
14
14
13
15
12
15
16
6
11
12
11
16
9
12
10
17
14
18
7
10
9
19
18
15
11
19
11
2
12
20
13
13
16
20
11
7
17
18
14
2
7
19
3
15
12
16
16
11
14
...

output:

1321696698

result:

ok single line: '1321696698'

Test #34:

score: 0
Accepted
time: 45ms
memory: 16420kb

input:

1000000
1
1
2
2
2
1
2
2
2
3
4
3
4
5
6
4
2
2
3
3
7
6
7
6
6
4
7
8
8
7
5
5
3
9
4
8
6
8
8
7
2
10
8
3
5
9
7
8
2
8
11
11
9
5
5
10
9
7
11
6
6
12
3
9
10
13
10
4
2
11
7
10
8
12
9
9
8
13
3
14
11
2
7
9
8
10
11
12
10
10
15
13
11
14
12
15
15
16
11
3
16
13
4
5
9
14
14
17
15
5
10
9
16
17
18
18
6
14
3
10
6
19
6
15
...

output:

1316963278

result:

ok single line: '1316963278'

Test #35:

score: 0
Accepted
time: 50ms
memory: 16788kb

input:

1000000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...

output:

374999750001

result:

ok single line: '374999750001'

Extra Test:

score: 0
Extra Test Passed