답안 #627768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627768 2022-08-12T22:38:25 Z peti1234 디지털 회로 (IOI22_circuit) C++17
100 / 100
1117 ms 39048 KB
#include <bits/stdc++.h>

using namespace std;
//#include "circuit.h"
const int c=500005;
int n, m;
const long long mod=1000002022, phimod=497758632;
int bal[c], jobb[c];
long long ert[c], sum[c], sum2[c], flip[c], po2[c], po223[c], rem[c];
vector<int> sz[c], aa;
long long po(long long a, long long p) {
    long long ans=1;
    while (p) {
        if (p%2) ans=ans*a%mod;
        a=a*a%mod;
        p/=2;
    }
    return ans;
}
long long oszt(long long a) {
    assert(__gcd(mod, a)==1);
    return po(a, phimod-1);
}
void calc(int a) {
    int x=2*a, y=2*a+1;
    sum[a]=(sum[x]+sum[y])%mod;
    sum2[a]=(sum2[x]+sum2[y])%mod;
    if (flip[a]) {
        swap(sum[a], sum2[a]);
    }
}
void seg_tree_init(int m) {
    int po=1;
    while (po<m) {
        po*=2;
    }
    for (int i=po; i<2*po; i++) {
        bal[i]=i-po, jobb[i]=i-po;
        if (i-po<m) {
            sum[i]=ert[i-po+n], sum2[i]=0;
            if (!aa[i-po]) flip[i]=1, swap(sum[i], sum2[i]);
            //cout << "fontos " << i << " " << sum[i] << " " << sum2[i] << "\n";
        }
    }
    for (int i=po-1; i>=1; i--) {
        bal[i]=bal[2*i], jobb[i]=jobb[2*i+1];
        calc(i);
        //cout << "kozep " << i << " " << sum[i] << " " << sum2[i] << "\n";
    }
}
int h(int a, int l, int r) {
    if (bal[a]>r || jobb[a]<l) return 0;
    if (l<=bal[a] && jobb[a]<=r) return 2;
    return 1;
}
void add(int a, int l, int r) {
    int s=h(a, l, r);
    if (s==0) return;
    if (s==2) {
        flip[a]=1-flip[a];
        swap(sum[a], sum2[a]);
        return;
    }
    int x=2*a, y=2*a+1;
    add(x, l, r), add(y, l, r);
    calc(a);
}
void dfs(int a) {
    int si=sz[a].size();
    long long p2=po2[a], p223=po223[a], val=rem[a];
    ert[a]=po(2, p2)*po(223, p223)%mod*val%mod;
    //cout << "dfs " << a << " " << ert[a] << "\n";
    if (si==0) return;
    while (si%2==0) p2--, si/=2;
    while (si%223==0) p223--, si/=223;
    val=val*oszt(si)%mod;
    for (auto x:sz[a]) {
        po2[x]=p2, po223[x]=p223, rem[x]=val;
        dfs(x);
    }
}
void init(int N, int M, vector<int> P, vector<int> A) {
    n=N, m=M;
    aa=A;
    for (int i=1; i<n+m; i++) {
        sz[P[i]].push_back(i);
    }
    rem[0]=1;
    for (int i=0; i<n; i++) {
        int si=sz[i].size();
        while (si%2==0) po2[0]++, si/=2;
        while (si%223==0) po223[0]++, si/=223;
        rem[0]=rem[0]*si%mod;
    }
    dfs(0);
    seg_tree_init(m);
}

int count_ways(int L, int R) {
    L-=n, R-=n;
    add(1, L, R);
    return sum[1];
}
/*
int main()
{
    int a, b;
    vector<int> x, y;
    cin >> a >> b;
    for (int i=0; i<a+b; i++) {
        int s;
        cin >> s;
        x.push_back(s);
    }
    for (int i=0; i<b; i++) {
        int s;
        cin >> s;
        y.push_back(s);
    }
    init(a, b, x, y);
    int q;
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        cout << count_ways(l, r) << "\n";
    }
    return 0;
}
*/
/*
3 4
-1 0 1 2 1 1 0
1 0 1 0
2
3 4
4 5
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12112 KB Output is correct
2 Correct 6 ms 12112 KB Output is correct
3 Correct 6 ms 12112 KB Output is correct
4 Correct 7 ms 12184 KB Output is correct
5 Correct 7 ms 12228 KB Output is correct
6 Correct 6 ms 12112 KB Output is correct
7 Correct 6 ms 12112 KB Output is correct
8 Correct 6 ms 12112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12112 KB Output is correct
2 Correct 6 ms 12036 KB Output is correct
3 Correct 7 ms 12112 KB Output is correct
4 Correct 8 ms 12112 KB Output is correct
5 Correct 7 ms 12112 KB Output is correct
6 Correct 7 ms 12240 KB Output is correct
7 Correct 7 ms 12240 KB Output is correct
8 Correct 7 ms 12240 KB Output is correct
9 Correct 7 ms 12240 KB Output is correct
10 Correct 7 ms 12368 KB Output is correct
11 Correct 8 ms 12368 KB Output is correct
12 Correct 7 ms 12240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12112 KB Output is correct
2 Correct 6 ms 12112 KB Output is correct
3 Correct 6 ms 12112 KB Output is correct
4 Correct 7 ms 12184 KB Output is correct
5 Correct 7 ms 12228 KB Output is correct
6 Correct 6 ms 12112 KB Output is correct
7 Correct 6 ms 12112 KB Output is correct
8 Correct 6 ms 12112 KB Output is correct
9 Correct 7 ms 12112 KB Output is correct
10 Correct 6 ms 12036 KB Output is correct
11 Correct 7 ms 12112 KB Output is correct
12 Correct 8 ms 12112 KB Output is correct
13 Correct 7 ms 12112 KB Output is correct
14 Correct 7 ms 12240 KB Output is correct
15 Correct 7 ms 12240 KB Output is correct
16 Correct 7 ms 12240 KB Output is correct
17 Correct 7 ms 12240 KB Output is correct
18 Correct 7 ms 12368 KB Output is correct
19 Correct 8 ms 12368 KB Output is correct
20 Correct 7 ms 12240 KB Output is correct
21 Correct 7 ms 12240 KB Output is correct
22 Correct 7 ms 12112 KB Output is correct
23 Correct 8 ms 12240 KB Output is correct
24 Correct 8 ms 12240 KB Output is correct
25 Correct 7 ms 12240 KB Output is correct
26 Correct 8 ms 12228 KB Output is correct
27 Correct 9 ms 12228 KB Output is correct
28 Correct 7 ms 12232 KB Output is correct
29 Correct 7 ms 12112 KB Output is correct
30 Correct 7 ms 12112 KB Output is correct
31 Correct 7 ms 12240 KB Output is correct
32 Correct 7 ms 12240 KB Output is correct
33 Correct 7 ms 12220 KB Output is correct
34 Correct 7 ms 12240 KB Output is correct
35 Correct 6 ms 12112 KB Output is correct
36 Correct 7 ms 12368 KB Output is correct
37 Correct 7 ms 12368 KB Output is correct
38 Correct 7 ms 12368 KB Output is correct
39 Correct 7 ms 12112 KB Output is correct
40 Correct 6 ms 12240 KB Output is correct
41 Correct 7 ms 12168 KB Output is correct
42 Correct 8 ms 12112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 528 ms 17892 KB Output is correct
2 Correct 907 ms 23540 KB Output is correct
3 Correct 740 ms 23112 KB Output is correct
4 Correct 783 ms 23556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 528 ms 17892 KB Output is correct
2 Correct 907 ms 23540 KB Output is correct
3 Correct 740 ms 23112 KB Output is correct
4 Correct 783 ms 23556 KB Output is correct
5 Correct 572 ms 17852 KB Output is correct
6 Correct 733 ms 23556 KB Output is correct
7 Correct 876 ms 23576 KB Output is correct
8 Correct 866 ms 23556 KB Output is correct
9 Correct 498 ms 12368 KB Output is correct
10 Correct 864 ms 12856 KB Output is correct
11 Correct 766 ms 12756 KB Output is correct
12 Correct 768 ms 12752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12112 KB Output is correct
2 Correct 6 ms 12036 KB Output is correct
3 Correct 7 ms 12112 KB Output is correct
4 Correct 8 ms 12112 KB Output is correct
5 Correct 7 ms 12112 KB Output is correct
6 Correct 7 ms 12240 KB Output is correct
7 Correct 7 ms 12240 KB Output is correct
8 Correct 7 ms 12240 KB Output is correct
9 Correct 7 ms 12240 KB Output is correct
10 Correct 7 ms 12368 KB Output is correct
11 Correct 8 ms 12368 KB Output is correct
12 Correct 7 ms 12240 KB Output is correct
13 Correct 528 ms 17892 KB Output is correct
14 Correct 907 ms 23540 KB Output is correct
15 Correct 740 ms 23112 KB Output is correct
16 Correct 783 ms 23556 KB Output is correct
17 Correct 572 ms 17852 KB Output is correct
18 Correct 733 ms 23556 KB Output is correct
19 Correct 876 ms 23576 KB Output is correct
20 Correct 866 ms 23556 KB Output is correct
21 Correct 498 ms 12368 KB Output is correct
22 Correct 864 ms 12856 KB Output is correct
23 Correct 766 ms 12756 KB Output is correct
24 Correct 768 ms 12752 KB Output is correct
25 Correct 815 ms 30408 KB Output is correct
26 Correct 834 ms 30588 KB Output is correct
27 Correct 1058 ms 30628 KB Output is correct
28 Correct 825 ms 30608 KB Output is correct
29 Correct 954 ms 38432 KB Output is correct
30 Correct 839 ms 38400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12112 KB Output is correct
2 Correct 6 ms 12112 KB Output is correct
3 Correct 6 ms 12112 KB Output is correct
4 Correct 7 ms 12184 KB Output is correct
5 Correct 7 ms 12228 KB Output is correct
6 Correct 6 ms 12112 KB Output is correct
7 Correct 6 ms 12112 KB Output is correct
8 Correct 6 ms 12112 KB Output is correct
9 Correct 7 ms 12112 KB Output is correct
10 Correct 6 ms 12036 KB Output is correct
11 Correct 7 ms 12112 KB Output is correct
12 Correct 8 ms 12112 KB Output is correct
13 Correct 7 ms 12112 KB Output is correct
14 Correct 7 ms 12240 KB Output is correct
15 Correct 7 ms 12240 KB Output is correct
16 Correct 7 ms 12240 KB Output is correct
17 Correct 7 ms 12240 KB Output is correct
18 Correct 7 ms 12368 KB Output is correct
19 Correct 8 ms 12368 KB Output is correct
20 Correct 7 ms 12240 KB Output is correct
21 Correct 7 ms 12240 KB Output is correct
22 Correct 7 ms 12112 KB Output is correct
23 Correct 8 ms 12240 KB Output is correct
24 Correct 8 ms 12240 KB Output is correct
25 Correct 7 ms 12240 KB Output is correct
26 Correct 8 ms 12228 KB Output is correct
27 Correct 9 ms 12228 KB Output is correct
28 Correct 7 ms 12232 KB Output is correct
29 Correct 7 ms 12112 KB Output is correct
30 Correct 7 ms 12112 KB Output is correct
31 Correct 7 ms 12240 KB Output is correct
32 Correct 7 ms 12240 KB Output is correct
33 Correct 7 ms 12220 KB Output is correct
34 Correct 7 ms 12240 KB Output is correct
35 Correct 6 ms 12112 KB Output is correct
36 Correct 7 ms 12368 KB Output is correct
37 Correct 7 ms 12368 KB Output is correct
38 Correct 7 ms 12368 KB Output is correct
39 Correct 7 ms 12112 KB Output is correct
40 Correct 6 ms 12240 KB Output is correct
41 Correct 7 ms 12168 KB Output is correct
42 Correct 8 ms 12112 KB Output is correct
43 Correct 576 ms 12624 KB Output is correct
44 Correct 809 ms 12624 KB Output is correct
45 Correct 842 ms 12624 KB Output is correct
46 Correct 851 ms 13008 KB Output is correct
47 Correct 772 ms 13136 KB Output is correct
48 Correct 784 ms 13136 KB Output is correct
49 Correct 895 ms 13264 KB Output is correct
50 Correct 844 ms 13008 KB Output is correct
51 Correct 870 ms 12752 KB Output is correct
52 Correct 874 ms 12752 KB Output is correct
53 Correct 756 ms 12752 KB Output is correct
54 Correct 624 ms 13144 KB Output is correct
55 Correct 877 ms 12880 KB Output is correct
56 Correct 805 ms 12880 KB Output is correct
57 Correct 829 ms 12772 KB Output is correct
58 Correct 856 ms 13512 KB Output is correct
59 Correct 730 ms 13572 KB Output is correct
60 Correct 851 ms 13544 KB Output is correct
61 Correct 884 ms 12752 KB Output is correct
62 Correct 892 ms 12624 KB Output is correct
63 Correct 896 ms 12624 KB Output is correct
64 Correct 833 ms 12804 KB Output is correct
65 Correct 356 ms 12488 KB Output is correct
66 Correct 748 ms 12752 KB Output is correct
67 Correct 599 ms 12764 KB Output is correct
68 Correct 832 ms 12840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12112 KB Output is correct
2 Correct 6 ms 12112 KB Output is correct
3 Correct 6 ms 12112 KB Output is correct
4 Correct 7 ms 12184 KB Output is correct
5 Correct 7 ms 12228 KB Output is correct
6 Correct 6 ms 12112 KB Output is correct
7 Correct 6 ms 12112 KB Output is correct
8 Correct 6 ms 12112 KB Output is correct
9 Correct 7 ms 12112 KB Output is correct
10 Correct 6 ms 12036 KB Output is correct
11 Correct 7 ms 12112 KB Output is correct
12 Correct 8 ms 12112 KB Output is correct
13 Correct 7 ms 12112 KB Output is correct
14 Correct 7 ms 12240 KB Output is correct
15 Correct 7 ms 12240 KB Output is correct
16 Correct 7 ms 12240 KB Output is correct
17 Correct 7 ms 12240 KB Output is correct
18 Correct 7 ms 12368 KB Output is correct
19 Correct 8 ms 12368 KB Output is correct
20 Correct 7 ms 12240 KB Output is correct
21 Correct 7 ms 12240 KB Output is correct
22 Correct 7 ms 12112 KB Output is correct
23 Correct 8 ms 12240 KB Output is correct
24 Correct 8 ms 12240 KB Output is correct
25 Correct 7 ms 12240 KB Output is correct
26 Correct 8 ms 12228 KB Output is correct
27 Correct 9 ms 12228 KB Output is correct
28 Correct 7 ms 12232 KB Output is correct
29 Correct 7 ms 12112 KB Output is correct
30 Correct 7 ms 12112 KB Output is correct
31 Correct 7 ms 12240 KB Output is correct
32 Correct 7 ms 12240 KB Output is correct
33 Correct 7 ms 12220 KB Output is correct
34 Correct 7 ms 12240 KB Output is correct
35 Correct 6 ms 12112 KB Output is correct
36 Correct 7 ms 12368 KB Output is correct
37 Correct 7 ms 12368 KB Output is correct
38 Correct 7 ms 12368 KB Output is correct
39 Correct 7 ms 12112 KB Output is correct
40 Correct 6 ms 12240 KB Output is correct
41 Correct 7 ms 12168 KB Output is correct
42 Correct 8 ms 12112 KB Output is correct
43 Correct 528 ms 17892 KB Output is correct
44 Correct 907 ms 23540 KB Output is correct
45 Correct 740 ms 23112 KB Output is correct
46 Correct 783 ms 23556 KB Output is correct
47 Correct 572 ms 17852 KB Output is correct
48 Correct 733 ms 23556 KB Output is correct
49 Correct 876 ms 23576 KB Output is correct
50 Correct 866 ms 23556 KB Output is correct
51 Correct 498 ms 12368 KB Output is correct
52 Correct 864 ms 12856 KB Output is correct
53 Correct 766 ms 12756 KB Output is correct
54 Correct 768 ms 12752 KB Output is correct
55 Correct 815 ms 30408 KB Output is correct
56 Correct 834 ms 30588 KB Output is correct
57 Correct 1058 ms 30628 KB Output is correct
58 Correct 825 ms 30608 KB Output is correct
59 Correct 954 ms 38432 KB Output is correct
60 Correct 839 ms 38400 KB Output is correct
61 Correct 576 ms 12624 KB Output is correct
62 Correct 809 ms 12624 KB Output is correct
63 Correct 842 ms 12624 KB Output is correct
64 Correct 851 ms 13008 KB Output is correct
65 Correct 772 ms 13136 KB Output is correct
66 Correct 784 ms 13136 KB Output is correct
67 Correct 895 ms 13264 KB Output is correct
68 Correct 844 ms 13008 KB Output is correct
69 Correct 870 ms 12752 KB Output is correct
70 Correct 874 ms 12752 KB Output is correct
71 Correct 756 ms 12752 KB Output is correct
72 Correct 624 ms 13144 KB Output is correct
73 Correct 877 ms 12880 KB Output is correct
74 Correct 805 ms 12880 KB Output is correct
75 Correct 829 ms 12772 KB Output is correct
76 Correct 856 ms 13512 KB Output is correct
77 Correct 730 ms 13572 KB Output is correct
78 Correct 851 ms 13544 KB Output is correct
79 Correct 884 ms 12752 KB Output is correct
80 Correct 892 ms 12624 KB Output is correct
81 Correct 896 ms 12624 KB Output is correct
82 Correct 833 ms 12804 KB Output is correct
83 Correct 356 ms 12488 KB Output is correct
84 Correct 748 ms 12752 KB Output is correct
85 Correct 599 ms 12764 KB Output is correct
86 Correct 832 ms 12840 KB Output is correct
87 Correct 6 ms 12112 KB Output is correct
88 Correct 486 ms 28940 KB Output is correct
89 Correct 1008 ms 23228 KB Output is correct
90 Correct 975 ms 23124 KB Output is correct
91 Correct 750 ms 30724 KB Output is correct
92 Correct 983 ms 30468 KB Output is correct
93 Correct 1117 ms 30808 KB Output is correct
94 Correct 1040 ms 30752 KB Output is correct
95 Correct 958 ms 30832 KB Output is correct
96 Correct 848 ms 24128 KB Output is correct
97 Correct 931 ms 24204 KB Output is correct
98 Correct 928 ms 26952 KB Output is correct
99 Correct 994 ms 30624 KB Output is correct
100 Correct 921 ms 27144 KB Output is correct
101 Correct 986 ms 25860 KB Output is correct
102 Correct 954 ms 24260 KB Output is correct
103 Correct 894 ms 38472 KB Output is correct
104 Correct 949 ms 39048 KB Output is correct
105 Correct 869 ms 39048 KB Output is correct
106 Correct 853 ms 24388 KB Output is correct
107 Correct 1024 ms 24000 KB Output is correct
108 Correct 967 ms 24160 KB Output is correct
109 Correct 938 ms 24256 KB Output is correct