답안 #468427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468427 2021-08-28T07:38:14 Z hhhhaura Intergalactic ship (IZhO19_xorsum) C++14
0 / 100
1998 ms 16608 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define MOD 1000000007
#define eps (1e-9)
using namespace std;

#define int long long int
#ifdef wiwihorz
#define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...)
#define vprint(...)
#endif
namespace solver {
	int n, q, tot;
	const int P = 8;
	vector<vector<int>> v[2], ans, s, p, ll, rr;
	vector<int> L, R, X, A, cnt;
	void init_(int _n, int _q) {
		n = _n, q = _q, tot = 2 * P;
		v[0].assign(n + 2, vector<int>(4 * P * P, 0));
		v[1].assign(n + 2, vector<int>(4 * P * P, 0));
		cnt.assign(4 * P * P, 0);
		ll.assign(n + 2, vector<int>(4 * P * P, 0));
		rr.assign(n + 2, vector<int>(4 * P * P, 0));
		ans.assign(n + 2, vector<int>(n + 2, 0));
		s.assign(n + 2, vector<int>(2 * P, 0));
		p.assign(n + 2, vector<int>());
		L.assign(q + 1, 0);
		R.assign(q + 1, 0);
		X.assign(q + 1, 0);
	}
	int get(int a, int va, int b, int vb) {
		return (2 * a + va) * tot + (2 * b + vb);
	}
	int val(int L, int R, int type) {
		int ans = ll[n][type] - ll[L][type] 
			+ rr[R - 1][type] - v[!(R & 1)][L + 1][type];
		return (cnt[type] - ans) % MOD; 
	}
	int solve() {
		rep(i, 1, q) rep(j, 0, P - 1) {
			int val = (X[i] >> j) & 1;
			s[L[i]][j * 2 + val] ++;
			s[R[i] + 1][j * 2 + val] --;
		}
		rep(i, 1, q) rep(a, 0, P - 1) rep(b, 0, P - 1) {
			int va = (X[i] >> a) & 1, vb = (X[i] >> b) & 1;
			int id = get(a, va, b, vb);
			cnt[id] ++;
			ll[L[i]][id] ++;
			rr[R[i]][id] ++;
		}
		rep(i, 1, n) rep(j, 0, tot * tot - 1) {
			ll[i][j] += ll[i - 1][j];
			rr[i][j] += rr[i - 1][j];	
		}
		rep(i, 1, n) rep(j, 0, 2 * P - 1) s[i][j] += s[i - 1][j];
		rep(i, 1, n) rep(j, 0, P - 1) s[i][2 * j] ++;
		rep(i, 1, n) {
			int id = i & 1;
			// place new
			v[id].assign(n + 2, vector<int>(4 * P * P, 0));
			for(auto j : p[i]) {
				rep(a, 0, P - 1) rep(b, 0, P - 1) {
					v[id][L[j]][get(a, (X[j] >> a) & 1, b, (X[j] >> b) & 1)] ++;
				}
			}
			// convolute
			rep(j, 1, i) rep(m, 0, tot * tot - 1) 
				v[id][i][m] = (v[id][i][m] + v[id][i - 1][m]) % MOD;
			rep(j, 1, i) rep(m, 0, tot * tot - 1) 
				v[id][i][m] = (v[id][i][m] + v[!id][i][m]) % MOD;  
			// cal ans
			rep(j, 1, i - 1) rep(a, 0, P - 1) rep(b, 0, P - 1) {
				int va = (A[j] >> a) & 1, vb = (A[i] >> b) & 1;
				int cross = val(j, i, get(a, 1 ^ va, b, 1 ^ vb));
				int k1 = s[j][2 * a + (1 ^ va)] - cross - val(j, i, get(a, 1 ^ va, b, vb));
				int k2 = s[i][2 * b + (1 ^ vb)] - cross - val(j, i, get(a, va, b, 1 ^ vb));
				int ways = (k1 * k2 + cross) % MOD;
				ans[j][i] += 2 * (1 << (a + b)) * ways % MOD;
				ans[j][i] %= MOD; 
			}	
			rep(a, 0, P - 1) rep(b, 0, P - 1) {
				int va = (A[i] >> a) & 1, vb = (A[i] >> b) & 1;
				ans[i][i] += (1 << (a + b)) * 
					(val(i, i, get(a, 1 ^ va, b, 1 ^ vb)) + (va == 1 && vb == 1))% MOD;
				ans[i][i] %= MOD;
			}		
		}
		rep(i, 1, n) rep(j, 1, n) ans[i][j] = 
			(ans[i][j] + ans[i - 1][j] + ans[i][j - 1] - ans[i - 1][j - 1]) % MOD;
		int cal = 0;
		rep(i, 1, n) rep(j, i, n) {
			cal = (cal + ans[j][j] - ans[i - 1][j] - ans[j][i - 1] + ans[i - 1][i - 1]) % MOD;
		} 
		return (cal + MOD) % MOD;
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n; cin >> n;
	A.assign(n + 1, 0);
	rep(i, 1, n) cin >> A[i];
	int q; cin >> q;
	init_(n, q);
	rep(i, 1, q) {
		cin >> L[i] >> R[i] >> X[i];
		p[R[i]].push_back(i);
	}
	cout << solve() << "\n";
	return 0;
}

Compilation message

xorsum.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
xorsum.cpp:13:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   13 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
      |             ^~~~
xorsum.cpp:13:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   13 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
      |                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 203 ms 4760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1998 ms 16608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -