@@ -23,6 +23,7 @@ using P = pair<int, int>;
23
23
const int N = 1e5 + 1 ;
24
24
const int S = 300 ;
25
25
26
+ // BeginCodeSnip{BIT (from PURS module)}
26
27
template <class T > class BIT {
27
28
private :
28
29
int size ;
@@ -50,6 +51,7 @@ template <class T> class BIT {
50
51
return total;
51
52
}
52
53
};
54
+ // EndCodeSnip
53
55
54
56
struct Query {
55
57
int l, r, i;
@@ -80,7 +82,6 @@ int main() {
80
82
});
81
83
82
84
ll res = 0 ;
83
-
84
85
BIT<int> bit(n );
85
86
// left -> whether we're modifying on the left
86
87
auto edit = [& ](int id , int x , bool left ) {
@@ -92,13 +93,14 @@ int main() {
92
93
93
94
vector<ll> ans(k );
94
95
for (int i = 0 ; i < q.size(); i++) {
95
- if (i ) ans [q [i ].i ] = res ;
96
- if (i + 1 >= q .size ()) break ;
96
+ if (i ) { ans [q [i ].i ] = res ; }
97
+ if (i + 1 >= q .size ()) { break ; }
97
98
while (q [i ].l > q [i + 1 ].l ) { edit (id (-- q [i ].l ), 1 , true ); }
98
99
while (q [i ].r < q [i + 1 ].r ) { edit (id (q [i ].r ++ ), 1 , false ); }
99
100
while (q [i ].l < q [i + 1 ].l ) { edit (id (q [i ].l ++ ), - 1 , true ); }
100
101
while (q [i ].r > q [i + 1 ].r ) { edit (id (-- q [i ].r ), - 1 , false ); }
101
102
}
103
+
102
104
for (int i = 0 ; i < k ; i ++) { cout << ans [i ] << ' \n ' ; }
103
105
}
104
106
` ` `
0 commit comments