답안 #821820

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
821820 2023-08-11T17:57:16 Z I_Love_EliskaM_ 디지털 회로 (IOI22_circuit) C++17
46 / 100
907 ms 32360 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 int64_t

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];

int one=1;

void dfs(int u) {
  z[u]=adj[u].size();
  z[u]=max(z[u],one);
  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( (1ll*pr.back()*z[v])%mod );
  reverse(all(adj[u]));
  for(auto&v:adj[u]) sf.pb( (1ll*sf.back()*z[v])%mod );
  reverse(all(sf));
  reverse(all(adj[u]));

  f[u]=o;

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

const int sz=1<<20;
struct node {
  int sum=0,now=0,lazy=0;
};
node t[8*sz];
node merge(node a, node b) {
  node n;
  n.sum=(a.sum+b.sum)%mod;
  n.now=(a.now+b.now)%mod;
  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+mod)%mod;
    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(int64_t, int64_t)':
circuit.cpp:4:33: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for(int i=0; i<n; ++i)
......
   43 |   forn(i,adj[u].size()) {
      |        ~~~~~~~~~~~~~~~           
circuit.cpp:43:3: note: in expansion of macro 'forn'
   43 |   forn(i,adj[u].size()) {
      |   ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 27232 KB Output is correct
2 Correct 18 ms 27320 KB Output is correct
3 Correct 23 ms 27444 KB Output is correct
4 Correct 19 ms 27344 KB Output is correct
5 Correct 19 ms 27344 KB Output is correct
6 Correct 18 ms 27396 KB Output is correct
7 Correct 19 ms 27344 KB Output is correct
8 Correct 19 ms 27364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 27280 KB Output is correct
2 Correct 18 ms 27320 KB Output is correct
3 Correct 20 ms 27344 KB Output is correct
4 Correct 19 ms 27384 KB Output is correct
5 Correct 23 ms 27292 KB Output is correct
6 Correct 18 ms 27412 KB Output is correct
7 Correct 19 ms 27472 KB Output is correct
8 Correct 19 ms 27336 KB Output is correct
9 Correct 18 ms 27472 KB Output is correct
10 Correct 18 ms 27728 KB Output is correct
11 Correct 19 ms 27620 KB Output is correct
12 Correct 19 ms 27448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 27232 KB Output is correct
2 Correct 18 ms 27320 KB Output is correct
3 Correct 23 ms 27444 KB Output is correct
4 Correct 19 ms 27344 KB Output is correct
5 Correct 19 ms 27344 KB Output is correct
6 Correct 18 ms 27396 KB Output is correct
7 Correct 19 ms 27344 KB Output is correct
8 Correct 19 ms 27364 KB Output is correct
9 Correct 20 ms 27280 KB Output is correct
10 Correct 18 ms 27320 KB Output is correct
11 Correct 20 ms 27344 KB Output is correct
12 Correct 19 ms 27384 KB Output is correct
13 Correct 23 ms 27292 KB Output is correct
14 Correct 18 ms 27412 KB Output is correct
15 Correct 19 ms 27472 KB Output is correct
16 Correct 19 ms 27336 KB Output is correct
17 Correct 18 ms 27472 KB Output is correct
18 Correct 18 ms 27728 KB Output is correct
19 Correct 19 ms 27620 KB Output is correct
20 Correct 19 ms 27448 KB Output is correct
21 Correct 19 ms 27388 KB Output is correct
22 Correct 20 ms 27344 KB Output is correct
23 Correct 18 ms 27320 KB Output is correct
24 Correct 19 ms 27396 KB Output is correct
25 Correct 19 ms 27444 KB Output is correct
26 Correct 19 ms 27344 KB Output is correct
27 Correct 19 ms 27472 KB Output is correct
28 Correct 19 ms 27480 KB Output is correct
29 Correct 19 ms 27452 KB Output is correct
30 Correct 19 ms 27344 KB Output is correct
31 Correct 19 ms 27508 KB Output is correct
32 Correct 19 ms 27472 KB Output is correct
33 Correct 19 ms 27356 KB Output is correct
34 Correct 19 ms 27404 KB Output is correct
35 Correct 19 ms 27428 KB Output is correct
36 Correct 20 ms 27600 KB Output is correct
37 Correct 20 ms 27644 KB Output is correct
38 Correct 20 ms 27728 KB Output is correct
39 Correct 22 ms 27396 KB Output is correct
40 Correct 19 ms 27436 KB Output is correct
41 Correct 21 ms 27432 KB Output is correct
42 Correct 19 ms 27412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 650 ms 32360 KB Output is correct
2 Runtime error 31 ms 14680 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 650 ms 32360 KB Output is correct
2 Runtime error 31 ms 14680 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 27280 KB Output is correct
2 Correct 18 ms 27320 KB Output is correct
3 Correct 20 ms 27344 KB Output is correct
4 Correct 19 ms 27384 KB Output is correct
5 Correct 23 ms 27292 KB Output is correct
6 Correct 18 ms 27412 KB Output is correct
7 Correct 19 ms 27472 KB Output is correct
8 Correct 19 ms 27336 KB Output is correct
9 Correct 18 ms 27472 KB Output is correct
10 Correct 18 ms 27728 KB Output is correct
11 Correct 19 ms 27620 KB Output is correct
12 Correct 19 ms 27448 KB Output is correct
13 Correct 650 ms 32360 KB Output is correct
14 Runtime error 31 ms 14680 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 27232 KB Output is correct
2 Correct 18 ms 27320 KB Output is correct
3 Correct 23 ms 27444 KB Output is correct
4 Correct 19 ms 27344 KB Output is correct
5 Correct 19 ms 27344 KB Output is correct
6 Correct 18 ms 27396 KB Output is correct
7 Correct 19 ms 27344 KB Output is correct
8 Correct 19 ms 27364 KB Output is correct
9 Correct 20 ms 27280 KB Output is correct
10 Correct 18 ms 27320 KB Output is correct
11 Correct 20 ms 27344 KB Output is correct
12 Correct 19 ms 27384 KB Output is correct
13 Correct 23 ms 27292 KB Output is correct
14 Correct 18 ms 27412 KB Output is correct
15 Correct 19 ms 27472 KB Output is correct
16 Correct 19 ms 27336 KB Output is correct
17 Correct 18 ms 27472 KB Output is correct
18 Correct 18 ms 27728 KB Output is correct
19 Correct 19 ms 27620 KB Output is correct
20 Correct 19 ms 27448 KB Output is correct
21 Correct 19 ms 27388 KB Output is correct
22 Correct 20 ms 27344 KB Output is correct
23 Correct 18 ms 27320 KB Output is correct
24 Correct 19 ms 27396 KB Output is correct
25 Correct 19 ms 27444 KB Output is correct
26 Correct 19 ms 27344 KB Output is correct
27 Correct 19 ms 27472 KB Output is correct
28 Correct 19 ms 27480 KB Output is correct
29 Correct 19 ms 27452 KB Output is correct
30 Correct 19 ms 27344 KB Output is correct
31 Correct 19 ms 27508 KB Output is correct
32 Correct 19 ms 27472 KB Output is correct
33 Correct 19 ms 27356 KB Output is correct
34 Correct 19 ms 27404 KB Output is correct
35 Correct 19 ms 27428 KB Output is correct
36 Correct 20 ms 27600 KB Output is correct
37 Correct 20 ms 27644 KB Output is correct
38 Correct 20 ms 27728 KB Output is correct
39 Correct 22 ms 27396 KB Output is correct
40 Correct 19 ms 27436 KB Output is correct
41 Correct 21 ms 27432 KB Output is correct
42 Correct 19 ms 27412 KB Output is correct
43 Correct 454 ms 27728 KB Output is correct
44 Correct 900 ms 27820 KB Output is correct
45 Correct 752 ms 27856 KB Output is correct
46 Correct 581 ms 28076 KB Output is correct
47 Correct 659 ms 28160 KB Output is correct
48 Correct 645 ms 28180 KB Output is correct
49 Correct 771 ms 28096 KB Output is correct
50 Correct 895 ms 27856 KB Output is correct
51 Correct 593 ms 27860 KB Output is correct
52 Correct 907 ms 28104 KB Output is correct
53 Correct 786 ms 28752 KB Output is correct
54 Correct 711 ms 28104 KB Output is correct
55 Correct 692 ms 27968 KB Output is correct
56 Correct 723 ms 27980 KB Output is correct
57 Correct 698 ms 27856 KB Output is correct
58 Correct 757 ms 29392 KB Output is correct
59 Correct 683 ms 29376 KB Output is correct
60 Correct 656 ms 29224 KB Output is correct
61 Correct 825 ms 28072 KB Output is correct
62 Correct 659 ms 27856 KB Output is correct
63 Correct 562 ms 27852 KB Output is correct
64 Correct 867 ms 27984 KB Output is correct
65 Correct 313 ms 27728 KB Output is correct
66 Correct 811 ms 27984 KB Output is correct
67 Correct 699 ms 27960 KB Output is correct
68 Correct 716 ms 27728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 27232 KB Output is correct
2 Correct 18 ms 27320 KB Output is correct
3 Correct 23 ms 27444 KB Output is correct
4 Correct 19 ms 27344 KB Output is correct
5 Correct 19 ms 27344 KB Output is correct
6 Correct 18 ms 27396 KB Output is correct
7 Correct 19 ms 27344 KB Output is correct
8 Correct 19 ms 27364 KB Output is correct
9 Correct 20 ms 27280 KB Output is correct
10 Correct 18 ms 27320 KB Output is correct
11 Correct 20 ms 27344 KB Output is correct
12 Correct 19 ms 27384 KB Output is correct
13 Correct 23 ms 27292 KB Output is correct
14 Correct 18 ms 27412 KB Output is correct
15 Correct 19 ms 27472 KB Output is correct
16 Correct 19 ms 27336 KB Output is correct
17 Correct 18 ms 27472 KB Output is correct
18 Correct 18 ms 27728 KB Output is correct
19 Correct 19 ms 27620 KB Output is correct
20 Correct 19 ms 27448 KB Output is correct
21 Correct 19 ms 27388 KB Output is correct
22 Correct 20 ms 27344 KB Output is correct
23 Correct 18 ms 27320 KB Output is correct
24 Correct 19 ms 27396 KB Output is correct
25 Correct 19 ms 27444 KB Output is correct
26 Correct 19 ms 27344 KB Output is correct
27 Correct 19 ms 27472 KB Output is correct
28 Correct 19 ms 27480 KB Output is correct
29 Correct 19 ms 27452 KB Output is correct
30 Correct 19 ms 27344 KB Output is correct
31 Correct 19 ms 27508 KB Output is correct
32 Correct 19 ms 27472 KB Output is correct
33 Correct 19 ms 27356 KB Output is correct
34 Correct 19 ms 27404 KB Output is correct
35 Correct 19 ms 27428 KB Output is correct
36 Correct 20 ms 27600 KB Output is correct
37 Correct 20 ms 27644 KB Output is correct
38 Correct 20 ms 27728 KB Output is correct
39 Correct 22 ms 27396 KB Output is correct
40 Correct 19 ms 27436 KB Output is correct
41 Correct 21 ms 27432 KB Output is correct
42 Correct 19 ms 27412 KB Output is correct
43 Correct 650 ms 32360 KB Output is correct
44 Runtime error 31 ms 14680 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -