이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
#define MAX 200000
#define mod 1000002022
struct x {
lli unos;
lli ceros;
lli lazy;
};
x stree[MAX+2];
lli offset;
void push(lli pos){
if (!stree[pos].lazy) return;
swap(stree[pos].ceros, stree[pos].unos);
if (pos < offset) {
stree[pos*2].lazy ^= 1;
stree[(pos*2)+1].lazy ^= 1;
}
stree[pos].lazy = 0;
return;
}
x solve(x a, x b) {
x res;
res.ceros = a.ceros*b.ceros*2;
res.unos = a.unos*b.unos*2;
lli y = a.ceros*b.unos + b.ceros*a.unos;
res.ceros += y;
res.unos += y;
res.ceros %= mod;
res.unos %= mod;
return res;
}
void update(lli pos, lli ini, lli fin, lli l, lli r) {
push(pos);
if(ini > r || fin < l) return;
if (l <= ini && fin <= r) {
stree[pos].lazy = 1;
push(pos);
return;
}
lli mitad = (ini+fin)/2;
update(pos*2,ini,mitad,l,r);
update(pos*2+1,mitad+1,fin,l,r);
stree[pos] = solve(stree[pos*2], stree[pos*2+1]);
return;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
offset = 1;
while (offset < M) offset *= 2;
rep(i,offset,offset+M-1) {
if (A[i-offset] == 1) stree[i] = {1,0};
else stree[i] = {0,1};
}
repa(pos,offset-1,1) stree[pos] = solve(stree[pos*2], stree[pos*2+1]);
}
int count_ways(int L, int R) {
L -= (offset - 2);
R -= (offset - 2);
update(1,1,offset,L,R);
return stree[1].unos;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |