QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108323#4322. rsraogps / 雪に咲く花Public123#RE 0ms0kbC++114.6kb2023-05-24 15:49:342023-05-24 15:49:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-24 15:49:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-05-24 15:49:34]
  • 提交

answer

/*
60 + 0 + 100 + 64 = 224.
*/

#pragma GCC optimize(2) 
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ll __int128
inline int read()
{
	int sum = 0, nega = 1;
	char ch = getchar();
	while (ch > '9'||ch < '0')
	{
	    if (ch == '-') nega = -1;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
	return sum * nega;
}
char opt[40]; int cnt;
inline void Write(ll X) 
{
	cnt = 0;
	while(X) opt[++cnt] = X % 10 + '0', X /= 10; 
	while(cnt) putchar(opt[cnt]), cnt--; return ;
}
const int N = 1e6 + 9, M = 5e6 + 9, mod = 998244353;
int seed = 1, base = 1919810;
struct node
{
	int id, x; 
};
inline int Gcd(int x, int y) 
{
	if(y == 0) return x;
	return Gcd(y, x % y);
} 
int n, m, a[N], b[N], c[N], suma[N], sumb[N], sumc[N], nwa, nwb, nwc;
int A[N][21], B[N][21], C[N][21];
ll ans[M], tr[N << 2], tag[N << 2];
inline int lc(int p) {return p << 1;}
inline int rc(int p) {return p << 1 | 1;}
inline void push_up(int p) {tr[p] = tr[lc(p)] + tr[rc(p)]; return ;}
inline void push_down(int p, int l, int r) 
{
	if(tag[p]) 
	{
		int mid = (l + r) >> 1;
		tr[lc(p)] += tag[p] * (mid - l + 1), tr[rc(p)] += tag[p] * (r - mid); 
		tag[lc(p)] += tag[p], tag[rc(p)] += tag[p]; tag[p] = 0; 
	}
	return ;
}
inline void update(int l, int r, int p, int L, int R, ll v) 
{
	if(L > R) return ;
	if(L <= l && r <= R) {tr[p] += v * (r - l + 1), tag[p] += v; return ;}
	int mid = (l + r) >> 1; 
	push_down(p, l, r);
	if(mid >= L) update(l, mid, lc(p), L, R, v);
	if(mid < R) update(mid + 1, r, rc(p), L, R, v); 
	push_up(p); return ;
}
inline ll query(int l, int r, int p, int L, int R) 
{
	if(L <= l && r <= R) return tr[p]; 
	int mid = (l + r) >> 1; ll res = 0; push_down(p, l, r); 
	if(mid >= L) res += query(l, mid, lc(p), L, R);
	if(mid < R) res += query(mid + 1, r, rc(p), L, R); 
	return res; 
}
vector<node> G[N];
int pos;  
inline int upda(int x, int posa)
{
	if(nwa == suma[x]) return 0;
	int toa = posa;
	for (int i = 0; i <= 20; i++) 
		if((A[toa][i] & nwa) == nwa) toa -= (1 << i); 
		else {pos = i; break;}
	for (int i = pos - 1; i >= 0; i--) 
		if((A[toa][i] & nwa) == nwa) toa -= (1 << i); 
	return toa;
}
inline int updb(int x, int posb) 
{
	if(nwb == sumb[x]) return 0;
	int tob = posb; 
	for (int i = 0; i <= 20; i++) 
		if((B[tob][i] | nwb) == nwb) tob -= (1 << i); 
		else {pos = i; break;}
	for (int i = pos - 1; i >= 0; i--) 
		if((B[tob][i] | nwb) == nwb) tob -= (1 << i); 
	return tob;
}
inline int updc(int x, int posc) 
{
	if(nwc == sumc[x]) return 0;
	int toc = posc; 
	for (int i = 0; i <= 20; i++) 
		if(C[toc][i] % nwc == 0) toc -= (1 << i); 
		else {pos = i; break;}
	for (int i = pos - 1; i >= 0; i--) 
		if(C[toc][i] % nwc == 0) toc -= (1 << i); 	
	return toc; 
}
inline void work(int x) 
{
	int posa = x, posb = x, posc = x, toa = x, tob = x, toc = x;
	nwa = a[x], nwb = b[x], nwc = c[x];		
	toa = upda(x, posa), tob = updb(x, posb), toc = updc(x, posc); 
	int now = x;
	while(nwa != suma[x] || nwb != sumb[x] || nwc != sumc[x]) 
	{
 		int t = max(max(toa, tob), toc); 
		update(1, n, 1, t + 1, now, 1ll * nwa * nwb * nwc); now = t; 
		if(toa == t) nwa &= a[toa], posa = toa, toa = upda(x, toa); 
		if(tob == t) nwb |= b[tob], posb = tob, tob = updb(x, tob);
		if(toc == t) nwc = Gcd(nwc, c[toc]), posc = toc, toc = updc(x, toc);  
	} 
	update(1, n, 1, 1, now, 1ll * suma[x] * sumb[x] * sumc[x]); 
	for (auto v : G[x]) ans[v.id] = query(1, n, 1, v.x, x); 
	return ;
}
signed main()
{
	freopen("qwq.out", "r", stdin);
	freopen("1.out", "w", stdout);
	n = read(), m = read(); 
	for (int i = 1; i <= n; i++) a[i] = read();
	for (int i = 1; i <= n; i++) b[i] = read();
	for (int i = 1; i <= n; i++) c[i] = read();
	suma[1] = a[1], sumb[1] = b[1], sumc[1] = c[1];
	for (int i = 2; i <= n; i++) suma[i] = (suma[i - 1] & a[i]), sumb[i] = (sumb[i - 1] | b[i]), sumc[i] = Gcd(sumc[i - 1], c[i]);
	for (int i = 1; i <= m; i++) 
	{
		int l = read(), r = read(); 
		G[r].push_back(node{i, l}); 
	}
	for (int i = 1; i <= n; i++) 
	{
		A[i][0] = a[i], B[i][0] = b[i], C[i][0] = c[i];
		for (int j = 1; j <= 20; j++) 
			if((1 << j) <= i) 
			{
				A[i][j] = (A[i][j - 1] & A[i - (1 << (j - 1))][j - 1]); 
				B[i][j] = (B[i][j - 1] | B[i - (1 << (j - 1))][j - 1]); 
				C[i][j] = Gcd(C[i][j - 1], C[i - (1 << (j - 1))][j - 1]); 
			}
			else B[i][j] = (1 << 20) - 1, C[i][j] = 1; 
	}
	for (int i = 1; i <= n; i++) work(i);
	for (int i = 1; i <= m; i++) 
	{
		Write(ans[i]); puts("");
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

1000000 4999998
677759 16844 194149 882507 258413 301124 335220 853562 556891 940146 265534 89372 852421 821748 453468 389493 767295 749954 967376 543995 891396 399529 837606 300380 188426 701042 209657 534843 857430 548210 681875 715389 276811 492296 717786 463046 233941 281371 641808 990695 702677...

output:


result: