답안 #322470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
322470 2020-11-14T18:38:23 Z ryansee Intergalactic ship (IZhO19_xorsum) C++14
83 / 100
895 ms 262148 KB
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<pi,ll>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (100006)
ll n, A[1006], B[1006][1006][7][7], fw[7][7][1006], q, mod=1e9+7, ans, psum[7][1006], p2[MAXN];
vector<spi> v, o;
void update(int b1,int b2,int x,ll nval) {
	for(;x<=1000;x+=x&(-x)) fw[b1][b2][x]+=nval;
}
ll sum(int b1,int b2,int x) {
	ll res=0;
	for(;x;x-=x&(-x))res+=fw[b1][b2][x];
	return res;
}
ll sum(int bit1,int bit2,int a,int b) {
	return sum(bit1,bit2,b) - sum(bit1,bit2,a-1);
}
int main() {
	FAST
	cin>>n;
	FOR(i,1,n) cin>>A[i];
	cin>>q;
	v.resize(q);
	for(auto&i:v)cin>>i.f.f>>i.f.s>>i.s;
	sort(all(v)), reverse(all(v));
	o=v;
	FOR(i,1,n) {
		while(v.size()&&v.back().f.f==i) {
			FOR(i,0,6)if(1<<i&v.back().s)FOR(j,0,6)if(1<<j&v.back().s)update(i, j, v.back().f.s, 1);
			v.pop_back();
		}
		FOR(j,i,n)FOR(b1,0,6)FOR(b2,0,6){
			B[i][j][b1][b2]=sum(b1,b2,j,n);
		}
	}
	v=o, mmst(fw,0);
	FOR(i,1,n)FOR(j,i+1,n)FOR(b1,0,6)FOR(b2,0,6)B[j][i][b1][b2]=B[i][j][b1][b2];
	for(auto i:v){
		FOR(b,0,6) if(1<<b&i.s) ++ psum[b][i.f.f], -- psum[b][i.f.s+1];
	}
	FOR(b,0,6) FOR(i,1,n) psum[b][i]+=psum[b][i-1];
	p2[0]=1; FOR(i,1,MAXN-1)p2[i]=p2[i-1]*2%mod;
	auto Cp=[&](ll x){return p2[x-1];};// make sure x!=0
	FOR(i,1,n)FOR(j,i,n)FOR(b1,0,6)FOR(b2,0,6){
		// ways for b1 to be activated for i, and b2 to be activated for j
		// * 2 ah
		ll x=psum[b1][i], y=psum[b2][j], ways1[2]={0,0}, ways2[2]={0,0}, c=B[i][j][b1][b2], ceff=i*(n-j+1)%mod;
		if(i^j) ceff*=2, ceff%=mod;
		x-=c, y-=c;
		ll notin = q-x-y-c;
		if(1<<b1&A[i]) ways1[0] = x ? Cp(x) : 0, ways1[1] = x ? Cp(x) : 1;
		else ways1[0] = x ? Cp(x) : 1, ways1[1] = x ? Cp(x) : 0;
		if(1<<b2&A[j]) ways2[0] = y ? Cp(y) : 0, ways2[1] = y ? Cp(y) : 1;
		else ways2[0] = y ? Cp(y) : 1, ways2[1] = y ? Cp(y) : 0;
		ans += ceff * ways1[0] % mod * ways2[0] % mod * (c ? Cp(c) : 0) % mod * (1ll<<b1) % mod * (1ll<<b2) % mod * p2[notin] % mod, ans %= mod;
		ans += ceff * ways1[1] % mod * ways2[1] % mod * (c ? Cp(c) : 1) % mod * (1ll<<b1) % mod * (1ll<<b2) % mod * p2[notin] % mod, ans %= mod;
	}
	cout<<ans<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 2 ms 1644 KB Output is correct
4 Correct 2 ms 1644 KB Output is correct
5 Correct 2 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 2 ms 1644 KB Output is correct
4 Correct 2 ms 1644 KB Output is correct
5 Correct 2 ms 1644 KB Output is correct
6 Correct 19 ms 5868 KB Output is correct
7 Correct 17 ms 5868 KB Output is correct
8 Correct 17 ms 5868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 10604 KB Output is correct
2 Correct 25 ms 6380 KB Output is correct
3 Correct 19 ms 5868 KB Output is correct
4 Correct 18 ms 5868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 532 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2028 KB Output is correct
2 Correct 3 ms 2028 KB Output is correct
3 Correct 3 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2028 KB Output is correct
2 Correct 3 ms 2028 KB Output is correct
3 Correct 3 ms 2028 KB Output is correct
4 Correct 7 ms 2284 KB Output is correct
5 Correct 8 ms 2280 KB Output is correct
6 Correct 7 ms 2284 KB Output is correct
7 Correct 8 ms 2284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 2 ms 1644 KB Output is correct
4 Correct 2 ms 1644 KB Output is correct
5 Correct 2 ms 1644 KB Output is correct
6 Correct 19 ms 5868 KB Output is correct
7 Correct 17 ms 5868 KB Output is correct
8 Correct 17 ms 5868 KB Output is correct
9 Correct 4 ms 2028 KB Output is correct
10 Correct 3 ms 2028 KB Output is correct
11 Correct 3 ms 2028 KB Output is correct
12 Correct 30 ms 5868 KB Output is correct
13 Correct 32 ms 5868 KB Output is correct
14 Correct 21 ms 5868 KB Output is correct
15 Correct 25 ms 5932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 2 ms 1644 KB Output is correct
4 Correct 2 ms 1644 KB Output is correct
5 Correct 2 ms 1644 KB Output is correct
6 Correct 19 ms 5868 KB Output is correct
7 Correct 17 ms 5868 KB Output is correct
8 Correct 17 ms 5868 KB Output is correct
9 Correct 4 ms 2028 KB Output is correct
10 Correct 3 ms 2028 KB Output is correct
11 Correct 3 ms 2028 KB Output is correct
12 Correct 7 ms 2284 KB Output is correct
13 Correct 8 ms 2280 KB Output is correct
14 Correct 7 ms 2284 KB Output is correct
15 Correct 8 ms 2284 KB Output is correct
16 Correct 30 ms 5868 KB Output is correct
17 Correct 32 ms 5868 KB Output is correct
18 Correct 21 ms 5868 KB Output is correct
19 Correct 25 ms 5932 KB Output is correct
20 Correct 895 ms 105480 KB Output is correct
21 Correct 635 ms 105508 KB Output is correct
22 Correct 861 ms 105472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 2 ms 1644 KB Output is correct
4 Correct 2 ms 1644 KB Output is correct
5 Correct 2 ms 1644 KB Output is correct
6 Correct 19 ms 5868 KB Output is correct
7 Correct 17 ms 5868 KB Output is correct
8 Correct 17 ms 5868 KB Output is correct
9 Correct 64 ms 10604 KB Output is correct
10 Correct 25 ms 6380 KB Output is correct
11 Correct 19 ms 5868 KB Output is correct
12 Correct 18 ms 5868 KB Output is correct
13 Runtime error 532 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Halted 0 ms 0 KB -