1
+ package IndexedTree .P5676 ;
2
+
3
+ import java .io .*;
4
+ import java .util .*;
5
+
6
+ public class Main {
7
+
8
+ static int N , K ;
9
+ static int [] nums ;
10
+ final static char CH_CMD = 'C' , MUL_CMD = 'P' ;
11
+
12
+ public static void main (String [] args ) throws Exception {
13
+ System .setIn (new FileInputStream ("src/IndexedTree/P5676/input.txt" ));
14
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
15
+
16
+ String line ;
17
+ while ((line = br .readLine ()) != null ) {
18
+ StringTokenizer st = new StringTokenizer (line );
19
+ N = stoi (st .nextToken ());
20
+ K = stoi (st .nextToken ());
21
+
22
+ st = new StringTokenizer (br .readLine ());
23
+ nums = new int [N ];
24
+ for (int i = 0 ; i < N ; i ++) nums [i ] = stoi (st .nextToken ());
25
+
26
+ SegmentTree tree = new SegmentTree (N , nums );
27
+
28
+ StringBuilder sb = new StringBuilder ();
29
+ while (K -- > 0 ) {
30
+ st = new StringTokenizer (br .readLine ());
31
+ char command = st .nextToken ().charAt (0 );
32
+ int from = stoi (st .nextToken ()), to = stoi (st .nextToken ());
33
+
34
+ if (command == CH_CMD ) tree .changeValue (0 , 0 , N -1 , from -1 , to );
35
+ else if (command == MUL_CMD ) {
36
+ int result = tree .multiple (0 , 0 , N -1 , from -1 , to -1 );
37
+ if (result == 0 ) sb .append (0 );
38
+ else sb .append (result > 0 ? '+' : '-' );
39
+ }
40
+ }
41
+ System .out .println (sb .toString ());
42
+ }
43
+
44
+ br .close ();
45
+ }
46
+
47
+ static int stoi (String s ) { return Integer .parseInt (s ); }
48
+ }
49
+
50
+ class SegmentTree {
51
+ int [] tree ;
52
+ int [] arr ;
53
+
54
+ public SegmentTree (int N , int [] arr ) {
55
+ this .tree = new int [(int ) Math .pow (2 , (Math .ceil (Math .log (N ) / Math .log (2 )) + 1 ))];
56
+ this .arr = arr ;
57
+ makeTree (0 , 0 , N -1 );
58
+ }
59
+
60
+ private int setValue (int value ) {
61
+ return Integer .compare (value , 0 );
62
+ }
63
+
64
+ void makeTree (int idx , int start , int end ) {
65
+ if (start == end ) {
66
+ tree [idx ] = setValue (arr [start ]);
67
+ return ;
68
+ }
69
+ makeTree (idx *2 +1 , start , (start +end )/2 );
70
+ makeTree (idx *2 +2 , (start +end )/2 +1 , end );
71
+ tree [idx ] = tree [idx *2 +1 ] * tree [idx *2 +2 ];
72
+ }
73
+
74
+ void changeValue (int idx , int start , int end , int target , int value ) {
75
+ if (target < start || target > end ) return ;
76
+ if (start == end ) {
77
+ tree [idx ] = setValue (value );
78
+ return ;
79
+ }
80
+ changeValue (idx *2 +1 , start , (start +end )/2 , target , value );
81
+ changeValue (idx *2 +2 , (start +end )/2 +1 , end , target , value );
82
+ tree [idx ] = tree [idx *2 +1 ] * tree [idx *2 +2 ];
83
+ }
84
+
85
+ int multiple (int idx , int start , int end , int left , int right ) {
86
+ if (end < left || start > right ) return 1 ;
87
+ if (left <= start && end <= right ) return tree [idx ];
88
+ return multiple (idx *2 +1 , start , (start +end )/2 , left , right )
89
+ * multiple (idx *2 +2 , (start +end )/2 +1 , end , left , right );
90
+ }
91
+ }
0 commit comments