Submission #1061482

# Submission time Handle Problem Language Result Execution time Memory
1061482 2024-08-16T09:46:10 Z ewirlan Digital Circuit (IOI22_circuit) C++17
100 / 100
762 ms 28520 KB
//
#ifndef __SIZEOF_INT128__
  #define __SIZEOF_INT128__
#endif
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template <typename T> using oset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i, p, k) for(int i(p); i < (k); ++i)
#define per(i, p, k) for(int i(p); i > (k); --i)
#define sz(x) (int)(x).size()
#define sc static_cast
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef __int128_t lll;
//#define int ll
template <typename T = int> using par = std::pair <T, T>;
#define fi first
#define se second
#define test int _number_of_tests(in()); while(_number_of_tests--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb emplace_back
struct Timer {
    string name{""};
    time_point<high_resolution_clock> end, start{high_resolution_clock::now()};
    duration<float, std::milli> dur;
    Timer() = default;
    Timer(string nm): name(nm) {}
    ~Timer() {
        end = high_resolution_clock::now(); dur= end - start;
        cout << "@" << name << "> " << dur.count() << " ms" << '\n';
    }
};
template <typename T = int> inline T in()
{
    static T x;
    std::cin >> x;
    return x;
}
std::string yn(bool b)
{
    if(b) return "YES\n";
    else return "NO\n";
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par);
template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek)
{
    for(const auto& i : wek)out << i << ' ';
    return out;
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par)
{
    out << '{'<<par.first<<", "<<par.second<<"}";
    return out;
}
#define show(x) cerr << #x << " = " << x << '\n';
#include "circuit.h"
constexpr int maxn = 1e5 + 3, mod = 1e9 + 2022, pol = 1<<17;
ll mm(ll a, ll b){return (a*b)%mod;}
ll dm(ll a, ll b){return (a+b)%mod;}
ll om(ll a, ll b){return (mod+a-b)%mod;}
vector <int> syn[2*maxn];
int a[maxn*2], z[maxn];
int N, M;
int la(int w)
{
    a[w] = max(1, sz(syn[w]));
    for(auto i: syn[w])a[w] = mm(a[w], la(i));
    return a[w];
}
void lz(int w, ll g)
{
    if(w >= N){
        z[w-N] = g;
        return;
    }
    int ss(sz(syn[w]));
    vector <ll> p(ss+1), s(ss+1);
    p.front() = s.back() = 1;
    rep(i, 0, ss)p[i+1] = mm(a[syn[w][i]], p[i]);
    per(i, ss-1, 0)s[i] = mm(a[syn[w][i]], s[i+1]);
    rep(i, 0, ss)lz(syn[w][i], mm(g, mm(p[i], s[i+1])));
}
constexpr int tres = pol*2+3;
int tre[tres];
bool tre2[tres];
int ful[tres];
void init(int n, int m, vector <int> p, vector <int> c)
{
    N = n;
    M = m;
    rep(i, 1, n+m)syn[p[i]].pb(i);
    la(0);
    lz(0, 1);
    rep(i, 0, m){
        ful[pol+i] = z[i];
        tre[pol+i] = z[i]*c[i];
    }
    per(i, pol-1, 0){
        ful[i] = dm(ful[2*i], ful[2*i+1]);
        tre[i] = dm(tre[2*i], tre[2*i+1]);
    }
}
void flip(int i){
    tre[i] = om(ful[i], tre[i]);
    tre2[i] = !tre2[i];
}
void pyt(int a, int b, int p, int k, int w)
{
    // cerr << p << " - " << k << ": " << ful[w] << ' ' << tre[w] << '\n';
    if(a > k || p > b)return;
    if(a <= p && k <= b){
        // cerr << "switch " << p << ' ' << k << " (" << a << ',' << b << ')' << '\n';
        flip(w);
        return;
    }
    if(tre2[w]){
        tre2[w] = 0;
        flip(w*2);
        flip(w*2+1);
    }
    pyt(a, b, p, (p+k)/2, w*2);
    pyt(a, b, (p+k)/2+1, k, w*2+1);
    tre[w] = dm(tre[w*2], tre[w*2+1]);
}
int count_ways(int a, int b)
{
    pyt(a-N, b-N, 0, pol-1, 1);
    return tre[1];
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8536 KB Output is correct
3 Correct 3 ms 8536 KB Output is correct
4 Correct 3 ms 8536 KB Output is correct
5 Correct 3 ms 8536 KB Output is correct
6 Correct 3 ms 8536 KB Output is correct
7 Correct 3 ms 8624 KB Output is correct
8 Correct 3 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8532 KB Output is correct
3 Correct 3 ms 8536 KB Output is correct
4 Correct 3 ms 8536 KB Output is correct
5 Correct 3 ms 8536 KB Output is correct
6 Correct 3 ms 8536 KB Output is correct
7 Correct 5 ms 8536 KB Output is correct
8 Correct 4 ms 8536 KB Output is correct
9 Correct 4 ms 8536 KB Output is correct
10 Correct 3 ms 8792 KB Output is correct
11 Correct 3 ms 8792 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8536 KB Output is correct
3 Correct 3 ms 8536 KB Output is correct
4 Correct 3 ms 8536 KB Output is correct
5 Correct 3 ms 8536 KB Output is correct
6 Correct 3 ms 8536 KB Output is correct
7 Correct 3 ms 8624 KB Output is correct
8 Correct 3 ms 8536 KB Output is correct
9 Correct 3 ms 8536 KB Output is correct
10 Correct 3 ms 8532 KB Output is correct
11 Correct 3 ms 8536 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
13 Correct 3 ms 8536 KB Output is correct
14 Correct 3 ms 8536 KB Output is correct
15 Correct 5 ms 8536 KB Output is correct
16 Correct 4 ms 8536 KB Output is correct
17 Correct 4 ms 8536 KB Output is correct
18 Correct 3 ms 8792 KB Output is correct
19 Correct 3 ms 8792 KB Output is correct
20 Correct 3 ms 8536 KB Output is correct
21 Correct 3 ms 8536 KB Output is correct
22 Correct 3 ms 8536 KB Output is correct
23 Correct 3 ms 8536 KB Output is correct
24 Correct 4 ms 8536 KB Output is correct
25 Correct 3 ms 8632 KB Output is correct
26 Correct 3 ms 8536 KB Output is correct
27 Correct 3 ms 8536 KB Output is correct
28 Correct 3 ms 8536 KB Output is correct
29 Correct 3 ms 8536 KB Output is correct
30 Correct 3 ms 8536 KB Output is correct
31 Correct 3 ms 8536 KB Output is correct
32 Correct 4 ms 8536 KB Output is correct
33 Correct 3 ms 8536 KB Output is correct
34 Correct 3 ms 8536 KB Output is correct
35 Correct 4 ms 8536 KB Output is correct
36 Correct 3 ms 8792 KB Output is correct
37 Correct 3 ms 8792 KB Output is correct
38 Correct 3 ms 8792 KB Output is correct
39 Correct 3 ms 8536 KB Output is correct
40 Correct 3 ms 8616 KB Output is correct
41 Correct 3 ms 8536 KB Output is correct
42 Correct 3 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 10376 KB Output is correct
2 Correct 673 ms 12120 KB Output is correct
3 Correct 697 ms 12112 KB Output is correct
4 Correct 686 ms 12040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 10376 KB Output is correct
2 Correct 673 ms 12120 KB Output is correct
3 Correct 697 ms 12112 KB Output is correct
4 Correct 686 ms 12040 KB Output is correct
5 Correct 575 ms 10328 KB Output is correct
6 Correct 713 ms 12120 KB Output is correct
7 Correct 660 ms 12120 KB Output is correct
8 Correct 679 ms 12120 KB Output is correct
9 Correct 339 ms 8536 KB Output is correct
10 Correct 697 ms 8792 KB Output is correct
11 Correct 682 ms 8792 KB Output is correct
12 Correct 657 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8532 KB Output is correct
3 Correct 3 ms 8536 KB Output is correct
4 Correct 3 ms 8536 KB Output is correct
5 Correct 3 ms 8536 KB Output is correct
6 Correct 3 ms 8536 KB Output is correct
7 Correct 5 ms 8536 KB Output is correct
8 Correct 4 ms 8536 KB Output is correct
9 Correct 4 ms 8536 KB Output is correct
10 Correct 3 ms 8792 KB Output is correct
11 Correct 3 ms 8792 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
13 Correct 450 ms 10376 KB Output is correct
14 Correct 673 ms 12120 KB Output is correct
15 Correct 697 ms 12112 KB Output is correct
16 Correct 686 ms 12040 KB Output is correct
17 Correct 575 ms 10328 KB Output is correct
18 Correct 713 ms 12120 KB Output is correct
19 Correct 660 ms 12120 KB Output is correct
20 Correct 679 ms 12120 KB Output is correct
21 Correct 339 ms 8536 KB Output is correct
22 Correct 697 ms 8792 KB Output is correct
23 Correct 682 ms 8792 KB Output is correct
24 Correct 657 ms 8792 KB Output is correct
25 Correct 690 ms 13900 KB Output is correct
26 Correct 743 ms 13912 KB Output is correct
27 Correct 725 ms 13900 KB Output is correct
28 Correct 615 ms 13904 KB Output is correct
29 Correct 754 ms 27984 KB Output is correct
30 Correct 658 ms 27984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8536 KB Output is correct
3 Correct 3 ms 8536 KB Output is correct
4 Correct 3 ms 8536 KB Output is correct
5 Correct 3 ms 8536 KB Output is correct
6 Correct 3 ms 8536 KB Output is correct
7 Correct 3 ms 8624 KB Output is correct
8 Correct 3 ms 8536 KB Output is correct
9 Correct 3 ms 8536 KB Output is correct
10 Correct 3 ms 8532 KB Output is correct
11 Correct 3 ms 8536 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
13 Correct 3 ms 8536 KB Output is correct
14 Correct 3 ms 8536 KB Output is correct
15 Correct 5 ms 8536 KB Output is correct
16 Correct 4 ms 8536 KB Output is correct
17 Correct 4 ms 8536 KB Output is correct
18 Correct 3 ms 8792 KB Output is correct
19 Correct 3 ms 8792 KB Output is correct
20 Correct 3 ms 8536 KB Output is correct
21 Correct 3 ms 8536 KB Output is correct
22 Correct 3 ms 8536 KB Output is correct
23 Correct 3 ms 8536 KB Output is correct
24 Correct 4 ms 8536 KB Output is correct
25 Correct 3 ms 8632 KB Output is correct
26 Correct 3 ms 8536 KB Output is correct
27 Correct 3 ms 8536 KB Output is correct
28 Correct 3 ms 8536 KB Output is correct
29 Correct 3 ms 8536 KB Output is correct
30 Correct 3 ms 8536 KB Output is correct
31 Correct 3 ms 8536 KB Output is correct
32 Correct 4 ms 8536 KB Output is correct
33 Correct 3 ms 8536 KB Output is correct
34 Correct 3 ms 8536 KB Output is correct
35 Correct 4 ms 8536 KB Output is correct
36 Correct 3 ms 8792 KB Output is correct
37 Correct 3 ms 8792 KB Output is correct
38 Correct 3 ms 8792 KB Output is correct
39 Correct 3 ms 8536 KB Output is correct
40 Correct 3 ms 8616 KB Output is correct
41 Correct 3 ms 8536 KB Output is correct
42 Correct 3 ms 8536 KB Output is correct
43 Correct 497 ms 8536 KB Output is correct
44 Correct 676 ms 8792 KB Output is correct
45 Correct 632 ms 8536 KB Output is correct
46 Correct 612 ms 8792 KB Output is correct
47 Correct 682 ms 8792 KB Output is correct
48 Correct 639 ms 8792 KB Output is correct
49 Correct 626 ms 8792 KB Output is correct
50 Correct 675 ms 8744 KB Output is correct
51 Correct 609 ms 8792 KB Output is correct
52 Correct 615 ms 8792 KB Output is correct
53 Correct 636 ms 9304 KB Output is correct
54 Correct 670 ms 8792 KB Output is correct
55 Correct 709 ms 8536 KB Output is correct
56 Correct 654 ms 8536 KB Output is correct
57 Correct 675 ms 8536 KB Output is correct
58 Correct 681 ms 9560 KB Output is correct
59 Correct 639 ms 9560 KB Output is correct
60 Correct 666 ms 9560 KB Output is correct
61 Correct 623 ms 8792 KB Output is correct
62 Correct 661 ms 8536 KB Output is correct
63 Correct 667 ms 8536 KB Output is correct
64 Correct 656 ms 8536 KB Output is correct
65 Correct 336 ms 8536 KB Output is correct
66 Correct 682 ms 8792 KB Output is correct
67 Correct 653 ms 8792 KB Output is correct
68 Correct 695 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8536 KB Output is correct
3 Correct 3 ms 8536 KB Output is correct
4 Correct 3 ms 8536 KB Output is correct
5 Correct 3 ms 8536 KB Output is correct
6 Correct 3 ms 8536 KB Output is correct
7 Correct 3 ms 8624 KB Output is correct
8 Correct 3 ms 8536 KB Output is correct
9 Correct 3 ms 8536 KB Output is correct
10 Correct 3 ms 8532 KB Output is correct
11 Correct 3 ms 8536 KB Output is correct
12 Correct 3 ms 8536 KB Output is correct
13 Correct 3 ms 8536 KB Output is correct
14 Correct 3 ms 8536 KB Output is correct
15 Correct 5 ms 8536 KB Output is correct
16 Correct 4 ms 8536 KB Output is correct
17 Correct 4 ms 8536 KB Output is correct
18 Correct 3 ms 8792 KB Output is correct
19 Correct 3 ms 8792 KB Output is correct
20 Correct 3 ms 8536 KB Output is correct
21 Correct 3 ms 8536 KB Output is correct
22 Correct 3 ms 8536 KB Output is correct
23 Correct 3 ms 8536 KB Output is correct
24 Correct 4 ms 8536 KB Output is correct
25 Correct 3 ms 8632 KB Output is correct
26 Correct 3 ms 8536 KB Output is correct
27 Correct 3 ms 8536 KB Output is correct
28 Correct 3 ms 8536 KB Output is correct
29 Correct 3 ms 8536 KB Output is correct
30 Correct 3 ms 8536 KB Output is correct
31 Correct 3 ms 8536 KB Output is correct
32 Correct 4 ms 8536 KB Output is correct
33 Correct 3 ms 8536 KB Output is correct
34 Correct 3 ms 8536 KB Output is correct
35 Correct 4 ms 8536 KB Output is correct
36 Correct 3 ms 8792 KB Output is correct
37 Correct 3 ms 8792 KB Output is correct
38 Correct 3 ms 8792 KB Output is correct
39 Correct 3 ms 8536 KB Output is correct
40 Correct 3 ms 8616 KB Output is correct
41 Correct 3 ms 8536 KB Output is correct
42 Correct 3 ms 8536 KB Output is correct
43 Correct 450 ms 10376 KB Output is correct
44 Correct 673 ms 12120 KB Output is correct
45 Correct 697 ms 12112 KB Output is correct
46 Correct 686 ms 12040 KB Output is correct
47 Correct 575 ms 10328 KB Output is correct
48 Correct 713 ms 12120 KB Output is correct
49 Correct 660 ms 12120 KB Output is correct
50 Correct 679 ms 12120 KB Output is correct
51 Correct 339 ms 8536 KB Output is correct
52 Correct 697 ms 8792 KB Output is correct
53 Correct 682 ms 8792 KB Output is correct
54 Correct 657 ms 8792 KB Output is correct
55 Correct 690 ms 13900 KB Output is correct
56 Correct 743 ms 13912 KB Output is correct
57 Correct 725 ms 13900 KB Output is correct
58 Correct 615 ms 13904 KB Output is correct
59 Correct 754 ms 27984 KB Output is correct
60 Correct 658 ms 27984 KB Output is correct
61 Correct 497 ms 8536 KB Output is correct
62 Correct 676 ms 8792 KB Output is correct
63 Correct 632 ms 8536 KB Output is correct
64 Correct 612 ms 8792 KB Output is correct
65 Correct 682 ms 8792 KB Output is correct
66 Correct 639 ms 8792 KB Output is correct
67 Correct 626 ms 8792 KB Output is correct
68 Correct 675 ms 8744 KB Output is correct
69 Correct 609 ms 8792 KB Output is correct
70 Correct 615 ms 8792 KB Output is correct
71 Correct 636 ms 9304 KB Output is correct
72 Correct 670 ms 8792 KB Output is correct
73 Correct 709 ms 8536 KB Output is correct
74 Correct 654 ms 8536 KB Output is correct
75 Correct 675 ms 8536 KB Output is correct
76 Correct 681 ms 9560 KB Output is correct
77 Correct 639 ms 9560 KB Output is correct
78 Correct 666 ms 9560 KB Output is correct
79 Correct 623 ms 8792 KB Output is correct
80 Correct 661 ms 8536 KB Output is correct
81 Correct 667 ms 8536 KB Output is correct
82 Correct 656 ms 8536 KB Output is correct
83 Correct 336 ms 8536 KB Output is correct
84 Correct 682 ms 8792 KB Output is correct
85 Correct 653 ms 8792 KB Output is correct
86 Correct 695 ms 8792 KB Output is correct
87 Correct 3 ms 8536 KB Output is correct
88 Correct 434 ms 13532 KB Output is correct
89 Correct 709 ms 12368 KB Output is correct
90 Correct 658 ms 12120 KB Output is correct
91 Correct 715 ms 14160 KB Output is correct
92 Correct 712 ms 14160 KB Output is correct
93 Correct 747 ms 14160 KB Output is correct
94 Correct 737 ms 14160 KB Output is correct
95 Correct 680 ms 14160 KB Output is correct
96 Correct 678 ms 10672 KB Output is correct
97 Correct 675 ms 10672 KB Output is correct
98 Correct 656 ms 26448 KB Output is correct
99 Correct 718 ms 13904 KB Output is correct
100 Correct 747 ms 11968 KB Output is correct
101 Correct 657 ms 11608 KB Output is correct
102 Correct 667 ms 10584 KB Output is correct
103 Correct 748 ms 27984 KB Output is correct
104 Correct 762 ms 28520 KB Output is correct
105 Correct 751 ms 28476 KB Output is correct
106 Correct 556 ms 15436 KB Output is correct
107 Correct 616 ms 11104 KB Output is correct
108 Correct 626 ms 11096 KB Output is correct
109 Correct 628 ms 10756 KB Output is correct