File tree Expand file tree Collapse file tree 2 files changed +97
-0
lines changed Expand file tree Collapse file tree 2 files changed +97
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "bytes"
5+ . "fmt"
6+ "io"
7+ )
8+
9+ // https://github.com/EndlessCheng
10+ func cf2053B (in io.Reader , out io.Writer ) {
11+ var T , n int
12+ for Fscan (in , & T ); T > 0 ; T -- {
13+ Fscan (in , & n )
14+ type pair struct { l , r int }
15+ a := make ([]pair , n )
16+ cnt := make ([]int , n * 2 + 1 )
17+ for i := range a {
18+ Fscan (in , & a [i ].l , & a [i ].r )
19+ if a [i ].l == a [i ].r {
20+ cnt [a [i ].l ]++
21+ }
22+ }
23+
24+ // 优化前 https://codeforces.com/problemset/submission/2053/350549792
25+ s := make ([]int , n * 2 + 1 )
26+ for i := 1 ; i <= n * 2 ; i ++ {
27+ s [i ] = s [i - 1 ]
28+ if cnt [i ] == 0 {
29+ s [i ]--
30+ }
31+ }
32+
33+ ans := bytes .Repeat ([]byte {'0' }, n )
34+ for i , p := range a {
35+ if p .l < p .r {
36+ if s [p .r ] < s [p .l - 1 ] {
37+ ans [i ] = '1'
38+ }
39+ } else if cnt [p .l ] == 1 {
40+ ans [i ] = '1'
41+ }
42+ }
43+ Fprintf (out , "%s\n " , ans )
44+ }
45+ }
46+
47+ //func main() { cf2053B(bufio.NewReader(os.Stdin), os.Stdout) }
Original file line number Diff line number Diff line change 1+ // Generated by copypasta/template/generator_test.go
2+ package main
3+
4+ import (
5+ "github.com/EndlessCheng/codeforces-go/main/testutil"
6+ "testing"
7+ )
8+
9+ // https://codeforces.com/problemset/problem/2053/B 1200
10+ // https://codeforces.com/problemset/status/2053/problem/B?friends=on
11+ func Test_cf2053B (t * testing.T ) {
12+ testCases := [][2 ]string {
13+ {
14+ `5
15+ 2
16+ 1 1
17+ 1 1
18+ 4
19+ 1 3
20+ 1 3
21+ 1 3
22+ 1 3
23+ 6
24+ 3 6
25+ 2 2
26+ 1 2
27+ 1 1
28+ 3 4
29+ 2 2
30+ 7
31+ 3 4
32+ 4 4
33+ 4 4
34+ 1 3
35+ 2 5
36+ 1 4
37+ 2 2
38+ 3
39+ 4 5
40+ 4 4
41+ 5 5` ,
42+ `00
43+ 1111
44+ 100110
45+ 1001111
46+ 011` ,
47+ },
48+ }
49+ testutil .AssertEqualStringCase (t , testCases , 0 , cf2053B )
50+ }
You can’t perform that action at this time.
0 commit comments