QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418282#4322. rsraogps / 雪に咲く花oscaryangzjCompile Error//C++143.1kb2024-05-23 12:17:202024-05-23 12:18:48

Judging History

你现在查看的是最新测评结果

  • [2024-05-23 12:18:48]
  • 评测
  • [2024-05-23 12:17:20]
  • 提交

answer

#include <bits/stdc++.h>

#define i128 unsigned int
#define ll unsigned int                               
#define vc vector
#define pb emplace_back
#define pii pair <int, int>
#define mkp make_pair
#define rep(i, a, b) for (int i = (a); i <= (b); i ++)
#define lep(i, a, b) for (int i = (a); i >= (b); i --)

using namespace std;
bool ST;

mt19937 gen (time (0));

inline int read () {
	int x = 0, w = 0; char ch = getchar (); while (!isdigit (ch)) w |= (ch == '-'), ch = getchar ();
	while (isdigit (ch)) x = x * 10 + (ch ^ 48), ch = getchar (); return w ? - x : x;
}
inline void write (i128 x) { if (x > 9) write (x / 10); putchar (x % 10 + '0'); }

const int N = 1e6 + 5, M = 5e6 + 5, LOG = 25;

int n, m;
i128 ans[M], a[N], b[N], c[N];
vc <pii> q[N];

struct bit {
	i128 tre[N];
	inline void add (int p, i128 v) { while (p) tre[p] += v, p ^= (p & - p); }
	inline i128 ask (int p) { i128 res = 0; while (p <= n) res += tre[p], p += (p & - p); return res; }
} K, B;

inline void add (int l, int L, int R, i128 v) {
	if (L > R) return ;
	B.add (R, v * (ll) (R + 1));
	B.add (L - 1, v * (ll) (- L));
	K.add (R, - v);
	K.add (L - 1, v);
}

inline ll sum (ll x) { return K.ask (x) * x + B.ask (x); }

inline void prework () {
	pair <ll, int> A[LOG], B[LOG], C[LOG], tmp[LOG];
	int la = 0, lb = 0, lc = 0, len = 0, val;
	lep (i, n, 1) {
		// upd A
		{
			tmp[len = 1].first = val = a[i]; tmp[len].second = i;
			rep (j, 1, la) 
				if ((A[j].first & val) == tmp[len].first) tmp[len].second = A[j].second;
				else tmp[++ len] = mkp (val = (A[j].first & val), A[j].second);
			rep (j, 1, len) A[j] = tmp[j]; la = len;
		}
		// upd B
		{
			tmp[len = 1].first = val = b[i]; tmp[len].second = i;
			rep (j, 1, lb) 
				if ((B[j].first | val) == tmp[len].first) tmp[len].second = B[j].second;
				else tmp[++ len] = mkp (val = (B[j].first | val), B[j].second);
			rep (j, 1, len) B[j] = tmp[j]; lb = len;
		}
		// upd C
		{
			tmp[len = 1].first = val = c[i]; tmp[len].second = i;
			rep (j, 1, lc) 
				if ((val = gcd (C[j].first, val)) == tmp[len].first) tmp[len].second = C[j].second;
				else tmp[++ len] = mkp (val, C[j].second);
			rep (j, 1, len) C[j] = tmp[j]; lc = len;
		}
		// merge 
		{
			int u = 1, v = 1, w = 1, p = i; ll z;
			while (p <= n && u <= la && A[u].second) {
				z = A[u].first * B[v].first * C[w].first;
				if (u <= la && A[u].second <= B[v].second && A[u].second <= C[w].second)
					add (i, p, A[u].second, z), p = A[u].second + 1, ++ u;
				else if (v <= lb && B[v].second <= C[w].second)
					add (i, p, B[v].second, z), p = B[v].second + 1, ++ v;
				else    add (i, p, C[w].second, z), p = C[w].second + 1, ++ w;
			}
		}
		for (auto [r, id] : q[i]) ans[id] = sum (i) - sum (r + 1);
	}
}

bool ED;
signed main () {
	cerr << (&ED - &ST) / 1024 / 1024 << " MB ------------" << endl;
	
	n = read (); m = read ();
	rep (i, 1, n) a[i] = read ();
	rep (i, 1, n) b[i] = read ();
	rep (i, 1, n) c[i] = read (); 
	for (int i = 1, l, r; i <= m; i ++)
		l = read (), r = read (), q[l].pb (mkp (r, i));
	
	prework ();
	
	rep (i, 1, m) write (ans[i]), putchar (10);
	
	return 0;
}


Details

answer.code: In function ‘void prework()’:
answer.code:69:44: error: ‘gcd’ was not declared in this scope
   69 |                                 if ((val = gcd (C[j].first, val)) == tmp[len].first) tmp[len].second = C[j].second;
      |                                            ^~~
answer.code:85:27: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   85 |                 for (auto [r, id] : q[i]) ans[id] = sum (i) - sum (r + 1);
      |                           ^