답안 #287024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287024 2020-08-31T09:13:13 Z oolimry Intergalactic ship (IZhO19_xorsum) C++14
100 / 100
821 ms 199660 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
using namespace std;
typedef long long lint;
typedef pair<int,int> ii;

int arr[1005];
struct query{ int l, r, x; };

vector<query> queries;

bool in(int x, int bit){
	return ((x & (1 << bit)) != 0);
}

lint mod = 1000000007;
lint two[500005];
lint ans = 0;

inline lint odd(int N){
	if(N == 0) return -10234523;
	else return N-1;
}
inline lint even(int N){
	if(N == 0) return 0;
	else return N-1;
}
inline void fix(lint &x){
	x %= mod;
}

int cnt[7][7][1005][1005];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	lint n; cin >> n;
	for(int i = 1;i <= n;i++) cin >> arr[i];
	
	int Q; cin >> Q;
	for(int q = 0;q < Q;q++){
		queries.push_back({});
		query &QQ = queries.back();
		cin >> QQ.l >> QQ.r >> QQ.x;
	}
	
	for(query q : queries){
		int l = q.l, r = q.r, x = q.x;
		for(int bit = 0;bit < 7;bit++){
			for(int bit2 = 0;bit2 < 7;bit2++){	
				if(!in(x, bit) || !in(x, bit2)) continue;
				cnt[bit][bit2][l][r]++;
			}
		}
	}
	
	for(int bit = 0;bit < 7;bit++){
		for(int bit2 = 0;bit2 < 7;bit2++){
			for(int l = 1;l <= n;l++){
				for(int r = n;r >= l;r--){
					cnt[bit][bit2][l][r] += cnt[bit][bit2][l-1][r];
					cnt[bit][bit2][l][r] += cnt[bit][bit2][l][r+1];
					cnt[bit][bit2][l][r] -= cnt[bit][bit2][l-1][r+1];
				}
			}
		}
	}

	two[0] = 1;
	for(int i = 1;i <= 500004;i++) two[i] = (two[i-1] * 2) % mod;

	for(lint a = 1;a <= n;a++){
		for(lint b = a;b <= n;b++){
			for(int aBit = 0;aBit < 7;aBit++){
				for(int bBit = 0;bBit < 7;bBit++){
					
					lint none = 0;
					lint onlyA = cnt[aBit][aBit][a][a];
					lint onlyB = cnt[bBit][bBit][b][b];
					lint both = cnt[aBit][bBit][a][b];
					onlyA -= both;
					onlyB -= both;
					none = Q - onlyA - onlyB - both;
					
					///don't use "both"
					lint base = min(a,b) * (n - max(a,b) + 1);
					fix(base);
					
					lint p1 = 0;
					
					if(in(arr[a], aBit)) p1 += even(onlyA);
					else p1 += odd(onlyA);
					
					if(in(arr[b], bBit)) p1 += even(onlyB);
					else p1 += odd(onlyB);
					
					p1 += none;
					p1 += even(both);
					p1 += (aBit + bBit);				
					if(a != b) p1++;
					
					//cout << onlyA << " " << onlyB << " " << none << " " << both << " " << p1 << endl;
					if(p1 >= 0){
						ans += base * two[p1];
						fix(ans);					
					}
					
					
					///use "both"
					lint p2 = 0;
					
					if(in(arr[a], aBit)) p2 += odd(onlyA);
					else p2 += even(onlyA);
					
					if(in(arr[b], bBit)) p2 += odd(onlyB);
					else p2 += even(onlyB);
					
					p2 += none;
					p2 += odd(both);
					p2 += (aBit + bBit);				
					if(a != b) p2++;
					
					//cout << onlyA << " " << onlyB << " " << none << " " << both << " " << p1 << endl;
					if(p2 >= 0){
						ans += base * two[p2];
						fix(ans);					
					}
					
				}
			}
		} 
	}
	
	cout << ans << "\n";
}



# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4864 KB Output is correct
2 Correct 6 ms 5376 KB Output is correct
3 Correct 6 ms 6400 KB Output is correct
4 Correct 7 ms 6400 KB Output is correct
5 Correct 6 ms 6400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4864 KB Output is correct
2 Correct 6 ms 5376 KB Output is correct
3 Correct 6 ms 6400 KB Output is correct
4 Correct 7 ms 6400 KB Output is correct
5 Correct 6 ms 6400 KB Output is correct
6 Correct 24 ms 23680 KB Output is correct
7 Correct 24 ms 23808 KB Output is correct
8 Correct 24 ms 23672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 25064 KB Output is correct
2 Correct 26 ms 23964 KB Output is correct
3 Correct 23 ms 23672 KB Output is correct
4 Correct 25 ms 23680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 809 ms 197248 KB Output is correct
2 Correct 805 ms 197256 KB Output is correct
3 Correct 751 ms 197248 KB Output is correct
4 Correct 744 ms 197368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10240 KB Output is correct
2 Correct 10 ms 10240 KB Output is correct
3 Correct 10 ms 10240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10240 KB Output is correct
2 Correct 10 ms 10240 KB Output is correct
3 Correct 10 ms 10240 KB Output is correct
4 Correct 11 ms 10368 KB Output is correct
5 Correct 11 ms 10368 KB Output is correct
6 Correct 11 ms 10368 KB Output is correct
7 Correct 11 ms 10368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4864 KB Output is correct
2 Correct 6 ms 5376 KB Output is correct
3 Correct 6 ms 6400 KB Output is correct
4 Correct 7 ms 6400 KB Output is correct
5 Correct 6 ms 6400 KB Output is correct
6 Correct 24 ms 23680 KB Output is correct
7 Correct 24 ms 23808 KB Output is correct
8 Correct 24 ms 23672 KB Output is correct
9 Correct 10 ms 10240 KB Output is correct
10 Correct 10 ms 10240 KB Output is correct
11 Correct 10 ms 10240 KB Output is correct
12 Correct 23 ms 23808 KB Output is correct
13 Correct 23 ms 23808 KB Output is correct
14 Correct 23 ms 23808 KB Output is correct
15 Correct 25 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4864 KB Output is correct
2 Correct 6 ms 5376 KB Output is correct
3 Correct 6 ms 6400 KB Output is correct
4 Correct 7 ms 6400 KB Output is correct
5 Correct 6 ms 6400 KB Output is correct
6 Correct 24 ms 23680 KB Output is correct
7 Correct 24 ms 23808 KB Output is correct
8 Correct 24 ms 23672 KB Output is correct
9 Correct 10 ms 10240 KB Output is correct
10 Correct 10 ms 10240 KB Output is correct
11 Correct 10 ms 10240 KB Output is correct
12 Correct 11 ms 10368 KB Output is correct
13 Correct 11 ms 10368 KB Output is correct
14 Correct 11 ms 10368 KB Output is correct
15 Correct 11 ms 10368 KB Output is correct
16 Correct 23 ms 23808 KB Output is correct
17 Correct 23 ms 23808 KB Output is correct
18 Correct 23 ms 23808 KB Output is correct
19 Correct 25 ms 23808 KB Output is correct
20 Correct 288 ms 102312 KB Output is correct
21 Correct 253 ms 102256 KB Output is correct
22 Correct 254 ms 102256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4864 KB Output is correct
2 Correct 6 ms 5376 KB Output is correct
3 Correct 6 ms 6400 KB Output is correct
4 Correct 7 ms 6400 KB Output is correct
5 Correct 6 ms 6400 KB Output is correct
6 Correct 24 ms 23680 KB Output is correct
7 Correct 24 ms 23808 KB Output is correct
8 Correct 24 ms 23672 KB Output is correct
9 Correct 60 ms 25064 KB Output is correct
10 Correct 26 ms 23964 KB Output is correct
11 Correct 23 ms 23672 KB Output is correct
12 Correct 25 ms 23680 KB Output is correct
13 Correct 809 ms 197248 KB Output is correct
14 Correct 805 ms 197256 KB Output is correct
15 Correct 751 ms 197248 KB Output is correct
16 Correct 744 ms 197368 KB Output is correct
17 Correct 10 ms 10240 KB Output is correct
18 Correct 10 ms 10240 KB Output is correct
19 Correct 10 ms 10240 KB Output is correct
20 Correct 11 ms 10368 KB Output is correct
21 Correct 11 ms 10368 KB Output is correct
22 Correct 11 ms 10368 KB Output is correct
23 Correct 11 ms 10368 KB Output is correct
24 Correct 23 ms 23808 KB Output is correct
25 Correct 23 ms 23808 KB Output is correct
26 Correct 23 ms 23808 KB Output is correct
27 Correct 25 ms 23808 KB Output is correct
28 Correct 288 ms 102312 KB Output is correct
29 Correct 253 ms 102256 KB Output is correct
30 Correct 254 ms 102256 KB Output is correct
31 Correct 821 ms 198508 KB Output is correct
32 Correct 761 ms 199660 KB Output is correct
33 Correct 803 ms 199528 KB Output is correct
34 Correct 765 ms 199400 KB Output is correct
35 Correct 794 ms 199400 KB Output is correct
36 Correct 791 ms 199400 KB Output is correct