QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#417197 | #4322. rsraogps / 雪に咲く花 | YeahPotato | WA | 1253ms | 175832kb | C++14 | 2.2kb | 2024-05-22 16:03:40 | 2024-05-22 16:03:40 |
Judging History
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]), putchar('\n');
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1253ms
memory: 175832kb
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:
67523889008476123068625 26874983979621873409472 3463168822645293180007 68543767663038248777691 64187474245404115165195 3040928632557363425645 23155239492727577010464 24492087177704769397469 19259351977904326035209 3589121570440859954185 33258346891255851742409 38707153001318217453868 328407867349664...
result:
wrong answer 1st lines differ - expected: '3578099829', found: '67523889008476123068625'