Submission #869132

# Submission time Handle Problem Language Result Execution time Memory
869132 2023-11-03T09:43:03 Z KiaRez Intergalactic ship (IZhO19_xorsum) C++17
100 / 100
1279 ms 23116 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 1e5+23, lg = 17;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

ll n, q, a[N], pw[N], X[N], ans, L[N], R[N];
int dp[1005][1005][4];
vector<int> vec[N];

int get(int b1, int b2) {
	return b1*2+b2;
}

void update(int b1, int b2) {
	for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) for(int k=0; k<4; k++) dp[i][j][k]=0;

	for(int i=1; i<=q; i++) {
		dp[L[i]][R[i]][get((X[i]>>b1)%2, (X[i]>>b2)%2)] ++;
	}

	for(int sz=n-1; sz>=1; sz--) {
		for(int l,r=sz; r<=n; r++) {
			l = r-sz+1;
			for(int b=0; b<4; b++) {
				dp[l][r][b] += (dp[l][r+1][b] + dp[l-1][r][b] - dp[l-1][r+1][b]);
			}
		}
	}
}

int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	pw[0]=1; for(int i=1; i<N; i++) pw[i] = MOD(pw[i-1] * 2);

	cin>>n;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
	}
	cin>>q;
	for(int i=1; i<=q; i++) {
		cin>>L[i]>>R[i]>>X[i];
	}

	for(int bi=0; bi<7; bi++) {
	for(int bj=0; bj<7; bj++) {
		update(bi, bj);
		for(int i=1; i<=n; i++) {
			for(int j=n; j>=i; j--) {
				int num=dp[i][j][3];
				int numi=dp[i][i][2]+dp[i][i][3]-num;
				int numj=dp[j][j][1]+dp[j][j][3]-num;
				ll comb = 0;
				if(numi > 0) {
					if(numj > 0) {
						comb = MOD(MOD(pw[numi-1]*pw[numj-1])*pw[num]);
					} else {
						if(num > 0) {
							comb = MOD(pw[num-1] * pw[numi-1]);
						} else {
							if((a[j]>>bj)%2==1) comb = pw[numi-1];
						}
					}
				} else if(numj > 0) {
					if(num > 0) {
						comb = MOD(pw[num-1] * pw[numj-1]);
					} else {
						if((a[i]>>bi)%2==1) comb = pw[numj-1];
					}
				} else {
					if((a[i]>>bi)%2 == (a[j]>>bj)%2) {
						if(num > 0) comb = pw[num-1];
						else {
							if((a[i]>>bi)%2==1) comb=1;
						}
					}
				}
			ans = MOD(ans + MOD(comb*pw[q-num-numi-numj])*MOD(pw[bi+bj]*MOD(1ll*i*(n-j+1))) * (i==j ? 1ll : 2ll));
			}
		}
	}
	}

	cout<<ans<<endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9308 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 9440 KB Output is correct
4 Correct 2 ms 9308 KB Output is correct
5 Correct 2 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9308 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 9440 KB Output is correct
4 Correct 2 ms 9308 KB Output is correct
5 Correct 2 ms 9308 KB Output is correct
6 Correct 8 ms 9308 KB Output is correct
7 Correct 7 ms 9308 KB Output is correct
8 Correct 7 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 10076 KB Output is correct
2 Correct 12 ms 9308 KB Output is correct
3 Correct 8 ms 9448 KB Output is correct
4 Correct 7 ms 9304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 654 ms 21844 KB Output is correct
2 Correct 664 ms 21748 KB Output is correct
3 Correct 589 ms 21596 KB Output is correct
4 Correct 628 ms 21744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9304 KB Output is correct
2 Correct 2 ms 9308 KB Output is correct
3 Correct 3 ms 9440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9304 KB Output is correct
2 Correct 2 ms 9308 KB Output is correct
3 Correct 3 ms 9440 KB Output is correct
4 Correct 4 ms 9308 KB Output is correct
5 Correct 4 ms 9484 KB Output is correct
6 Correct 4 ms 9304 KB Output is correct
7 Correct 4 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9308 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 9440 KB Output is correct
4 Correct 2 ms 9308 KB Output is correct
5 Correct 2 ms 9308 KB Output is correct
6 Correct 8 ms 9308 KB Output is correct
7 Correct 7 ms 9308 KB Output is correct
8 Correct 7 ms 9308 KB Output is correct
9 Correct 3 ms 9304 KB Output is correct
10 Correct 2 ms 9308 KB Output is correct
11 Correct 3 ms 9440 KB Output is correct
12 Correct 13 ms 9308 KB Output is correct
13 Correct 13 ms 9304 KB Output is correct
14 Correct 10 ms 9308 KB Output is correct
15 Correct 11 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9308 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 9440 KB Output is correct
4 Correct 2 ms 9308 KB Output is correct
5 Correct 2 ms 9308 KB Output is correct
6 Correct 8 ms 9308 KB Output is correct
7 Correct 7 ms 9308 KB Output is correct
8 Correct 7 ms 9308 KB Output is correct
9 Correct 3 ms 9304 KB Output is correct
10 Correct 2 ms 9308 KB Output is correct
11 Correct 3 ms 9440 KB Output is correct
12 Correct 4 ms 9308 KB Output is correct
13 Correct 4 ms 9484 KB Output is correct
14 Correct 4 ms 9304 KB Output is correct
15 Correct 4 ms 9308 KB Output is correct
16 Correct 13 ms 9308 KB Output is correct
17 Correct 13 ms 9304 KB Output is correct
18 Correct 10 ms 9308 KB Output is correct
19 Correct 11 ms 9308 KB Output is correct
20 Correct 339 ms 16884 KB Output is correct
21 Correct 291 ms 16660 KB Output is correct
22 Correct 331 ms 16548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9308 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 9440 KB Output is correct
4 Correct 2 ms 9308 KB Output is correct
5 Correct 2 ms 9308 KB Output is correct
6 Correct 8 ms 9308 KB Output is correct
7 Correct 7 ms 9308 KB Output is correct
8 Correct 7 ms 9308 KB Output is correct
9 Correct 33 ms 10076 KB Output is correct
10 Correct 12 ms 9308 KB Output is correct
11 Correct 8 ms 9448 KB Output is correct
12 Correct 7 ms 9304 KB Output is correct
13 Correct 654 ms 21844 KB Output is correct
14 Correct 664 ms 21748 KB Output is correct
15 Correct 589 ms 21596 KB Output is correct
16 Correct 628 ms 21744 KB Output is correct
17 Correct 3 ms 9304 KB Output is correct
18 Correct 2 ms 9308 KB Output is correct
19 Correct 3 ms 9440 KB Output is correct
20 Correct 4 ms 9308 KB Output is correct
21 Correct 4 ms 9484 KB Output is correct
22 Correct 4 ms 9304 KB Output is correct
23 Correct 4 ms 9308 KB Output is correct
24 Correct 13 ms 9308 KB Output is correct
25 Correct 13 ms 9304 KB Output is correct
26 Correct 10 ms 9308 KB Output is correct
27 Correct 11 ms 9308 KB Output is correct
28 Correct 339 ms 16884 KB Output is correct
29 Correct 291 ms 16660 KB Output is correct
30 Correct 331 ms 16548 KB Output is correct
31 Correct 1279 ms 23116 KB Output is correct
32 Correct 1130 ms 22824 KB Output is correct
33 Correct 1259 ms 22728 KB Output is correct
34 Correct 1048 ms 22628 KB Output is correct
35 Correct 1039 ms 22868 KB Output is correct
36 Correct 1032 ms 22620 KB Output is correct