답안 #791658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791658 2023-07-24T08:38:25 Z firewater 디지털 회로 (IOI22_circuit) C++17
2 / 100
501 ms 20420 KB
#include "circuit.h"
#include<cstdio>
#include<vector>
#include<cstring>
//#include<cassert>
#include<iostream>
#include<algorithm>
#define ll long long
#define MX 202300
#define mod 1000002022
using namespace std;
ll n,m,a[MX],b[MX],sz[MX];
vector<ll>to[MX],pre[MX],suf[MX];

struct Tree
{
	#define ls x*2
	#define rs x*2+1
	ll c[MX<<2],s[MX<<2],lazy[MX<<2];
	void push_up(int x)
	{
		c[x]=c[ls]+c[rs];
		s[x]=s[ls]+s[rs];
		return;
	}
	void get(int x)
	{
		s[x]=(c[x]-s[x]+mod)%mod;
		lazy[x]^=1;
		return;
	}
	void push_down(int x)
	{
		if(lazy[x]){
			get(ls);
			get(rs);
			lazy[x]=0;
		}
		return;
	}
	void build(int x,int l,int r)
	{
		if(l==r){
			c[x]=a[l];
			s[x]=a[l]*b[l];
			return;
		}
		int mid=l+r>>1;
		build(ls,l,mid);
		build(rs,mid+1,r);
		push_up(x);
		return;
	}
	void change(int x,int L,int R,int l,int r)
	{
		if(L==l&&R==r){
			get(x);
			return;
		}
		push_down(x);
		int mid=L+R>>1;
		if(r<=mid)change(ls,L,mid,l,r);
		else if(l>mid)change(rs,mid+1,R,l,r);
		else change(ls,L,mid,l,mid),change(rs,mid+1,R,mid+1,r);
		push_up(x);
		return;
	}
}T;
void dfs(int x)
{
	sz[x]=to[x].size();
	if(!sz[x])sz[x]=1;
	int sav=to[x].size();
	for(int i=0;i<sav;++i){
		dfs(to[x][i]);
		sz[x]=sz[x]*sz[to[x][i]]%mod;
	}
	return;
}
void dfs1(int x,int num)
{
	if(x>=n)a[x-n+1]=num;
	int sav=to[x].size();
	for(int i=0;i<sav;++i){
		pre[x].push_back(sz[to[x][i]]);
		suf[x].push_back(sz[to[x][i]]);
	}
	for(int i=1;i<sav;++i)
		pre[x][i]=pre[x][i]*pre[x][i-1]%mod;
	for(int i=sav-2;i>=0;--i)
		suf[x][i]=suf[x][i]*suf[x][i+1]%mod;
	for(int i=0;i<sav;++i)
		dfs1(to[x][i],(i>0?pre[x][i-1]:1)*(i<sav-1?suf[x][i+1]:1)%mod*num%mod);
	return;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
	n=N;m=M;
	for(int i=1;i<n+m;++i)
		to[P[i]].push_back(i);
	for(int i=1;i<=m;++i)
		b[i]=A[i-1];
	dfs(0);
	dfs1(0,1);
	T.build(1,1,m);
	return;
}

int count_ways(int L, int R) {
	L=L-n+1;
	R=R-n+1;
	T.change(1,1,m,L,R);
  	return T.s[1];
}
//int main() {
//  int N, M, Q;
//  assert(3 == scanf("%d %d %d", &N, &M, &Q));
//  std::vector<int> P(N + M), A(M);
//  for (int i = 0; i < N + M; ++i) {
//    assert(1 == scanf("%d", &P[i]));
//  }
//  for (int j = 0; j < M; ++j) {
//    assert(1 == scanf("%d", &A[j]));
//  }
//  init(N, M, P, A);
//
//  for (int i = 0; i < Q; ++i) {
//    int L, R;
//    assert(2 == scanf("%d %d", &L, &R));
//    printf("%d\n", count_ways(L, R));
//  }
//  return 0;
//}

Compilation message

circuit.cpp: In member function 'void Tree::build(int, int, int)':
circuit.cpp:48:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |   int mid=l+r>>1;
      |           ~^~
circuit.cpp: In member function 'void Tree::change(int, int, int, int, int)':
circuit.cpp:61:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |   int mid=L+R>>1;
      |           ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 8 ms 14544 KB Output is correct
3 Correct 8 ms 14672 KB Output is correct
4 Correct 6 ms 14672 KB Output is correct
5 Correct 9 ms 14672 KB Output is correct
6 Correct 7 ms 14624 KB Output is correct
7 Correct 6 ms 14696 KB Output is correct
8 Correct 7 ms 14672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14496 KB Output is correct
2 Incorrect 8 ms 14544 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 8 ms 14544 KB Output is correct
3 Correct 8 ms 14672 KB Output is correct
4 Correct 6 ms 14672 KB Output is correct
5 Correct 9 ms 14672 KB Output is correct
6 Correct 7 ms 14624 KB Output is correct
7 Correct 6 ms 14696 KB Output is correct
8 Correct 7 ms 14672 KB Output is correct
9 Correct 8 ms 14496 KB Output is correct
10 Incorrect 8 ms 14544 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 501 ms 20420 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 501 ms 20420 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-747097920'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14496 KB Output is correct
2 Incorrect 8 ms 14544 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 8 ms 14544 KB Output is correct
3 Correct 8 ms 14672 KB Output is correct
4 Correct 6 ms 14672 KB Output is correct
5 Correct 9 ms 14672 KB Output is correct
6 Correct 7 ms 14624 KB Output is correct
7 Correct 6 ms 14696 KB Output is correct
8 Correct 7 ms 14672 KB Output is correct
9 Correct 8 ms 14496 KB Output is correct
10 Incorrect 8 ms 14544 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 8 ms 14544 KB Output is correct
3 Correct 8 ms 14672 KB Output is correct
4 Correct 6 ms 14672 KB Output is correct
5 Correct 9 ms 14672 KB Output is correct
6 Correct 7 ms 14624 KB Output is correct
7 Correct 6 ms 14696 KB Output is correct
8 Correct 7 ms 14672 KB Output is correct
9 Correct 8 ms 14496 KB Output is correct
10 Incorrect 8 ms 14544 KB 1st lines differ - on the 1st token, expected: '52130940', found: '-1782334720'
11 Halted 0 ms 0 KB -