이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "circuit.h"
const ll MOD = 1000002022;
VL contr;
struct SEGTREE {
int n;
VL tree1, tree2;
VI lazy;
SEGTREE(){}
SEGTREE(VI val) {
n = 1;
while (n < val.size()) n *= 2;
tree1 = tree2 = VL(2*n);
lazy = VI(2*n);
rep(i, val.size()) {
if (val[i]) tree1[i + n-1] = contr[i];
else tree2[i + n-1] = contr[i];
}
build(0, 0, n-1);
}
void build(int N, int L, int R) {
if (L == R) return;
int M = (L + R) / 2;
build(2*N+1, L, M);
build(2*N+2, M+1, R);
tree1[N] = (tree1[2*N+1] + tree1[2*N+2]) % MOD;
tree2[N] = (tree2[2*N+1] + tree2[2*N+2]) % MOD;
}
void push(int N) {
if (lazy[N]%2) swap(tree1[N], tree2[N]);
if (2*N+2 < 2*n) {
lazy[2*N+1] += lazy[N];
lazy[2*N+2] += lazy[N];
}
lazy[N] = 0;
}
void upd(int N, int L, int R, int l, int r) {
push(N);
if (R < l || L > r) return;
if (l <= L && R <= r) {
lazy[N]++;
push(N);
return;
}
int M = (L + R) / 2;
upd(2*N+1, L, M, l, r);
upd(2*N+2, M+1, R, l, r);
tree1[N] = (tree1[2*N+1] + tree1[2*N+2]) % MOD;
tree2[N] = (tree2[2*N+1] + tree2[2*N+2]) % MOD;
}
void upd(int l, int r) {
upd(0, 0, n-1, l, r);
}
ll get() {
return tree1[0];
}
} seg;
int n;
VVI gp;
VL sub;
ll dfs1(int u = 0) {
sub[u] = max((ll)gp[u].size(), 1ll);
for (int v : gp[u]) sub[u] = sub[u] * dfs1(v) % MOD;
return sub[u];
}
void dfs2(int u = 0, ll prod = 1) {
contr[u] = prod;
VL a;
a.pb(1);
for (int v : gp[u]) a.pb(sub[v]);
a.pb(1);
int c = a.size();
VL pref, suff;
pref = suff = a;
replr(i, 1, c-1) pref[i] = pref[i-1] * pref[i] % MOD;
reprl(i, c-2, 0) suff[i] = suff[i+1] * suff[i] % MOD;
int i = 1;
for (int v : gp[u]) dfs2(v, prod*pref[i-1]%MOD*suff[i+1]%MOD), i++;
}
void init(int N, int M, VI par, VI A) {
n = N + M;
gp = VVI(n);
rep(u, n) if (u) gp[par[u]].pb(u);
VI val = VI(n);
rep(u, M) val[u+N] = A[u];
contr = VL(n);
sub = VL(n);
dfs1();
dfs2();
seg = SEGTREE(val);
}
int count_ways(int L, int R) {
seg.upd(L, R);
return seg.get();
}
컴파일 시 표준 에러 (stderr) 메시지
circuit.cpp: In constructor 'SEGTREE::SEGTREE(VI)':
circuit.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | while (n < val.size()) n *= 2;
| ~~^~~~~~~~~~~~
# | 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... |