QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#417208#4322. rsraogps / 雪に咲く花YeahPotatoWA 1143ms175988kbC++142.2kb2024-05-22 16:12:542024-05-22 16:12:55

Judging History

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

  • [2024-05-22 16:12:55]
  • 评测
  • 测评结果:WA
  • 用时:1143ms
  • 内存:175988kb
  • [2024-05-22 16:12:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 I;
const int N = 1e6 + 6;
int n, q, a[N], b[N], c[N], l[N], top, aa[N], bb[N], cc[N], r[N], t[N], id[N];
ll v[N]; I d[N], s[N], h[N], ans[N*5]; basic_string <int> qry[N];
int read() {
	int s = 0; char ch = getchar();
	while (! isdigit(ch)) ch = getchar();
	while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
	return s;
}
void write(I x) {
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
I calc(int x, int i) {
	if (! x) return 0;
	int p = id[x];
	return h[p] + d[x] + (s[p] + (I) v[p] * (x - r[p-1])) * (i - t[p] + 1);
}
int main() {
	cin >> n >> q;
	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();
	for (int i=1; i<=q; i++)
		l[i] = read(), qry[read()] += i;
	for (int i=1; i<=n; i++) {
		top ++, aa[top] = a[i], bb[top] = b[i], cc[top] = c[i];
		v[top] = 1ll * a[i] * b[i] * c[i], r[top] = i, t[top] = i, id[i] = top;
		int j = top - 1;
		for (int g=c[i]; j; j--) {
			g = __gcd(g, cc[j]);
			if ((a[i] & aa[j]) != aa[j] || (b[i] | bb[j]) != bb[j] || g != cc[j]) {
				I _ = (I) v[j] * (i - t[j]), dd = _;
				for (int k=r[j-1]+1; k<=r[j]; k++, dd+=_) d[k] += dd;
				aa[j] &= a[i], bb[j] |= b[i], cc[j] = g;
				v[j] = 1ll * aa[j] * bb[j] * cc[j], t[j] = i;
			} else break;
		}
		int _top = j;
		for (j++; j<=top; j++)
			if (aa[j] == aa[_top] && bb[j] == bb[_top] && cc[j] == cc[_top]) {
				I _ = (I) v[j] * (i - t[_top]), dd = d[r[_top]] - _;
				for (int k=r[_top]+1; k<=r[j]; k++, dd-=_) d[k] += dd, id[k] = _top;
				r[_top] = r[j];
			} else {
				for (int k=r[_top]+1; k<=r[j]; k++) id[k] = _top + 1;
				_top ++, aa[_top] = aa[j], bb[_top] = bb[j], cc[_top] = cc[j];
				v[_top] = v[j], r[_top] = r[j], t[_top] = i;
				if (_top == 1) s[_top] = h[_top] = 0;
				else s[_top] = s[_top-1] + (I) v[_top-1] * (r[_top-1] - r[_top-2]), 
					 h[_top] = h[_top-1] + d[r[_top-1]] + (I) s[_top] * (t[_top] - t[_top-1]);
			}
		top = _top;
		I now = calc(i, i);
		for (int j : qry[i])
			ans[j] = now - calc(l[j] - 1, i);
	}
	for (int i=1; i<=q; i++)
		write(ans[i] & 4294967295), putchar('\n');
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1143ms
memory: 175988kb

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:

4073486545
3416579520
2222580839
2107635675
2662424587
3489821037
1131438368
2957845213
3828336393
3147377673
3324212425
3144716588
2967294697
1812583385
3927299798
1907609410
753806168
2418382245
1265641623
1927558094
3958897805
3981487386
1986747598
353481782
373921649
526287136
2106490964
2142884...

result:

wrong answer 1st lines differ - expected: '3578099829', found: '4073486545'