Submission #469692

# Submission time Handle Problem Language Result Execution time Memory
469692 2021-09-01T15:36:47 Z keta_tsimakuridze Intergalactic ship (IZhO19_xorsum) C++14
92 / 100
2000 ms 29840 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 1e3 + 5, M = 1e5 + 5, mod = 1e9 + 7; // !
int a[N],n,Q,ch[M][2],pwr[M],dp[5][N][N],p[5][N];
vector<pair<pii,int> > all;
int choose(int x,int t) {
	return ch[x][t];
}
main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	cin >> Q;
	for(int j = 1; j <= Q; j++) {
		int l,r,x;
		cin >> l >> r >> x;
		all.push_back({{l,r},x});
	}
	
	ch[0][0] = 1;
	pwr[0] = 1;
	for(int i = 1; i <= Q; i++) {
		for(int t = 0; t < 2; t++){
			ch[i][t] = ch[i - 1][t] + ch[i - 1][1 - t];
			ch[i][t] %= mod;
		}
		pwr[i] = pwr[i - 1] * 2 % mod;
	}
	int ans = 0;
	for(int t1 = 0; t1 < 8; t1++) {
		for(int t2 = 0; t2 < 8; t2++) {
			for(int t = 0; t < 3; t++) 
			for(int i = 1; i <= n; i++) {
				p[t][i] = 0;
				for(int j = 1; j <= n; j++) dp[t][i][j] = 0;
			}
			for(int i = 0; i < Q; i++){
				int l = all[i].f.f, r = all[i].f.s, x = all[i].s;
				if((x & (1 << t1)) && (x & (1 << t2))) {
					dp[2][l][r]++;
					p[2][l]++;
					p[2][r + 1]--;
				}
				else if(x & (1 << t1)) dp[0][l][r]++,p[0][l]++, p[0][r + 1]--;
				else if(x & (1 << t2))dp[1][l][r]++, p[1][l]++, p[1][r + 1]--;
			}
			
			for(int t = 0; t < 3; t++) {
				for(int l = 1; l <= n; l++) {
					for(int r = n; r >= l; r--) dp[t][l][r] += dp[t][l - 1][r] + dp[t][l][r + 1] - dp[t][l - 1][r + 1];
				}
			}
		//	cout<<"++"<<endl;
			for(int t = 0; t < 3; t++)
			for(int i = 1; i <= n; i++) {
				p[t][i] += p[t][i - 1];
			}
			for(int l = 1; l <= n; l++) {
				for(int r = l; r <= n; r++) {
					int b1 =( (1 << t1) & a[l] ) > 0;
					int b2 = ( (1 << t2) & a[r] ) > 0;
					int P = (1 << t1) % mod * (1 << t2) % mod 
							* l % mod * (n - r + 1) % mod* pwr[Q - p[0][l] - p[1][r] - p[2][l] - p[2][r] + dp[2][l][r] ] % mod;
					if(l < r) P *= 2;//cout<<P<<"++"<<endl;
					P %= mod;
					for(int x1 = 0; x1 < 2; x1++){
						for(int x2 = 0; x2 < 2; x2++) {
							int x3 = 1 ^ x1 ^ b1;
							
							if(x3 ^ x2 ^ b2) {
							
				//				cout << p[0][l] + p[2][l] - dp[2][l][r] << endl;
				//			if(t1 == 1 && t2 == 0 && l == 1 && r == 2)
				//			cout << p[0][l] + p[2][l] - dp[2][l][r] << "_"<<x1 <<" "<< p[1][r] + p[2][r] - dp[2][l][r] <<" "<<x2<< endl;
								ans += choose(p[0][l] + p[2][l] - dp[2][l][r],x1)% mod * choose(p[1][r] + p[2][r] - dp[2][l][r],x2) % mod * choose(dp[2][l][r],x3)% mod * P %mod; 
								ans %= mod;
							}
						}
					}
					
					// wth
					
			//	 cout <<l <<" ____  "<<r<<" "<< t1 <<" "<< t2 <<" "<< ans << endl;
				}
			}	
		}
	}
	cout << ans;
 }

Compilation message

xorsum.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 20 ms 1784 KB Output is correct
7 Correct 19 ms 1784 KB Output is correct
8 Correct 20 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 6516 KB Output is correct
2 Correct 28 ms 2376 KB Output is correct
3 Correct 20 ms 1828 KB Output is correct
4 Correct 20 ms 1796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1993 ms 23992 KB Output is correct
2 Correct 1982 ms 23988 KB Output is correct
3 Correct 1977 ms 23968 KB Output is correct
4 Correct 1988 ms 23968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 6 ms 1036 KB Output is correct
5 Correct 6 ms 1036 KB Output is correct
6 Correct 6 ms 1036 KB Output is correct
7 Correct 6 ms 1036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 20 ms 1784 KB Output is correct
7 Correct 19 ms 1784 KB Output is correct
8 Correct 20 ms 1740 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 22 ms 1740 KB Output is correct
13 Correct 21 ms 1820 KB Output is correct
14 Correct 20 ms 1820 KB Output is correct
15 Correct 20 ms 1820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 20 ms 1784 KB Output is correct
7 Correct 19 ms 1784 KB Output is correct
8 Correct 20 ms 1740 KB Output is correct
9 Correct 2 ms 716 KB Output is correct
10 Correct 3 ms 716 KB Output is correct
11 Correct 2 ms 716 KB Output is correct
12 Correct 6 ms 1036 KB Output is correct
13 Correct 6 ms 1036 KB Output is correct
14 Correct 6 ms 1036 KB Output is correct
15 Correct 6 ms 1036 KB Output is correct
16 Correct 22 ms 1740 KB Output is correct
17 Correct 21 ms 1820 KB Output is correct
18 Correct 20 ms 1820 KB Output is correct
19 Correct 20 ms 1820 KB Output is correct
20 Correct 669 ms 16948 KB Output is correct
21 Correct 602 ms 16948 KB Output is correct
22 Correct 576 ms 16948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 20 ms 1784 KB Output is correct
7 Correct 19 ms 1784 KB Output is correct
8 Correct 20 ms 1740 KB Output is correct
9 Correct 95 ms 6516 KB Output is correct
10 Correct 28 ms 2376 KB Output is correct
11 Correct 20 ms 1828 KB Output is correct
12 Correct 20 ms 1796 KB Output is correct
13 Correct 1993 ms 23992 KB Output is correct
14 Correct 1982 ms 23988 KB Output is correct
15 Correct 1977 ms 23968 KB Output is correct
16 Correct 1988 ms 23968 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 2 ms 716 KB Output is correct
20 Correct 6 ms 1036 KB Output is correct
21 Correct 6 ms 1036 KB Output is correct
22 Correct 6 ms 1036 KB Output is correct
23 Correct 6 ms 1036 KB Output is correct
24 Correct 22 ms 1740 KB Output is correct
25 Correct 21 ms 1820 KB Output is correct
26 Correct 20 ms 1820 KB Output is correct
27 Correct 20 ms 1820 KB Output is correct
28 Correct 669 ms 16948 KB Output is correct
29 Correct 602 ms 16948 KB Output is correct
30 Correct 576 ms 16948 KB Output is correct
31 Execution timed out 2077 ms 29840 KB Time limit exceeded
32 Halted 0 ms 0 KB -