File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ // https://atcoder.jp/contests/abc122/tasks/abc122_c
2
+ //
3
+ // 以下のクレートを使用。
4
+ //
5
+ // - `itertools-num`
6
+ // - `proconio`
7
+
8
+ use itertools_num:: ItertoolsNum as _;
9
+ use proconio:: marker:: { Bytes , Usize1 } ;
10
+ use proconio:: { fastout, input} ;
11
+
12
+ use std:: iter;
13
+
14
+ // `#[proconio::fastout]`で`println!`を置き換える。
15
+ //
16
+ // https://docs.rs/proconio-derive/0.1/proconio_derive/attr.fastout.html
17
+ #[ fastout]
18
+ fn main ( ) {
19
+ // `proconio::input!`では使わない値を`_`とすることができる。
20
+ //
21
+ // https://docs.rs/proconio/0.3.6/proconio/macro.input.html
22
+ input ! {
23
+ _: usize ,
24
+ q: usize ,
25
+ s: Bytes ,
26
+ lrs: [ ( Usize1 , Usize1 ) ; q] ,
27
+ }
28
+
29
+ // `<_ as itertools_num::ItertoolsNum>::cumsum`で作られた一次元累積和のイテレータを、先頭に`0`を挿入した上で`Vec<_>`にする。
30
+ //
31
+ // https://docs.rs/itertools-num/0.1/itertools_num/trait.ItertoolsNum.html#method.cumsum
32
+ let cumsum = iter:: once ( 0 )
33
+ . chain ( s. windows ( 2 ) . map ( |w| ( w == b"AC" ) . into ( ) ) )
34
+ . cumsum ( )
35
+ . collect :: < Vec < u32 > > ( ) ;
36
+
37
+ for ( l, r) in lrs {
38
+ println ! ( "{}" , cumsum[ r] - cumsum[ l] ) ;
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -100,6 +100,13 @@ url = "https://atcoder.jp/contests/abc121/tasks/abc121_b"
100
100
matching = " Words"
101
101
meta = { using = [" whiteread" ] }
102
102
103
+ [examples .abc122-c ]
104
+ type = " Normal"
105
+ name = " ABC122: C - GeT AC"
106
+ url = " https://atcoder.jp/contests/abc122/tasks/abc122_c"
107
+ matching = " Words"
108
+ meta = { using = [" itertools-num" , " proconio" ] }
109
+
103
110
[examples .abc129-f ]
104
111
type = " Normal"
105
112
name = " ABC129: F - Takahashi's Basics in Education and Learning"
You can’t perform that action at this time.
0 commit comments