Submission #651283

# Submission time Handle Problem Language Result Execution time Memory
651283 2022-10-18T06:19:44 Z alvingogo Intergalactic ship (IZhO19_xorsum) C++14
100 / 100
1389 ms 17328 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
 
struct BIT{
	int n;
	vector<int> bt;
	void init(int x){
		n=x;
		bt.resize(n+1);
	}
	void update(int x,int y){
		x++;
		for(;x<=n;x+=(x&-x)){
			bt[x]+=y;
		}
	}
	int query(int x){
		x++;
		int ans=0;
		for(;x>0;x-=(x&-x)){
			ans+=bt[x];
		}
		return ans;
	}
};
const int mod=1e9+7;
void add(int& x,int y){
	x+=y;
	x-=mod*(x>=mod);
}
int mul(int x,int y){
	return 1ll*x*y%mod;
}
int main(){
    AquA;
	vector<int> p2(1e5+7);
	p2[0]=1;
	for(int i=1;i<100007;i++){
		p2[i]=mul(p2[i-1],2);
	}
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	int q;
	cin >> q;
	const int A=7;
	vector<vector<int> > pre(A,vector<int>(n));
	vector<vector<vector<pair<int,int> > > > vq(A,vector<vector<pair<int,int> > >(A));
	for(int i=0;i<q;i++){
		int l,r,x;
		cin >> l >> r >> x;
		l--;
		r--;
		for(int j=0;j<A;j++){
			if((x>>j)&1){
				for(int k=0;k<A;k++){
					if((x>>k)&1){
						vq[j][k].push_back({l,r});
						
					}
				}
				pre[j][l]++;
				if(r+1<n){
					pre[j][r+1]--;
				}
			}
		}
	}
	int ans=0;
	for(int j=0;j<A;j++){
		for(int i=1;i<n;i++){
			pre[j][i]+=pre[j][i-1];
		}
	}
	for(int j=0;j<A;j++){
		for(int l=0;l<A;l++){
			BIT bt;
			bt.init(n);
			vector<vector<int> > ct(n,vector<int>(n));
			sort(vq[j][l].begin(),vq[j][l].end(),[&](pair<int,int> a,pair<int,int> b){return a.sc<b.sc;});
			int ll=0;
			for(auto h:vq[j][l]){
				bt.update(h.fs,1);
			}
			for(int i=0;i<n;i++){
				for(int k=0;k<=i;k++){
					ct[i][k]=bt.query(k);
				}
				while(ll<(int)vq[j][l].size() && vq[j][l][ll].sc==i){
					bt.update(vq[j][l][ll].fs,-1);
					ll++;
				}	
			}
			for(int i=0;i<n;i++){
				for(int k=0;k<=i;k++){
					int z=1;
					if(i!=k){
						z=2;
					}
					int a=ct[i][k],b=pre[j][i]-a,c=pre[l][k]-a;
					int now=p2[q-a-b-c];
					int x=(v[i]>>j)&1,y=(v[k]>>l)&1;
					for(int h=0;h<2;h++){
						if(h==1 && a==0){
							continue;
						}
						now=mul(now,p2[max(a-1,0)]);
						if(h==1){
							x^=1;
							y^=1;
						}
						if(x==0 && b==0){
							now=0;
						}
						if(y==0 && c==0){
							now=0;
						}
						now=mul(now,mul(p2[max(b-1,0)],p2[max(c-1,0)]));
						add(ans,mul(z,mul(mul(now,p2[j+l]),mul(k+1,n-i))));
						now=p2[q-a-b-c];
					}
				}
			}
		}
	}
	cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 9 ms 724 KB Output is correct
7 Correct 9 ms 724 KB Output is correct
8 Correct 8 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 7572 KB Output is correct
2 Correct 17 ms 1736 KB Output is correct
3 Correct 10 ms 844 KB Output is correct
4 Correct 8 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 780 ms 4892 KB Output is correct
2 Correct 782 ms 4852 KB Output is correct
3 Correct 765 ms 4860 KB Output is correct
4 Correct 774 ms 5028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 7 ms 1236 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 8 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 9 ms 724 KB Output is correct
7 Correct 9 ms 724 KB Output is correct
8 Correct 8 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 13 ms 724 KB Output is correct
13 Correct 13 ms 852 KB Output is correct
14 Correct 9 ms 732 KB Output is correct
15 Correct 11 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 9 ms 724 KB Output is correct
7 Correct 9 ms 724 KB Output is correct
8 Correct 8 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 7 ms 1236 KB Output is correct
14 Correct 8 ms 1236 KB Output is correct
15 Correct 8 ms 1236 KB Output is correct
16 Correct 13 ms 724 KB Output is correct
17 Correct 13 ms 852 KB Output is correct
18 Correct 9 ms 732 KB Output is correct
19 Correct 11 ms 724 KB Output is correct
20 Correct 456 ms 13936 KB Output is correct
21 Correct 350 ms 14356 KB Output is correct
22 Correct 310 ms 3588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 9 ms 724 KB Output is correct
7 Correct 9 ms 724 KB Output is correct
8 Correct 8 ms 724 KB Output is correct
9 Correct 94 ms 7572 KB Output is correct
10 Correct 17 ms 1736 KB Output is correct
11 Correct 10 ms 844 KB Output is correct
12 Correct 8 ms 724 KB Output is correct
13 Correct 780 ms 4892 KB Output is correct
14 Correct 782 ms 4852 KB Output is correct
15 Correct 765 ms 4860 KB Output is correct
16 Correct 774 ms 5028 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 2 ms 724 KB Output is correct
20 Correct 6 ms 1236 KB Output is correct
21 Correct 7 ms 1236 KB Output is correct
22 Correct 8 ms 1236 KB Output is correct
23 Correct 8 ms 1236 KB Output is correct
24 Correct 13 ms 724 KB Output is correct
25 Correct 13 ms 852 KB Output is correct
26 Correct 9 ms 732 KB Output is correct
27 Correct 11 ms 724 KB Output is correct
28 Correct 456 ms 13936 KB Output is correct
29 Correct 350 ms 14356 KB Output is correct
30 Correct 310 ms 3588 KB Output is correct
31 Correct 1389 ms 17328 KB Output is correct
32 Correct 987 ms 17120 KB Output is correct
33 Correct 1211 ms 6660 KB Output is correct
34 Correct 1200 ms 14020 KB Output is correct
35 Correct 1221 ms 14272 KB Output is correct
36 Correct 1187 ms 14096 KB Output is correct