답안 #628053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628053 2022-08-13T04:02:05 Z czhang2718 디지털 회로 (IOI22_circuit) C++17
13 / 100
1022 ms 11928 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

const int mod=1e9+2022;
const int N=2e5;
int n, m, q;
vector<int> adj[N];
int p[N];
int a[N];
int sum[4*N], con[4*N], c[N];
ll prod[N];

int add(int a, int b){
    return ((a+mod)%mod+(b+mod)%mod)%mod;
}

void add2(int &a, int b){
    a=add(a,b);
}

int mult(ll a, ll b){
    return (a*b)%mod;
}

void mult2(ll &a, ll b){
    a=mult(a,b);
}

void dfs(int x){
    prod[x]=x<n?adj[x].size():1;
    for(int k:adj[x]){
        dfs(k);
        mult2(prod[x], prod[k]);
    }
}

void dfs2(int x){
    int p=adj[x].size();
    vector<ll> pre(p), suf(p);
    for(int i=0; i<p; i++){
        int k=adj[x][i];
        pre[i]=suf[i]=prod[k];
    }
    for(int i=1; i<p; i++){
        mult2(pre[i], pre[i-1]);
    }
    for(int i=p-2; i>=0; i--){
        mult2(suf[i], suf[i+1]);
    }

    for(int i=0; i<p; i++){
        int k=adj[x][i];
        c[k]=mult(c[x], mult(i?pre[i-1]:1, i<p-1?suf[i+1]:1));
        dfs2(k);
    }
}

short lazy[4*N];

void build(int x, int lx, int rx){
    if(rx-lx==1){
        con[x]=a[lx]?c[lx+n]:0;
        // cout << "c[" << lx+n << "] " << c[lx+n] << "\n";
        sum[x]=c[lx+n];
        return;
    }
    int m=(lx+rx)/2;
    build(2*x+1, lx, m);
    build(2*x+2, m, rx);
    con[x]=add(con[2*x+1], con[2*x+2]);
    sum[x]=add(sum[2*x+1], sum[2*x+2]);
}

void push(int x, int lx, int rx){
    if(rx-lx==1 || !lazy[x]) return;
    for(int y=2*x+1; y<=2*x+2; y++){
        con[y]=sum[y]-con[y];
        lazy[y]^=1;
    }
    lazy[x]=0;
}

void tog(int l, int r, int x=0, int lx=0, int rx=m){
    push(x, lx, rx);
    if(lx>=r || rx<=l) return;
    if(lx>=l && rx<=r){
        con[x]=sum[x]-con[x];
        lazy[x]=1;
        return;
    }
    int m=(lx+rx)/2;
    tog(l, r, 2*x+1, lx, m);
    tog(l, r, 2*x+2, m, rx);
    con[x]=add(con[2*x+1], con[2*x+2]);
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  n=N, m=M;
  for(int i=0; i<n+m; i++){
      p[i]=P[i];
      if(i) adj[p[i]].push_back(i);
  }
  for(int i=0; i<m; i++) a[i]=A[i];

  dfs(0);
  c[0]=1;
  dfs2(0);
  build(0, 0, m);
}

int count_ways(int l, int r) {
  l-=n; r-=n;
  tog(l, r+1);
  return con[0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5124 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 4 ms 5200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5124 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 4 ms 5200 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 4 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Incorrect 4 ms 5072 KB 2nd lines differ - on the 1st token, expected: '903738266', found: '-96263756'
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 667 ms 8464 KB Output is correct
2 Correct 923 ms 11928 KB Output is correct
3 Correct 976 ms 11900 KB Output is correct
4 Correct 892 ms 11916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 667 ms 8464 KB Output is correct
2 Correct 923 ms 11928 KB Output is correct
3 Correct 976 ms 11900 KB Output is correct
4 Correct 892 ms 11916 KB Output is correct
5 Correct 879 ms 8400 KB Output is correct
6 Correct 1022 ms 11908 KB Output is correct
7 Correct 973 ms 11900 KB Output is correct
8 Incorrect 693 ms 11908 KB 1099th lines differ - on the 1st token, expected: '196050388', found: '-803951634'
9 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 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5124 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 4 ms 5200 KB Output is correct
13 Correct 667 ms 8464 KB Output is correct
14 Correct 923 ms 11928 KB Output is correct
15 Correct 976 ms 11900 KB Output is correct
16 Correct 892 ms 11916 KB Output is correct
17 Correct 879 ms 8400 KB Output is correct
18 Correct 1022 ms 11908 KB Output is correct
19 Correct 973 ms 11900 KB Output is correct
20 Incorrect 693 ms 11908 KB 1099th lines differ - on the 1st token, expected: '196050388', found: '-803951634'
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5124 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 4 ms 5200 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 4 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Incorrect 4 ms 5072 KB 2nd lines differ - on the 1st token, expected: '903738266', found: '-96263756'
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5124 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 4 ms 5200 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 4 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Incorrect 4 ms 5072 KB 2nd lines differ - on the 1st token, expected: '903738266', found: '-96263756'
29 Halted 0 ms 0 KB -