#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> p_sum(100005,0), w(100005,0);
const ll mod = 1e9+2022;
struct Node{
Node *l_child, *r_child;
int l,r; ll sum; bool lazy;
Node(){}
Node(int _l, int _r){
l = _l; r = _r; sum=0; lazy = false;
int m = (l+r)/2;
if(r-l > 1){
l_child = new Node(l,m);
r_child = new Node(m,r);
}
//cout << l << " " << r << "\n";
}
void push(){
if(!lazy) return;
if(r-l==1){
lazy = false;
sum = w[l] - sum;
}
else{
lazy = false;
l_child->flip(l,r);
r_child->flip(l,r);
}
}
void flip(int L, int R){
if(R <= l || L >= r) return; //not intersect
else if(r-l == 1){
sum = w[l] - sum;
}
else if(L <= l && r <= R){ //completely within
lazy = !lazy;
sum = (p_sum[r] - p_sum[l] - sum + 2*mod);
while(sum >= mod) sum -= mod;
}
else{
push();
l_child->flip(L,R); r_child->flip(L,R);
sum = ((l_child->sum) + (r_child->sum));
if(sum >= mod) sum -= mod;
}
}
ll query(){
push(); return sum;
}
};
ll exp(ll a, ll n){
if(n==0) return 1;
if(n==1) return a%mod;
ll x = exp(a, n/2);
if(n%2==0) return (x*x)%mod;
else return (((x*x)%mod)*a)%mod;
}
const ll p = 2;
const ll q = 223;
const ll r = 2242157;
const ll phi = (p-1)*(q-1)*(r-1);
struct mint{
int vp, vq; ll n;
mint(ll _n){
vp = 0; vq = 0;
n = _n;
while(n%p==0){vp++; n/=p;}
while(n%q==0){vq++; n/=q;}
n = n%mod;
}
mint(int _vp, int _vq, ll _n){
vp = _vp; vq = _vq; n = _n%mod;
}
friend mint operator *(mint a, mint b){
return mint(a.vp+b.vp, a.vq+b.vq, a.n*b.n);
}
mint inv(){
return mint(-vp, -vq, exp(n,phi-1));
}
friend mint operator /(mint a, mint b){
return a * b.inv();
}
ll to_int(){
assert(vp >= 0 && vq >= 0);
ll m=n;
m = (m*exp(p,vp)) % mod;
m = (m*exp(q,vq)) % mod;
return m;
}
};
int n,m;
Node tr(0,100005);
void init(int _n, int _m, std::vector<int> p, std::vector<int> a){
n = _n; m = _m;
//step 1: compute degree
vector<int> adj[n];
vector<int> d(n,0);
vector<mint> d_mod(n,1);
mint prod(1);
for(int i=1; i<n+m; ++i){
adj[p[i]].push_back(i);
d[p[i]]++;
}
for(int i=0; i<n; ++i){
d_mod[i] = mint(d[i]);
prod = prod * d_mod[i];
}
//step 2: dfs to find weight of each leaf
vector<mint> node_w(n+m, mint(1));
node_w[0] = prod;
vector<int> st(1,0);
while(!st.empty()){
int v = st[st.size()-1];
st.pop_back();
//cout << v << "\n";
for(int u : adj[v]){
node_w[u] = node_w[v] / d_mod[v];
if(u < n) st.push_back(u);
}
}
//step 3: build the tree
p_sum[0] = 0;
for(int i=0; i<m; ++i){
w[i] = node_w[i+n].to_int();
p_sum[i+1] = (p_sum[i] + w[i]);
if(p_sum[i+1] >= mod) p_sum[i+1] -= mod;
}
for(int i=0; i<m; ++i){
if(a[i] == 1) tr.flip(i,i+1);
}
}
int count_ways(int l, int r){
tr.flip(l-n,r-n+1);
return tr.query();
}
/*int main(){
for(int i=0; i<100; ++i){
w[i] = i;
p_sum[i+1] = p_sum[i] + w[i];
}
tr.flip(3,6);
cout << tr.query() << "\n";
tr.flip(5,10);
cout << tr.query() << "\n";
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11216 KB |
Output is correct |
2 |
Correct |
8 ms |
11216 KB |
Output is correct |
3 |
Correct |
9 ms |
11216 KB |
Output is correct |
4 |
Correct |
11 ms |
11280 KB |
Output is correct |
5 |
Correct |
9 ms |
11272 KB |
Output is correct |
6 |
Correct |
10 ms |
11292 KB |
Output is correct |
7 |
Correct |
9 ms |
11312 KB |
Output is correct |
8 |
Correct |
10 ms |
11304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
11276 KB |
Output is correct |
2 |
Correct |
9 ms |
11216 KB |
Output is correct |
3 |
Correct |
9 ms |
11328 KB |
Output is correct |
4 |
Correct |
9 ms |
11216 KB |
Output is correct |
5 |
Correct |
9 ms |
11304 KB |
Output is correct |
6 |
Correct |
9 ms |
11344 KB |
Output is correct |
7 |
Correct |
10 ms |
11344 KB |
Output is correct |
8 |
Correct |
9 ms |
11344 KB |
Output is correct |
9 |
Correct |
9 ms |
11344 KB |
Output is correct |
10 |
Correct |
10 ms |
11344 KB |
Output is correct |
11 |
Correct |
10 ms |
11344 KB |
Output is correct |
12 |
Correct |
10 ms |
11376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11216 KB |
Output is correct |
2 |
Correct |
8 ms |
11216 KB |
Output is correct |
3 |
Correct |
9 ms |
11216 KB |
Output is correct |
4 |
Correct |
11 ms |
11280 KB |
Output is correct |
5 |
Correct |
9 ms |
11272 KB |
Output is correct |
6 |
Correct |
10 ms |
11292 KB |
Output is correct |
7 |
Correct |
9 ms |
11312 KB |
Output is correct |
8 |
Correct |
10 ms |
11304 KB |
Output is correct |
9 |
Correct |
10 ms |
11276 KB |
Output is correct |
10 |
Correct |
9 ms |
11216 KB |
Output is correct |
11 |
Correct |
9 ms |
11328 KB |
Output is correct |
12 |
Correct |
9 ms |
11216 KB |
Output is correct |
13 |
Correct |
9 ms |
11304 KB |
Output is correct |
14 |
Correct |
9 ms |
11344 KB |
Output is correct |
15 |
Correct |
10 ms |
11344 KB |
Output is correct |
16 |
Correct |
9 ms |
11344 KB |
Output is correct |
17 |
Correct |
9 ms |
11344 KB |
Output is correct |
18 |
Correct |
10 ms |
11344 KB |
Output is correct |
19 |
Correct |
10 ms |
11344 KB |
Output is correct |
20 |
Correct |
10 ms |
11376 KB |
Output is correct |
21 |
Correct |
9 ms |
11344 KB |
Output is correct |
22 |
Correct |
9 ms |
11268 KB |
Output is correct |
23 |
Correct |
9 ms |
11344 KB |
Output is correct |
24 |
Correct |
9 ms |
11344 KB |
Output is correct |
25 |
Correct |
9 ms |
11344 KB |
Output is correct |
26 |
Correct |
10 ms |
11344 KB |
Output is correct |
27 |
Correct |
10 ms |
11344 KB |
Output is correct |
28 |
Correct |
10 ms |
11344 KB |
Output is correct |
29 |
Correct |
9 ms |
11232 KB |
Output is correct |
30 |
Correct |
9 ms |
11216 KB |
Output is correct |
31 |
Correct |
9 ms |
11372 KB |
Output is correct |
32 |
Correct |
9 ms |
11344 KB |
Output is correct |
33 |
Correct |
9 ms |
11252 KB |
Output is correct |
34 |
Correct |
9 ms |
11216 KB |
Output is correct |
35 |
Correct |
9 ms |
11216 KB |
Output is correct |
36 |
Correct |
10 ms |
11344 KB |
Output is correct |
37 |
Correct |
13 ms |
11344 KB |
Output is correct |
38 |
Correct |
9 ms |
11344 KB |
Output is correct |
39 |
Correct |
9 ms |
11268 KB |
Output is correct |
40 |
Correct |
12 ms |
11348 KB |
Output is correct |
41 |
Correct |
10 ms |
11216 KB |
Output is correct |
42 |
Correct |
9 ms |
11272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
653 ms |
15440 KB |
Output is correct |
2 |
Correct |
1002 ms |
19732 KB |
Output is correct |
3 |
Correct |
883 ms |
19668 KB |
Output is correct |
4 |
Correct |
992 ms |
19720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
653 ms |
15440 KB |
Output is correct |
2 |
Correct |
1002 ms |
19732 KB |
Output is correct |
3 |
Correct |
883 ms |
19668 KB |
Output is correct |
4 |
Correct |
992 ms |
19720 KB |
Output is correct |
5 |
Correct |
806 ms |
15496 KB |
Output is correct |
6 |
Correct |
1045 ms |
19704 KB |
Output is correct |
7 |
Correct |
939 ms |
19724 KB |
Output is correct |
8 |
Correct |
950 ms |
19736 KB |
Output is correct |
9 |
Correct |
484 ms |
11508 KB |
Output is correct |
10 |
Correct |
764 ms |
11728 KB |
Output is correct |
11 |
Correct |
838 ms |
11728 KB |
Output is correct |
12 |
Correct |
850 ms |
11728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
11276 KB |
Output is correct |
2 |
Correct |
9 ms |
11216 KB |
Output is correct |
3 |
Correct |
9 ms |
11328 KB |
Output is correct |
4 |
Correct |
9 ms |
11216 KB |
Output is correct |
5 |
Correct |
9 ms |
11304 KB |
Output is correct |
6 |
Correct |
9 ms |
11344 KB |
Output is correct |
7 |
Correct |
10 ms |
11344 KB |
Output is correct |
8 |
Correct |
9 ms |
11344 KB |
Output is correct |
9 |
Correct |
9 ms |
11344 KB |
Output is correct |
10 |
Correct |
10 ms |
11344 KB |
Output is correct |
11 |
Correct |
10 ms |
11344 KB |
Output is correct |
12 |
Correct |
10 ms |
11376 KB |
Output is correct |
13 |
Correct |
653 ms |
15440 KB |
Output is correct |
14 |
Correct |
1002 ms |
19732 KB |
Output is correct |
15 |
Correct |
883 ms |
19668 KB |
Output is correct |
16 |
Correct |
992 ms |
19720 KB |
Output is correct |
17 |
Correct |
806 ms |
15496 KB |
Output is correct |
18 |
Correct |
1045 ms |
19704 KB |
Output is correct |
19 |
Correct |
939 ms |
19724 KB |
Output is correct |
20 |
Correct |
950 ms |
19736 KB |
Output is correct |
21 |
Correct |
484 ms |
11508 KB |
Output is correct |
22 |
Correct |
764 ms |
11728 KB |
Output is correct |
23 |
Correct |
838 ms |
11728 KB |
Output is correct |
24 |
Correct |
850 ms |
11728 KB |
Output is correct |
25 |
Correct |
1057 ms |
23940 KB |
Output is correct |
26 |
Correct |
1124 ms |
24064 KB |
Output is correct |
27 |
Correct |
1059 ms |
24180 KB |
Output is correct |
28 |
Correct |
910 ms |
24176 KB |
Output is correct |
29 |
Correct |
1006 ms |
24296 KB |
Output is correct |
30 |
Correct |
913 ms |
24056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11216 KB |
Output is correct |
2 |
Correct |
8 ms |
11216 KB |
Output is correct |
3 |
Correct |
9 ms |
11216 KB |
Output is correct |
4 |
Correct |
11 ms |
11280 KB |
Output is correct |
5 |
Correct |
9 ms |
11272 KB |
Output is correct |
6 |
Correct |
10 ms |
11292 KB |
Output is correct |
7 |
Correct |
9 ms |
11312 KB |
Output is correct |
8 |
Correct |
10 ms |
11304 KB |
Output is correct |
9 |
Correct |
10 ms |
11276 KB |
Output is correct |
10 |
Correct |
9 ms |
11216 KB |
Output is correct |
11 |
Correct |
9 ms |
11328 KB |
Output is correct |
12 |
Correct |
9 ms |
11216 KB |
Output is correct |
13 |
Correct |
9 ms |
11304 KB |
Output is correct |
14 |
Correct |
9 ms |
11344 KB |
Output is correct |
15 |
Correct |
10 ms |
11344 KB |
Output is correct |
16 |
Correct |
9 ms |
11344 KB |
Output is correct |
17 |
Correct |
9 ms |
11344 KB |
Output is correct |
18 |
Correct |
10 ms |
11344 KB |
Output is correct |
19 |
Correct |
10 ms |
11344 KB |
Output is correct |
20 |
Correct |
10 ms |
11376 KB |
Output is correct |
21 |
Correct |
9 ms |
11344 KB |
Output is correct |
22 |
Correct |
9 ms |
11268 KB |
Output is correct |
23 |
Correct |
9 ms |
11344 KB |
Output is correct |
24 |
Correct |
9 ms |
11344 KB |
Output is correct |
25 |
Correct |
9 ms |
11344 KB |
Output is correct |
26 |
Correct |
10 ms |
11344 KB |
Output is correct |
27 |
Correct |
10 ms |
11344 KB |
Output is correct |
28 |
Correct |
10 ms |
11344 KB |
Output is correct |
29 |
Correct |
9 ms |
11232 KB |
Output is correct |
30 |
Correct |
9 ms |
11216 KB |
Output is correct |
31 |
Correct |
9 ms |
11372 KB |
Output is correct |
32 |
Correct |
9 ms |
11344 KB |
Output is correct |
33 |
Correct |
9 ms |
11252 KB |
Output is correct |
34 |
Correct |
9 ms |
11216 KB |
Output is correct |
35 |
Correct |
9 ms |
11216 KB |
Output is correct |
36 |
Correct |
10 ms |
11344 KB |
Output is correct |
37 |
Correct |
13 ms |
11344 KB |
Output is correct |
38 |
Correct |
9 ms |
11344 KB |
Output is correct |
39 |
Correct |
9 ms |
11268 KB |
Output is correct |
40 |
Correct |
12 ms |
11348 KB |
Output is correct |
41 |
Correct |
10 ms |
11216 KB |
Output is correct |
42 |
Correct |
9 ms |
11272 KB |
Output is correct |
43 |
Correct |
668 ms |
11628 KB |
Output is correct |
44 |
Correct |
876 ms |
11740 KB |
Output is correct |
45 |
Correct |
710 ms |
11672 KB |
Output is correct |
46 |
Correct |
872 ms |
11820 KB |
Output is correct |
47 |
Correct |
906 ms |
11856 KB |
Output is correct |
48 |
Correct |
730 ms |
11856 KB |
Output is correct |
49 |
Correct |
748 ms |
11856 KB |
Output is correct |
50 |
Correct |
876 ms |
11796 KB |
Output is correct |
51 |
Correct |
757 ms |
11472 KB |
Output is correct |
52 |
Correct |
565 ms |
11472 KB |
Output is correct |
53 |
Correct |
615 ms |
11748 KB |
Output is correct |
54 |
Correct |
917 ms |
11856 KB |
Output is correct |
55 |
Correct |
846 ms |
11660 KB |
Output is correct |
56 |
Correct |
933 ms |
11584 KB |
Output is correct |
57 |
Correct |
803 ms |
11436 KB |
Output is correct |
58 |
Correct |
694 ms |
11856 KB |
Output is correct |
59 |
Correct |
911 ms |
11856 KB |
Output is correct |
60 |
Correct |
892 ms |
11856 KB |
Output is correct |
61 |
Correct |
837 ms |
11736 KB |
Output is correct |
62 |
Correct |
885 ms |
11592 KB |
Output is correct |
63 |
Correct |
773 ms |
11516 KB |
Output is correct |
64 |
Correct |
876 ms |
11464 KB |
Output is correct |
65 |
Correct |
460 ms |
11516 KB |
Output is correct |
66 |
Correct |
882 ms |
11728 KB |
Output is correct |
67 |
Correct |
851 ms |
11728 KB |
Output is correct |
68 |
Correct |
691 ms |
11728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11216 KB |
Output is correct |
2 |
Correct |
8 ms |
11216 KB |
Output is correct |
3 |
Correct |
9 ms |
11216 KB |
Output is correct |
4 |
Correct |
11 ms |
11280 KB |
Output is correct |
5 |
Correct |
9 ms |
11272 KB |
Output is correct |
6 |
Correct |
10 ms |
11292 KB |
Output is correct |
7 |
Correct |
9 ms |
11312 KB |
Output is correct |
8 |
Correct |
10 ms |
11304 KB |
Output is correct |
9 |
Correct |
10 ms |
11276 KB |
Output is correct |
10 |
Correct |
9 ms |
11216 KB |
Output is correct |
11 |
Correct |
9 ms |
11328 KB |
Output is correct |
12 |
Correct |
9 ms |
11216 KB |
Output is correct |
13 |
Correct |
9 ms |
11304 KB |
Output is correct |
14 |
Correct |
9 ms |
11344 KB |
Output is correct |
15 |
Correct |
10 ms |
11344 KB |
Output is correct |
16 |
Correct |
9 ms |
11344 KB |
Output is correct |
17 |
Correct |
9 ms |
11344 KB |
Output is correct |
18 |
Correct |
10 ms |
11344 KB |
Output is correct |
19 |
Correct |
10 ms |
11344 KB |
Output is correct |
20 |
Correct |
10 ms |
11376 KB |
Output is correct |
21 |
Correct |
9 ms |
11344 KB |
Output is correct |
22 |
Correct |
9 ms |
11268 KB |
Output is correct |
23 |
Correct |
9 ms |
11344 KB |
Output is correct |
24 |
Correct |
9 ms |
11344 KB |
Output is correct |
25 |
Correct |
9 ms |
11344 KB |
Output is correct |
26 |
Correct |
10 ms |
11344 KB |
Output is correct |
27 |
Correct |
10 ms |
11344 KB |
Output is correct |
28 |
Correct |
10 ms |
11344 KB |
Output is correct |
29 |
Correct |
9 ms |
11232 KB |
Output is correct |
30 |
Correct |
9 ms |
11216 KB |
Output is correct |
31 |
Correct |
9 ms |
11372 KB |
Output is correct |
32 |
Correct |
9 ms |
11344 KB |
Output is correct |
33 |
Correct |
9 ms |
11252 KB |
Output is correct |
34 |
Correct |
9 ms |
11216 KB |
Output is correct |
35 |
Correct |
9 ms |
11216 KB |
Output is correct |
36 |
Correct |
10 ms |
11344 KB |
Output is correct |
37 |
Correct |
13 ms |
11344 KB |
Output is correct |
38 |
Correct |
9 ms |
11344 KB |
Output is correct |
39 |
Correct |
9 ms |
11268 KB |
Output is correct |
40 |
Correct |
12 ms |
11348 KB |
Output is correct |
41 |
Correct |
10 ms |
11216 KB |
Output is correct |
42 |
Correct |
9 ms |
11272 KB |
Output is correct |
43 |
Correct |
653 ms |
15440 KB |
Output is correct |
44 |
Correct |
1002 ms |
19732 KB |
Output is correct |
45 |
Correct |
883 ms |
19668 KB |
Output is correct |
46 |
Correct |
992 ms |
19720 KB |
Output is correct |
47 |
Correct |
806 ms |
15496 KB |
Output is correct |
48 |
Correct |
1045 ms |
19704 KB |
Output is correct |
49 |
Correct |
939 ms |
19724 KB |
Output is correct |
50 |
Correct |
950 ms |
19736 KB |
Output is correct |
51 |
Correct |
484 ms |
11508 KB |
Output is correct |
52 |
Correct |
764 ms |
11728 KB |
Output is correct |
53 |
Correct |
838 ms |
11728 KB |
Output is correct |
54 |
Correct |
850 ms |
11728 KB |
Output is correct |
55 |
Correct |
1057 ms |
23940 KB |
Output is correct |
56 |
Correct |
1124 ms |
24064 KB |
Output is correct |
57 |
Correct |
1059 ms |
24180 KB |
Output is correct |
58 |
Correct |
910 ms |
24176 KB |
Output is correct |
59 |
Correct |
1006 ms |
24296 KB |
Output is correct |
60 |
Correct |
913 ms |
24056 KB |
Output is correct |
61 |
Correct |
668 ms |
11628 KB |
Output is correct |
62 |
Correct |
876 ms |
11740 KB |
Output is correct |
63 |
Correct |
710 ms |
11672 KB |
Output is correct |
64 |
Correct |
872 ms |
11820 KB |
Output is correct |
65 |
Correct |
906 ms |
11856 KB |
Output is correct |
66 |
Correct |
730 ms |
11856 KB |
Output is correct |
67 |
Correct |
748 ms |
11856 KB |
Output is correct |
68 |
Correct |
876 ms |
11796 KB |
Output is correct |
69 |
Correct |
757 ms |
11472 KB |
Output is correct |
70 |
Correct |
565 ms |
11472 KB |
Output is correct |
71 |
Correct |
615 ms |
11748 KB |
Output is correct |
72 |
Correct |
917 ms |
11856 KB |
Output is correct |
73 |
Correct |
846 ms |
11660 KB |
Output is correct |
74 |
Correct |
933 ms |
11584 KB |
Output is correct |
75 |
Correct |
803 ms |
11436 KB |
Output is correct |
76 |
Correct |
694 ms |
11856 KB |
Output is correct |
77 |
Correct |
911 ms |
11856 KB |
Output is correct |
78 |
Correct |
892 ms |
11856 KB |
Output is correct |
79 |
Correct |
837 ms |
11736 KB |
Output is correct |
80 |
Correct |
885 ms |
11592 KB |
Output is correct |
81 |
Correct |
773 ms |
11516 KB |
Output is correct |
82 |
Correct |
876 ms |
11464 KB |
Output is correct |
83 |
Correct |
460 ms |
11516 KB |
Output is correct |
84 |
Correct |
882 ms |
11728 KB |
Output is correct |
85 |
Correct |
851 ms |
11728 KB |
Output is correct |
86 |
Correct |
691 ms |
11728 KB |
Output is correct |
87 |
Correct |
8 ms |
11216 KB |
Output is correct |
88 |
Correct |
589 ms |
23012 KB |
Output is correct |
89 |
Correct |
926 ms |
20484 KB |
Output is correct |
90 |
Correct |
944 ms |
19652 KB |
Output is correct |
91 |
Correct |
828 ms |
24392 KB |
Output is correct |
92 |
Correct |
1069 ms |
24288 KB |
Output is correct |
93 |
Correct |
1095 ms |
24216 KB |
Output is correct |
94 |
Correct |
1110 ms |
24224 KB |
Output is correct |
95 |
Correct |
912 ms |
24264 KB |
Output is correct |
96 |
Correct |
966 ms |
14904 KB |
Output is correct |
97 |
Correct |
1082 ms |
14784 KB |
Output is correct |
98 |
Correct |
904 ms |
20916 KB |
Output is correct |
99 |
Correct |
1041 ms |
24056 KB |
Output is correct |
100 |
Correct |
930 ms |
19196 KB |
Output is correct |
101 |
Correct |
972 ms |
17264 KB |
Output is correct |
102 |
Correct |
979 ms |
14792 KB |
Output is correct |
103 |
Correct |
973 ms |
24136 KB |
Output is correct |
104 |
Correct |
1024 ms |
24584 KB |
Output is correct |
105 |
Correct |
894 ms |
24776 KB |
Output is correct |
106 |
Correct |
1108 ms |
20264 KB |
Output is correct |
107 |
Correct |
909 ms |
17284 KB |
Output is correct |
108 |
Correct |
1038 ms |
16712 KB |
Output is correct |
109 |
Correct |
1040 ms |
14976 KB |
Output is correct |