結果
問題 | No.1996 <>< |
ユーザー | n_get |
提出日時 | 2022-07-01 23:08:55 |
言語 | Scheme (Gauche-0.9.14) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,236 bytes |
コンパイル時間 | 71 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 34,816 KB |
最終ジャッジ日時 | 2024-05-04 17:37:00 |
合計ジャッジ時間 | 8,530 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 82 ms
28,672 KB |
testcase_01 | AC | 79 ms
23,296 KB |
testcase_02 | AC | 79 ms
23,296 KB |
testcase_03 | AC | 82 ms
23,296 KB |
testcase_04 | AC | 82 ms
23,296 KB |
testcase_05 | AC | 84 ms
23,296 KB |
testcase_06 | AC | 82 ms
23,296 KB |
testcase_07 | AC | 80 ms
23,296 KB |
testcase_08 | AC | 87 ms
23,168 KB |
testcase_09 | AC | 85 ms
23,296 KB |
testcase_10 | AC | 89 ms
23,168 KB |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
(use util.queue)(use util.match)(use gauche.collection)(use gauche.sequence) (define-syntax def-syntax (syntax-rules()((_ v e ...)(define-syntax v (syntax-rules e ...))))) (define-syntax def-const define-constant)(define-syntax def define)(define-syntax def-inline define-inline) (def-syntax def-names ()((_[x y]...)(begin(define-constant x y)...))) (def-names [// quotient][% modulo][v-make make-vector][v-ref vector-ref][v-set! vector-set!][ht-make make-hash-table][ht-ref hash-table-get][ht-set! hash-table-put!][ht-keys hash-table-keys][ht-values hash-table-values][q-make make-queue][make-q make-queue][enq! enqueue!][deq! dequeue!][q-empty? queue-empty?]) (def-syntax input (: list vec cons str) ((_ : cons e ...)(cons(input : e ...)(input : e ...)))((_ : list str)(input : string->list str)) ((_ : vec str)(input : string->vector str))((_ : vec n e ...)(vector-tabulate n(^_(input : e ...)))) ((_ : list n e ...)(let l([k n])(if(zero? k)'()(cons(input : e ...)(l(- k 1))))))((_ :)(read))((_ : : e)e) ((_ : str)(let1 s(read-line)(if(string=? s "")(read-line)s)))((_[[v]: e ...])(def v(input : e ...))) ((_[[v w ...]: e ...])(begin(def v(input : e ...))(input[[w ...]: e ...]))) ((_[v : e ...])(def v(input : e ...)))((_ : op e ...)(op(input : e ...))) ((_(e ...))(e ...))((_ v)(def v(read)))((_ e ...)(begin(input e)...))) (define-constant *MOD* 1000000007) ;;(define-constant *MOD* 998244353) (def-syntax add-mod! ()((_ v x)(let1 y(+ v x)(set! v(if(< y *MOD*)y(- y *MOD*)))))) (def-inline(v-add-mod! v i x)(let1 y(+(v-ref v i)x)(v-set! v i(if(< y *MOD*)y(- y *MOD*))))) (def-syntax max! ()((_ v x)(set! v (max x v)))) (def-syntax min! ()((_ v x)(set! v (min x v)))) (def-inline(v-add! v i x)(v-set! v i(+ x(v-ref v i)))) (def-inline(ht-add! ht i x)(ht-set! ht i(+ x(ht-ref ht i 0)))) (def-inline(ht-cons! ht i x)(ht-set! ht i(cons x(ht-ref ht i '())))) (def-syntax return () ((_ e ...) (begin (print e ...) (exit)))) ;; 以下スニペットのコピペ ;; fenwick-tree ;; fw := (size . vector) (use scheme.bitwise) (define (make-fenwick-tree n) (cons n (make-vector n 0))) (define-constant %fenwick-tree-N car) (define-constant %fenwick-tree-data cdr) (define (fenwick-tree-add! fw p x) ;; fw[p] += x (let [[data (%fenwick-tree-data fw)] [n (%fenwick-tree-N fw)]] (let loop[[p (+ p 1)]] (when (<= p n) (vector-set! data (- p 1) (modulo (+ x (vector-ref data (- p 1))) *MOD*)) (loop (+ p (bitwise-and p (- p)))))))) (define (fenwick-tree-sum fw l r) ;; sum fw[i] , i <- [l r) (- (%fenwick-tree-sum (%fenwick-tree-data fw) r) (%fenwick-tree-sum (%fenwick-tree-data fw) l))) (define (%fenwick-tree-sum data r) (let loop[[r r] [s 0]] (cond [(zero? r) s] [else (loop (- r (bitwise-and r (- r))) (modulo (+ s (vector-ref data (- r 1))) *MOD*))]))) ;; (v1 ... vi ...vm) → (a1 ... ai ...am) 但しviはv中でai番目に小さい(0番始まり) ;; index->Nth : i->aiのvector ;; Nth->origin : ai->viのvector ;; origin->Nth : vi->aiのhash-table ;; N : aiの種類数 (use gauche.sequence) (define (zaatsu ls) (let* [[len-ls (length ls)] [gls (group-sequence (sort (map cons ls (iota len-ls))) :key car)] [N (length gls)] [origin->Nth (make-hash-table)] [index->Nth (make-vector len-ls)] [Nth->origin (make-vector N)]] (for-each-with-index (^(ai ls) (dolist [p ls] ;; (vi . i) (vector-set! index->Nth (cdr p) ai) (vector-set! Nth->origin ai (car p)) (hash-table-put! origin->Nth (car p) ai))) gls) (values index->Nth Nth->origin origin->Nth N))) ;; 以下が本体 (input N K [A : vec N] [S : (cut map (^c (char=? #\< c)) <>) vec str]) (define-values [index->Nth Nth->origin origin->Nth M] (zaatsu (vector->list A))) (def AA index->Nth) (def v (make-vector N 1)) (dolist [s S] (let [[vv (make-vector N)] [fw (make-fenwick-tree (+ M 1))]] (dotimes [i N] (v-set! vv i (if s (fenwick-tree-sum fw 0 (v-ref AA i)) (fenwick-tree-sum fw (+ (v-ref AA i) 1) M))) (fenwick-tree-add! fw (v-ref AA i) (v-ref v i))) (set! v vv))) (print (fold (^(x s) (modulo (+ x s) *MOD*)) 0 v))