답안 #629003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629003 2022-08-13T23:18:57 Z errorgorn 디지털 회로 (IOI22_circuit) C++17
2 / 100
633 ms 21148 KB
#include "circuit.h"

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define fi first
#define se second

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

struct node{
	int s,e,m;
	ii val={0,0};
	bool lazy=false;
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	
	void propo(){
		if (!lazy) return;
		swap(val.fi,val.se);
		if (s!=e){
			l->lazy^=true;
			r->lazy^=true;
		}
		lazy=false;
	}
	
	void update(int i,ii k){
		if (s==e) val=k;
		else{
			if (i<=m) l->update(i,k);
			else r->update(i,k);
			
			val={l->val.fi+r->val.fi,l->val.se+r->val.se};
		}
	}
	
	void update(int i,int j){
		propo();
		
		if (s==i && e==j) lazy^=true;
		else{
			if (j<=m) l->update(i,j);
			else if (m<i) r->update(i,j);
			else l->update(i,m),r->update(m+1,j);
			
			l->propo(),r->propo();
			val={l->val.fi+r->val.fi,l->val.se+r->val.se};
		}
	}
} *root=new node(0,100005);

const int MOD=1000002022;

int n,m;
vector<int> al[100005];
int coef[100005];
int arr[100005];

int ss[100005];

void dfs_ss(int i){
	if (i<n){
		ss[i]=sz(al[i]);
		for (auto it:al[i]){
			dfs_ss(it);
			ss[i]=ss[i]*ss[it]%MOD;
		}
	}
	else ss[i]=1;
}

void dfs(int i,int ans){
	if (i<n){
		vector<int> v;
		for (auto it:al[i]) v.pub(ss[it]);
		
		vector<int> f={1},b={1};
		rep(x,0,sz(v)) f.pub(f.back()*v[x]%MOD);
		rep(x,sz(v),0) b.pub(b.back()*v[x]%MOD);
		
		reverse(all(b));
		
		rep(x,0,sz(v)) dfs(al[i][x],ans*f[x]%MOD*b[x+1]%MOD);
	}
	else coef[i-n]=ans;
}

void init(signed N, signed M, vector<signed> P, vector<signed> A) {
	n=N,m=M;
	rep(x,1,n+m) al[P[x]].pub(x);
	rep(x,0,m) arr[x]=A[x];
	
	dfs_ss(0);
	dfs(0,1);
	
	//rep(x,0,m) cout<<coef[x]<<" "; cout<<endl;
	rep(x,0,m){
		if (A[x]) root->update(x,{coef[x],0});
		else root->update(x,{0,coef[x]});
	}
}

signed count_ways(signed a, signed b) {
	root->update(a-n,b-n);
	return root->val.fi;
}

Compilation message

circuit.cpp: In constructor 'node::node(long long int, long long int)':
circuit.cpp:31:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 18256 KB Output is correct
2 Correct 15 ms 18232 KB Output is correct
3 Correct 12 ms 18384 KB Output is correct
4 Correct 12 ms 18384 KB Output is correct
5 Correct 13 ms 18384 KB Output is correct
6 Correct 12 ms 18384 KB Output is correct
7 Correct 12 ms 18384 KB Output is correct
8 Correct 12 ms 18328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 18256 KB Output is correct
2 Incorrect 16 ms 18256 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 18256 KB Output is correct
2 Correct 15 ms 18232 KB Output is correct
3 Correct 12 ms 18384 KB Output is correct
4 Correct 12 ms 18384 KB Output is correct
5 Correct 13 ms 18384 KB Output is correct
6 Correct 12 ms 18384 KB Output is correct
7 Correct 12 ms 18384 KB Output is correct
8 Correct 12 ms 18328 KB Output is correct
9 Correct 11 ms 18256 KB Output is correct
10 Incorrect 16 ms 18256 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 633 ms 21148 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 633 ms 21148 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 18256 KB Output is correct
2 Incorrect 16 ms 18256 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 18256 KB Output is correct
2 Correct 15 ms 18232 KB Output is correct
3 Correct 12 ms 18384 KB Output is correct
4 Correct 12 ms 18384 KB Output is correct
5 Correct 13 ms 18384 KB Output is correct
6 Correct 12 ms 18384 KB Output is correct
7 Correct 12 ms 18384 KB Output is correct
8 Correct 12 ms 18328 KB Output is correct
9 Correct 11 ms 18256 KB Output is correct
10 Incorrect 16 ms 18256 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 18256 KB Output is correct
2 Correct 15 ms 18232 KB Output is correct
3 Correct 12 ms 18384 KB Output is correct
4 Correct 12 ms 18384 KB Output is correct
5 Correct 13 ms 18384 KB Output is correct
6 Correct 12 ms 18384 KB Output is correct
7 Correct 12 ms 18384 KB Output is correct
8 Correct 12 ms 18328 KB Output is correct
9 Correct 11 ms 18256 KB Output is correct
10 Incorrect 16 ms 18256 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -