Submission #1070551

# Submission time Handle Problem Language Result Execution time Memory
1070551 2024-08-22T15:16:37 Z pan Digital Circuit (IOI22_circuit) C++17
2 / 100
480 ms 16728 KB
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i) 
#define RFOR(i, x, n) for (ll i =x; i>=n; --i) 
using namespace std;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;

ll const mod = 1000002022;


ll n, m;
ll a[200005], child[200005], path[200005], sum[200005];
vector<ll> adj[200005];

// RURQ Segment Tree

struct node{

    int s, e, m; 
    ll val, tot;
    ll lazy; 
    node *l, *r; 
	node (int S, int E)
	{ 
       s = S, e = E, m = (s+e)/2;
       lazy = 0; 
       if(s != e)
       { 
           l = new node(s, m); 
           r = new node(m+1, e);
           val = (l->val + r->val)%mod;
           tot = (l->tot + r->tot)%mod;
       }
       else
       {
		   val = ((a[s])?path[n+s]:0);
		   tot = path[n+s];
	   }
 
    }
 
	void propogate()
	{
       if (lazy==0) return; 
       val = (tot - val + mod)%mod;
       if (s != e){ 
           l->lazy^=lazy;
           r->lazy^=lazy;
       }
       lazy=0; 
    }
	void update(int S, int E)
	{ 
	   propogate();
       if(s==S && e==E){ lazy^=1;}
       else{ 
           if(E <= m) l->update(S, E); 
           else if (m < S) r->update(S, E); 
           else l->update(S, m),r->update(m+1, E);
           l->propogate(),r->propogate();
           val = (l->val + r->val)%mod;
           tot = (l->tot + r->tot)%mod;
       }
    }
    ll query()
    {
		propogate();
		return val;
	}

} *root;

void dfs(ll x)
{
	if (x >= n){ sum[x] = 1; return;}
	sum[x] = child[x];
	for (ll u: adj[x])
	{
		dfs(u);
		sum[x] = (sum[u] * sum[x])%mod;
	}
}

void dfs2(ll x)
{
	if (x >= n) return;
	vector<ll> dp(child[x], 1);
	ll ps = 1;
	for (ll i=0; i<child[x]; ++i)
	{
		dp[i] = (dp[i] * ps)%mod;
		ps = (ps * sum[adj[x][i]])%mod;
	}
	ll ss = 1;
	for (ll i=child[x]-1; i>=0; --i)
	{
		dp[i] = (dp[i] * ss)%mod;
		ss = (ss * sum[adj[x][i]])%mod;
	}
	for (ll i=0; i<child[x]; ++i)
	{
		path[adj[x][i]] = dp[i];
		dfs2(adj[x][i]);
	}
	
}
 

void init(int N, int M, std::vector<int> P, std::vector<int> A)
{
	n = N, m = M;
	for (ll i=0; i<m; ++i) a[i] = A[i];
	for (ll i=0; i<n+m; ++i) child[i] =0;
	for (ll i=1; i<n+m; ++i) {adj[P[i]].pb(i); child[P[i]]++;}
	dfs(0);
	path[0] = 1;
	dfs2(0);
	root = new node(0, m-1);
	

}
int count_ways(int L, int R)
{
	root->update(L-n, R-n);
	return root->query();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 1 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Incorrect 2 ms 10840 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 1 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10892 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Incorrect 2 ms 10840 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 480 ms 16728 KB 1st lines differ - on the 1st token, expected: '431985922', found: '16402'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 480 ms 16728 KB 1st lines differ - on the 1st token, expected: '431985922', found: '16402'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Incorrect 2 ms 10840 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 1 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10892 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Incorrect 2 ms 10840 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 1 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10892 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Incorrect 2 ms 10840 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -