답안 #821813

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
821813 2023-08-11T17:52:58 Z I_Love_EliskaM_ 디지털 회로 (IOI22_circuit) C++17
2 / 100
484 ms 10760 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0; i<n; ++i)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pi pair<int,int>
#define f first
#define s second
using ll = long long;
#define int ll

const int N=1e5+5;
int n,m;
vector<int> adj[N];
int dp[N][2];
int a[N];
const int mod = 1e9+2022;

int f[N];
int z[N];

void dfs(int u) {
  z[u]=adj[u].size();
  z[u]=max(z[u],1ll);
  for(auto&v:adj[u]) {
    dfs(v);
    z[u]=(z[u]*z[v])%mod;
  }
}
void dfs(int u, int o) {
  vector<int> pr={1}, sf={1};
  for(auto&v:adj[u]) pr.pb( (pr.back()*z[v])%mod );
  reverse(all(adj[u]));
  for(auto&v:adj[u]) sf.pb( (sf.back()*z[v])%mod );
  reverse(all(sf));
  reverse(all(adj[u]));

  f[u]=o;

  forn(i,adj[u].size()) {
    int x = (o*pr[i])%mod;
    x = (x*sf[i+1])%mod;
    dfs(adj[u][i],x);
  }
}

const int sz=1<<17;
struct node {
  int sum=0,now=0,lazy=0;
};
node t[4*sz];
node merge(node a, node b) {
  node n;
  n.sum=a.sum+b.sum;
  n.now=a.now+b.now;
  n.lazy=0;
  return n;
}
void build(int v, int l, int r) {
  if (r-l==1) return;
  int m=(l+r)>>1;
  build(2*v+1,l,m);
  build(2*v+2,m,r);
  t[v]=merge(t[2*v+1],t[2*v+2]);
}
void build() {
  forn(i,m) {
    t[sz-1+i].sum=f[n+i];
    t[sz-1+i].now=a[i]*f[n+i];
    t[sz-1+i].lazy=0;
  }
  build(0,0,sz);
}

void push(int v) {
  if (t[v].lazy) {
    t[v].now=t[v].sum-t[v].now;
    t[2*v+1].lazy^=t[v].lazy;
    t[2*v+2].lazy^=t[v].lazy;
    t[v].lazy=0;
  }
}
void flip(int v, int l, int r, int lx, int rx) {
  if (t[v].lazy) push(v);
  if (rx<=l || r<=lx) return;
  if (lx<=l && r<=rx) {
    t[v].lazy^=1;
    push(v);
    return;
  }
  int m=(l+r)>>1;
  flip(2*v+1,l,m,lx,rx);
  flip(2*v+2,m,r,lx,rx);
  t[v]=merge(t[2*v+1],t[2*v+2]);
}
void flip(int l, int r) {
  flip(0,0,sz,l,r);
}

#undef int

void init(int _n, int _m, vector<int>p, vector<int>_a) {

  n=_n, m=_m;
  forn(i,m) a[i]=_a[i];
  for (int i=1; i<n+m; ++i) {
    adj[p[i]].pb(i);
  }
  dfs(0);
  dfs(0,1);
  build();

}

int count_ways(int l, int r) {
  flip(l-n,r-n+1);
  return t[0].now;
}

Compilation message

circuit.cpp: In function 'void dfs(ll, ll)':
circuit.cpp:4:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for(int i=0; i<n; ++i)
......
   41 |   forn(i,adj[u].size()) {
      |        ~~~~~~~~~~~~~~~           
circuit.cpp:41:3: note: in expansion of macro 'forn'
   41 |   forn(i,adj[u].size()) {
      |   ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 5 ms 5840 KB Output is correct
4 Correct 4 ms 5764 KB Output is correct
5 Correct 3 ms 5840 KB Output is correct
6 Correct 4 ms 5840 KB Output is correct
7 Correct 3 ms 5840 KB Output is correct
8 Correct 4 ms 5860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Incorrect 3 ms 5712 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 5 ms 5840 KB Output is correct
4 Correct 4 ms 5764 KB Output is correct
5 Correct 3 ms 5840 KB Output is correct
6 Correct 4 ms 5840 KB Output is correct
7 Correct 3 ms 5840 KB Output is correct
8 Correct 4 ms 5860 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Incorrect 3 ms 5712 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 484 ms 10760 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 484 ms 10760 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Incorrect 3 ms 5712 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 5 ms 5840 KB Output is correct
4 Correct 4 ms 5764 KB Output is correct
5 Correct 3 ms 5840 KB Output is correct
6 Correct 4 ms 5840 KB Output is correct
7 Correct 3 ms 5840 KB Output is correct
8 Correct 4 ms 5860 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Incorrect 3 ms 5712 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 5 ms 5840 KB Output is correct
4 Correct 4 ms 5764 KB Output is correct
5 Correct 3 ms 5840 KB Output is correct
6 Correct 4 ms 5840 KB Output is correct
7 Correct 3 ms 5840 KB Output is correct
8 Correct 4 ms 5860 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Incorrect 3 ms 5712 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -