답안 #930196

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930196 2024-02-18T23:58:14 Z Edu175 디지털 회로 (IOI22_circuit) C++17
34 / 100
3000 ms 39832 KB
#include "circuit.h"
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ioi=b;i<ioi;i++)
#define dfore(i,a,b) for(ll i=b-1,ioi=a;i>=ioi;i--)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define imp(v) for(auto djfhg:v)cout<<djfhg<<" ";cout<<"\n"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll MAXN=2e5+5,MOD=1000002022;
int add(int a, int b){a+=b;if(a>=MOD)a-=MOD;return a;}
int sub(int a, int b){a-=b;if(a<0)a+=MOD;return a;}
int mul(ll a, ll b){return a*b%MOD;}

ll n,m;
vector<ll>g[MAXN];
ll a[MAXN],tot[MAXN],dp[MAXN];
vector<ll> pre[MAXN], suf[MAXN];
struct tn{
	ll r0,r1;
};
/*string cv(tn a){
	return "["+to_string(a.r0)+","+to_string(a.r1)+"]";
}*/
tn unit(ll v){
	if(!v)return tn({1,0});
	return tn({0,1});
}
typedef ll tl;
tl CLEAR=0;
tn NEUT({0,0});
tn oper(tn a, tn b, ll k){
	tn c=NEUT;
	ll xa=2*k-1,xb=2*k;
	c.r0=add(mul(a.r0,tot[xb]),mul(b.r0,tot[xa]));
	c.r1=add(mul(a.r1,tot[xb]),mul(b.r1,tot[xa]));
	return c;
}
void acum(tl &a, ll v){
	a^=v;
};
void calc(tn &a, ll v){
	if(v)swap(a.r0,a.r1);
}
struct STree{
	vector<tn>st; vector<tl>lazy; ll n;
	STree(ll n): st(4*n+5,NEUT),lazy(4*n+5,CLEAR),n(n){}
	void push(ll k, ll s, ll e){
		calc(st[k],lazy[k]);
		if(e-s>1){
			acum(lazy[2*k],lazy[k]);
			acum(lazy[2*k+1],lazy[k]);
		}
		lazy[k]=CLEAR;
	}
	void init(ll k, ll s, ll e, vector<int>&a){
		if(e-s==1)st[k]=unit(a[s]);
		else {
			ll m=(s+e)/2;
			init(2*k,s,m,a); init(2*k+1,m,e,a);
			st[k]=oper(st[2*k],st[2*k+1],k);
		}
		//cout<<"init "<<k<<" "<<s<<","<<e<<" = "<<cv(st[k])<<"\n";
	}
	void upd(ll k, ll s, ll e, ll a, ll b){
		push(k,s,e);
		if(e<=a||b<=s);
		else if(a<=s&&e<=b){
			acum(lazy[k],1);
			push(k,s,e);
		}
		else {
			ll m=(s+e)/2;
			upd(2*k,s,m,a,b); upd(2*k+1,m,e,a,b);
			st[k]=oper(st[2*k],st[2*k+1],k);
		}
		//cout<<"upd "<<k<<" "<<s<<","<<e<<" "<<a<<","<<b<<" = "<<cv(st[k])<<"\n";
	}
	void init(vector<int>&a){init(1,0,n,a);}
	void upd(ll a, ll b){upd(1,0,n,a,b);}
	ll get(){
		push(1,0,n);
		return st[1].r1;
	}
};
STree st(0);
bool segtree=1;
void init(int N, int M, std::vector<int> P, std::vector<int> A){
	n=N,m=M;
	segtree=__builtin_popcountll(m)==1&&m==n+1;
	fore(i,0,SZ(P)){
		if(P[i]!=-1)g[P[i]].pb(i);
		if(i)segtree&=P[i]==(i-1)/2;
	}
	fore(i,0,m)a[i+n]=A[i];
	fore(i,0,m)tot[n+i]=1;
	dfore(x,0,n){
		ll k=SZ(g[x]);
		tot[x]=k;
		for(auto y:g[x])tot[x]=mul(tot[x],tot[y]);
		pre[x].resize(k+1,1),suf[x].resize(k+1,1);
		fore(i,1,k+1)pre[x][i]=mul(pre[x][i-1],tot[g[x][i-1]]);
		dfore(i,0,k)suf[x][i]=mul(suf[x][i+1],tot[g[x][i]]);
	}
	st=STree(m);
	st.init(A);
	//cout<<segtree<<" seg\n";
}

int count_ways(int L, int R){
	if(segtree){
		ll l=L-n,r=R-n+1;
		//cout<<"cw "<<l<<","<<r<<":\n";
		//fore(i,1,n+m)cout<<i<<": "<<cv(st.st[i])<<"\n";
		st.upd(l,r);
		return st.get();
	}
	else {
		fore(i,L,R+1)a[i]^=1;
		//fore(i,n,n+m)cout<<a[i];;cout<<"\n";
		dfore(x,0,n+m){
			dp[x]=0;
			if(x>=n)dp[x]=a[x];
			else {
				fore(i,0,SZ(g[x])){
					auto y=g[x][i];
					dp[x]=add(dp[x],mul(dp[y],mul(pre[x][i],suf[x][i+1])));
				}
			}
			//cout<<x<<": "<<dp[x]<<"\n";
		}
	return dp[0];
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 4 ms 19032 KB Output is correct
3 Correct 5 ms 19288 KB Output is correct
4 Correct 4 ms 19464 KB Output is correct
5 Correct 5 ms 19288 KB Output is correct
6 Correct 4 ms 19288 KB Output is correct
7 Correct 4 ms 19128 KB Output is correct
8 Correct 4 ms 19288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 4 ms 19032 KB Output is correct
3 Correct 4 ms 19288 KB Output is correct
4 Correct 4 ms 19288 KB Output is correct
5 Correct 4 ms 19128 KB Output is correct
6 Correct 5 ms 19288 KB Output is correct
7 Correct 4 ms 19288 KB Output is correct
8 Correct 5 ms 19284 KB Output is correct
9 Correct 4 ms 19288 KB Output is correct
10 Correct 4 ms 19280 KB Output is correct
11 Correct 4 ms 19272 KB Output is correct
12 Correct 5 ms 19288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 4 ms 19032 KB Output is correct
3 Correct 5 ms 19288 KB Output is correct
4 Correct 4 ms 19464 KB Output is correct
5 Correct 5 ms 19288 KB Output is correct
6 Correct 4 ms 19288 KB Output is correct
7 Correct 4 ms 19128 KB Output is correct
8 Correct 4 ms 19288 KB Output is correct
9 Correct 4 ms 19032 KB Output is correct
10 Correct 4 ms 19032 KB Output is correct
11 Correct 4 ms 19288 KB Output is correct
12 Correct 4 ms 19288 KB Output is correct
13 Correct 4 ms 19128 KB Output is correct
14 Correct 5 ms 19288 KB Output is correct
15 Correct 4 ms 19288 KB Output is correct
16 Correct 5 ms 19284 KB Output is correct
17 Correct 4 ms 19288 KB Output is correct
18 Correct 4 ms 19280 KB Output is correct
19 Correct 4 ms 19272 KB Output is correct
20 Correct 5 ms 19288 KB Output is correct
21 Correct 4 ms 19664 KB Output is correct
22 Correct 4 ms 19288 KB Output is correct
23 Correct 4 ms 19288 KB Output is correct
24 Correct 4 ms 19288 KB Output is correct
25 Correct 4 ms 19288 KB Output is correct
26 Correct 4 ms 19288 KB Output is correct
27 Correct 4 ms 19288 KB Output is correct
28 Correct 4 ms 19224 KB Output is correct
29 Correct 4 ms 19288 KB Output is correct
30 Correct 4 ms 19288 KB Output is correct
31 Correct 5 ms 19288 KB Output is correct
32 Correct 4 ms 19288 KB Output is correct
33 Correct 4 ms 19288 KB Output is correct
34 Correct 4 ms 19224 KB Output is correct
35 Correct 4 ms 19288 KB Output is correct
36 Correct 5 ms 19544 KB Output is correct
37 Correct 5 ms 19288 KB Output is correct
38 Correct 4 ms 19288 KB Output is correct
39 Correct 4 ms 19288 KB Output is correct
40 Correct 4 ms 19260 KB Output is correct
41 Correct 4 ms 19288 KB Output is correct
42 Correct 4 ms 19288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 387 ms 26016 KB Output is correct
2 Correct 560 ms 33112 KB Output is correct
3 Correct 561 ms 33032 KB Output is correct
4 Correct 567 ms 33048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 387 ms 26016 KB Output is correct
2 Correct 560 ms 33112 KB Output is correct
3 Correct 561 ms 33032 KB Output is correct
4 Correct 567 ms 33048 KB Output is correct
5 Correct 453 ms 25944 KB Output is correct
6 Correct 620 ms 32856 KB Output is correct
7 Correct 633 ms 33040 KB Output is correct
8 Correct 560 ms 33068 KB Output is correct
9 Correct 238 ms 19544 KB Output is correct
10 Correct 520 ms 20088 KB Output is correct
11 Correct 553 ms 20084 KB Output is correct
12 Correct 523 ms 20080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 4 ms 19032 KB Output is correct
3 Correct 4 ms 19288 KB Output is correct
4 Correct 4 ms 19288 KB Output is correct
5 Correct 4 ms 19128 KB Output is correct
6 Correct 5 ms 19288 KB Output is correct
7 Correct 4 ms 19288 KB Output is correct
8 Correct 5 ms 19284 KB Output is correct
9 Correct 4 ms 19288 KB Output is correct
10 Correct 4 ms 19280 KB Output is correct
11 Correct 4 ms 19272 KB Output is correct
12 Correct 5 ms 19288 KB Output is correct
13 Correct 387 ms 26016 KB Output is correct
14 Correct 560 ms 33112 KB Output is correct
15 Correct 561 ms 33032 KB Output is correct
16 Correct 567 ms 33048 KB Output is correct
17 Correct 453 ms 25944 KB Output is correct
18 Correct 620 ms 32856 KB Output is correct
19 Correct 633 ms 33040 KB Output is correct
20 Correct 560 ms 33068 KB Output is correct
21 Correct 238 ms 19544 KB Output is correct
22 Correct 520 ms 20088 KB Output is correct
23 Correct 553 ms 20084 KB Output is correct
24 Correct 523 ms 20080 KB Output is correct
25 Execution timed out 3088 ms 39832 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 4 ms 19032 KB Output is correct
3 Correct 5 ms 19288 KB Output is correct
4 Correct 4 ms 19464 KB Output is correct
5 Correct 5 ms 19288 KB Output is correct
6 Correct 4 ms 19288 KB Output is correct
7 Correct 4 ms 19128 KB Output is correct
8 Correct 4 ms 19288 KB Output is correct
9 Correct 4 ms 19032 KB Output is correct
10 Correct 4 ms 19032 KB Output is correct
11 Correct 4 ms 19288 KB Output is correct
12 Correct 4 ms 19288 KB Output is correct
13 Correct 4 ms 19128 KB Output is correct
14 Correct 5 ms 19288 KB Output is correct
15 Correct 4 ms 19288 KB Output is correct
16 Correct 5 ms 19284 KB Output is correct
17 Correct 4 ms 19288 KB Output is correct
18 Correct 4 ms 19280 KB Output is correct
19 Correct 4 ms 19272 KB Output is correct
20 Correct 5 ms 19288 KB Output is correct
21 Correct 4 ms 19664 KB Output is correct
22 Correct 4 ms 19288 KB Output is correct
23 Correct 4 ms 19288 KB Output is correct
24 Correct 4 ms 19288 KB Output is correct
25 Correct 4 ms 19288 KB Output is correct
26 Correct 4 ms 19288 KB Output is correct
27 Correct 4 ms 19288 KB Output is correct
28 Correct 4 ms 19224 KB Output is correct
29 Correct 4 ms 19288 KB Output is correct
30 Correct 4 ms 19288 KB Output is correct
31 Correct 5 ms 19288 KB Output is correct
32 Correct 4 ms 19288 KB Output is correct
33 Correct 4 ms 19288 KB Output is correct
34 Correct 4 ms 19224 KB Output is correct
35 Correct 4 ms 19288 KB Output is correct
36 Correct 5 ms 19544 KB Output is correct
37 Correct 5 ms 19288 KB Output is correct
38 Correct 4 ms 19288 KB Output is correct
39 Correct 4 ms 19288 KB Output is correct
40 Correct 4 ms 19260 KB Output is correct
41 Correct 4 ms 19288 KB Output is correct
42 Correct 4 ms 19288 KB Output is correct
43 Correct 2723 ms 19856 KB Output is correct
44 Execution timed out 3080 ms 19800 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19032 KB Output is correct
2 Correct 4 ms 19032 KB Output is correct
3 Correct 5 ms 19288 KB Output is correct
4 Correct 4 ms 19464 KB Output is correct
5 Correct 5 ms 19288 KB Output is correct
6 Correct 4 ms 19288 KB Output is correct
7 Correct 4 ms 19128 KB Output is correct
8 Correct 4 ms 19288 KB Output is correct
9 Correct 4 ms 19032 KB Output is correct
10 Correct 4 ms 19032 KB Output is correct
11 Correct 4 ms 19288 KB Output is correct
12 Correct 4 ms 19288 KB Output is correct
13 Correct 4 ms 19128 KB Output is correct
14 Correct 5 ms 19288 KB Output is correct
15 Correct 4 ms 19288 KB Output is correct
16 Correct 5 ms 19284 KB Output is correct
17 Correct 4 ms 19288 KB Output is correct
18 Correct 4 ms 19280 KB Output is correct
19 Correct 4 ms 19272 KB Output is correct
20 Correct 5 ms 19288 KB Output is correct
21 Correct 4 ms 19664 KB Output is correct
22 Correct 4 ms 19288 KB Output is correct
23 Correct 4 ms 19288 KB Output is correct
24 Correct 4 ms 19288 KB Output is correct
25 Correct 4 ms 19288 KB Output is correct
26 Correct 4 ms 19288 KB Output is correct
27 Correct 4 ms 19288 KB Output is correct
28 Correct 4 ms 19224 KB Output is correct
29 Correct 4 ms 19288 KB Output is correct
30 Correct 4 ms 19288 KB Output is correct
31 Correct 5 ms 19288 KB Output is correct
32 Correct 4 ms 19288 KB Output is correct
33 Correct 4 ms 19288 KB Output is correct
34 Correct 4 ms 19224 KB Output is correct
35 Correct 4 ms 19288 KB Output is correct
36 Correct 5 ms 19544 KB Output is correct
37 Correct 5 ms 19288 KB Output is correct
38 Correct 4 ms 19288 KB Output is correct
39 Correct 4 ms 19288 KB Output is correct
40 Correct 4 ms 19260 KB Output is correct
41 Correct 4 ms 19288 KB Output is correct
42 Correct 4 ms 19288 KB Output is correct
43 Correct 387 ms 26016 KB Output is correct
44 Correct 560 ms 33112 KB Output is correct
45 Correct 561 ms 33032 KB Output is correct
46 Correct 567 ms 33048 KB Output is correct
47 Correct 453 ms 25944 KB Output is correct
48 Correct 620 ms 32856 KB Output is correct
49 Correct 633 ms 33040 KB Output is correct
50 Correct 560 ms 33068 KB Output is correct
51 Correct 238 ms 19544 KB Output is correct
52 Correct 520 ms 20088 KB Output is correct
53 Correct 553 ms 20084 KB Output is correct
54 Correct 523 ms 20080 KB Output is correct
55 Execution timed out 3088 ms 39832 KB Time limit exceeded
56 Halted 0 ms 0 KB -