답안 #628007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628007 2022-08-13T03:10:05 Z Hanksburger 디지털 회로 (IOI22_circuit) C++17
2 / 100
597 ms 7880 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+2022, sq=3e2;
int seg[400005], sum[400005], lazy[400005], state[200005], dp[200005], a[200005], n, m;
vector<int> adj[200005];
void dfs(int u)
{
    if (u>=n)
    {
        dp[u]=1;
        return;
    }
    dp[u]=adj[u].size();
    for (int v:adj[u])
    {
        dfs(v);
        dp[u]=(dp[u]*dp[v])%mod;
    }
}
void dfs2(int u, int x)
{
    if (u>=n)
    {
        a[u]=x;
        return;
    }
    vector<int> vec;
    for (int i=0; i<adj[u].size(); i++)
    {
        int v=adj[u][i];
        if (i%sq==0)
            vec.push_back(dp[v]);
        else
            vec[vec.size()-1]=(vec[vec.size()-1]*dp[v])%mod;
    }
//    cout << "vec: ";
//    for (int i=0; i<vec.size(); i++)
//        cout << vec[i] << ' ';
//    cout << '\n';
    for (int i=0; i<adj[u].size(); i++)
    {
        int v=adj[u][i], y=x;
        for (int j=0; j<i/sq; j++)
            y=(y*vec[j])%mod;
        for (int j=i/sq+1; j<vec.size(); j++)
            y=(y*vec[j])%mod;
        for (int j=i/sq*sq; j<i; j++)
            y=(y*dp[adj[u][j]])%mod;
        for (int j=i+1; j<min((int)adj[u].size(), (i/sq+1)*sq); j++)
            y=(y*dp[adj[u][j]])%mod;
        dfs2(v, y);
    }
}
void push(int i, int l, int r)
{
    if (lazy[i])
    {
        seg[i]=sum[i]-seg[i];
        lazy[i]=0;
        lazy[i*2]^=1;
        lazy[i*2+1]^=1;
    }
}
void build(int i, int l, int r)
{
    if (l==r)
    {
        sum[i]=a[l];
        seg[i]=a[l]*state[l];
//        cout << "l r seg " << l << ' ' << r << ' ' << seg[i] << '\n';
        return;
    }
    int mid=(l+r)/2;
    build(i*2, l, mid);
    build(i*2+1, mid+1, r);
    sum[i]=(sum[i*2]+sum[i*2+1])%mod;
    seg[i]=(seg[i*2]+seg[i*2+1])%mod;
//    cout << "l r seg " << l << ' ' << r << ' ' << seg[i] << '\n';
}
void update(int i, int l, int r, int ql, int qr)
{
    push(i, l, r);
    if (ql<=l && r<=qr)
    {
        lazy[i]=1;
        push(i, l, r);
//        cout << "l r seg " << l << ' ' << r << ' ' << seg[i] << '\n';
        return;
    }
    int mid=(l+r)/2;
    push(i*2, l, mid);
    push(i*2+1, mid+1, r);
    if (l<=qr && ql<=mid)
        update(i*2, l, mid, ql, qr);
    if (mid+1<=qr && ql<=r)
        update(i*2+1, mid+1, r, ql, qr);
    seg[i]=(seg[i*2]+seg[i*2+1])%mod;
//    cout << "l r seg " << l << ' ' << r << ' ' << seg[i] << '\n';
}
void init(int N, int M, vector<int> P, vector<int> A)
{
    n=N;
    m=M;
    for (int i=1; i<n+m; i++)
        adj[P[i]].push_back(i);
    dfs(0);
    dfs2(0, 1);
//    cout << "a: ";
//    for (int i=0; i<m; i++)
//        cout << a[i+n] << ' ';
//    cout << '\n';
    for (int i=0; i<m; i++)
        state[i+n]=A[i];
    build(1, n, n+m-1);
}
int count_ways(int L, int R)
{
    update(1, n, n+m-1, L, R);
    return seg[1];
}

Compilation message

circuit.cpp: In function 'void dfs2(int, int)':
circuit.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i=0; i<adj[u].size(); i++)
      |                   ~^~~~~~~~~~~~~~
circuit.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int i=0; i<adj[u].size(); i++)
      |                   ~^~~~~~~~~~~~~~
circuit.cpp:46:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for (int j=i/sq+1; j<vec.size(); j++)
      |                            ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5088 KB Output is correct
6 Correct 4 ms 5004 KB Output is correct
7 Correct 4 ms 4980 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '83005428'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5088 KB Output is correct
6 Correct 4 ms 5004 KB Output is correct
7 Correct 4 ms 4980 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '83005428'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 597 ms 7880 KB 1st lines differ - on the 1st token, expected: '431985922', found: '646726998'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 597 ms 7880 KB 1st lines differ - on the 1st token, expected: '431985922', found: '646726998'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '83005428'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5088 KB Output is correct
6 Correct 4 ms 5004 KB Output is correct
7 Correct 4 ms 4980 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '83005428'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5088 KB Output is correct
6 Correct 4 ms 5004 KB Output is correct
7 Correct 4 ms 4980 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Incorrect 3 ms 4944 KB 1st lines differ - on the 1st token, expected: '52130940', found: '83005428'
11 Halted 0 ms 0 KB -