# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
836194 | SamAnd | 디지털 회로 (IOI22_circuit) | C++17 | 3087 ms | 7204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 200005, M = 1000002022;
int n, m;
vector<int> g[N];
int s[N];
int a[N];
void dfs0(int x)
{
a[x] = 1;
if (g[x].empty())
return;
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
dfs0(h);
a[x] = (a[x] * 1LL * a[h]) % M;
}
a[x] = (a[x] * 1LL * sz(g[x])) % M;
}
int u[N];
void dfs1(int x, int aa)
{
if (g[x].empty())
{
u[x - n] = aa;
return;
}
vector<int> p;
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
if (p.empty())
p.push_back(a[h]);
else
p.push_back((p.back() * 1LL * a[h]) % M);
}
vector<int> s;
for (int i = sz(g[x]) - 1; i >= 0; --i)
{
int h = g[x][i];
if (s.empty())
s.push_back(a[h]);
else
s.push_back((s.back() * 1LL * a[h]) % M);
}
reverse(all(s));
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
int yaa = aa;
if (i)
yaa = (yaa * 1LL * p[i - 1]) % M;
if (i + 1 < sz(g[x]))
yaa = (yaa * 1LL * s[i + 1]) % M;
dfs1(h, yaa);
}
}
void init(int NN, int MM, std::vector<int> P, std::vector<int> A)
{
n = NN;
m = MM;
for (int i = 1; i < n + m; ++i)
g[P[i]].push_back(i);
for (int i = 0; i < m; ++i)
s[i] = A[i];
dfs0(0);
dfs1(0, 1);
}
int count_ways(int L, int R)
{
L -= n;
R -= n;
for (int i = L; i <= R; ++i)
s[i] ^= 1;
int ans = 0;
for (int i = 0; i < m; ++i)
{
ans = (ans + s[i] * u[i]) % M;
}
return ans;
}
/*
3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6
*/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |