답안 #682157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682157 2023-01-16T01:59:07 Z vjudge1 Intergalactic ship (IZhO19_xorsum) C++17
100 / 100
1356 ms 15220 KB
#include<bits/stdc++.h>
using namespace std;
const long long du=1e9+7;
const int maxn=1e3+9;
const int maxq=1e5+9;
long long a[maxn];
int l[maxq],r[maxq],x[maxq];
int b[maxn][maxn][3];
long long pw[maxq];
void update(int t,int x1,int y1,int x2,int y2){
if (x1>x2||y1>y2)return;
b[x1][y1][t]++;
b[x2+1][y1][t]--;
b[x1][y2+1][t]--;
b[x2+1][y2+1][t]++;
}
long long yoonjung(int p,int q){
if (p==0)return (q==0);
return (du+1)/2;
}
signed main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(nullptr);
	//freopen("usaco.INP","r",stdin);
	//freopen("usaco.ANS","w",stdout);
    int n;
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
    }
    int q;
    cin>>q;
    for (int i=1;i<=q;i++){
        cin>>l[i]>>r[i]>>x[i];
    }
    pw[0]=1;
    for (int i=1;i<=100000;i++)pw[i]=(pw[i-1]*2)%du;
    long long ans=0;
    for (int bit1=0;bit1<7;bit1++){
        for (int bit2=0;bit2<7;bit2++){
        for (int i=1;i<=n;i++){
            for (int j=1;j<=n;j++){
                for (int k=0;k<3;k++){
                    b[i][j][k]=0;
                }
            }
        }
        for (int i=1;i<=q;i++){
            if ((x[i]>>bit1&1)&&(x[i]>>bit2&1)){
                update(0,l[i],l[i],r[i],r[i]);
                update(1,l[i],r[i]+1,r[i],n);
                update(2,1,l[i],l[i]-1,r[i]);
            }
            else if ((x[i]>>bit1&1)&&!(x[i]>>bit2&1)){
                update(1,l[i],l[i],r[i],n);
            }
            else if (!(x[i]>>bit1&1)&&(x[i]>>bit2&1)){
                update(2,1,l[i],r[i],r[i]);
            }
        }
        for (int j=1;j<=n;j++){
            for (int i=1;i<=n;i++){
                for (int k=0;k<3;k++){
                    b[i][j][k]+=b[i-1][j][k];
                }
            }
        }
        for (int i=1;i<=n;i++){
            for (int j=1;j<=n;j++){
                for (int k=0;k<3;k++){
                    b[i][j][k]+=b[i][j-1][k];
                }
            }
        }
        for (int i=1;i<=n;i++){
            for (int j=i;j<=n;j++){
                long long bonus=(1<<bit1)*(1<<bit2)*i*(n-j+1);
                if (i!=j)bonus=(bonus*2)%du;
                for (int t1=0;t1<2;t1++){
                    for (int t2=0;t2<2;t2++){
                        for (int t3=0;t3<2;t3++){
                            int p1=((a[i]>>bit1&1)^t1^t2),p2=((a[j]>>bit2&1)^t1^t3);
                            if ((p1==1)&&(p2==1)){
                                long long newval=(bonus*pw[q])%du;
                                newval=(newval*yoonjung(b[i][j][0],t1))%du;
                                newval=(newval*yoonjung(b[i][j][1],t2))%du;
                                newval=(newval*yoonjung(b[i][j][2],t3))%du;
                                ans=(ans+newval)%du;
                            }
                        }
                    }
                }
            }
        }
        }
    }
    cout<<ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1092 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 2 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1092 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 2 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 13 ms 1632 KB Output is correct
7 Correct 13 ms 1608 KB Output is correct
8 Correct 12 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 3620 KB Output is correct
2 Correct 23 ms 1820 KB Output is correct
3 Correct 13 ms 1652 KB Output is correct
4 Correct 13 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1229 ms 12976 KB Output is correct
2 Correct 1190 ms 12984 KB Output is correct
3 Correct 1175 ms 13060 KB Output is correct
4 Correct 1167 ms 12964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1236 KB Output is correct
2 Correct 2 ms 1220 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1236 KB Output is correct
2 Correct 2 ms 1220 KB Output is correct
3 Correct 2 ms 1236 KB Output is correct
4 Correct 5 ms 1236 KB Output is correct
5 Correct 6 ms 1236 KB Output is correct
6 Correct 6 ms 1352 KB Output is correct
7 Correct 5 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1092 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 2 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 13 ms 1632 KB Output is correct
7 Correct 13 ms 1608 KB Output is correct
8 Correct 12 ms 1620 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1220 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 14 ms 1620 KB Output is correct
13 Correct 15 ms 1640 KB Output is correct
14 Correct 18 ms 1628 KB Output is correct
15 Correct 15 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1092 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 2 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 13 ms 1632 KB Output is correct
7 Correct 13 ms 1608 KB Output is correct
8 Correct 12 ms 1620 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1220 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 5 ms 1236 KB Output is correct
13 Correct 6 ms 1236 KB Output is correct
14 Correct 6 ms 1352 KB Output is correct
15 Correct 5 ms 1356 KB Output is correct
16 Correct 14 ms 1620 KB Output is correct
17 Correct 15 ms 1640 KB Output is correct
18 Correct 18 ms 1628 KB Output is correct
19 Correct 15 ms 1644 KB Output is correct
20 Correct 384 ms 8296 KB Output is correct
21 Correct 381 ms 8304 KB Output is correct
22 Correct 320 ms 8200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1092 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 2 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 13 ms 1632 KB Output is correct
7 Correct 13 ms 1608 KB Output is correct
8 Correct 12 ms 1620 KB Output is correct
9 Correct 87 ms 3620 KB Output is correct
10 Correct 23 ms 1820 KB Output is correct
11 Correct 13 ms 1652 KB Output is correct
12 Correct 13 ms 1620 KB Output is correct
13 Correct 1229 ms 12976 KB Output is correct
14 Correct 1190 ms 12984 KB Output is correct
15 Correct 1175 ms 13060 KB Output is correct
16 Correct 1167 ms 12964 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 2 ms 1220 KB Output is correct
19 Correct 2 ms 1236 KB Output is correct
20 Correct 5 ms 1236 KB Output is correct
21 Correct 6 ms 1236 KB Output is correct
22 Correct 6 ms 1352 KB Output is correct
23 Correct 5 ms 1356 KB Output is correct
24 Correct 14 ms 1620 KB Output is correct
25 Correct 15 ms 1640 KB Output is correct
26 Correct 18 ms 1628 KB Output is correct
27 Correct 15 ms 1644 KB Output is correct
28 Correct 384 ms 8296 KB Output is correct
29 Correct 381 ms 8304 KB Output is correct
30 Correct 320 ms 8200 KB Output is correct
31 Correct 1356 ms 15220 KB Output is correct
32 Correct 1269 ms 15196 KB Output is correct
33 Correct 1207 ms 15116 KB Output is correct
34 Correct 1287 ms 15012 KB Output is correct
35 Correct 1227 ms 15008 KB Output is correct
36 Correct 1222 ms 14988 KB Output is correct