QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#417179 | #4322. rsraogps / 雪に咲く花 | YeahPotato | WA | 1468ms | 154648kb | C++14 | 2.2kb | 2024-05-22 15:50:33 | 2024-05-22 15:50:35 |
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]; 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, r; i<=q; i++)
scanf ("%d%d", &l[i], &r), qry[r] += 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: 1468ms
memory: 154648kb
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:
6877444193108673469872231339946530159 ' 15515784022214070591608890703849830698 ) - 81078873260104118204885624480216645873 . 146486002608025829595954524642251015362 , 1629123019386223789908194 27552237346510877486048664193882432758 ) 122491332272343500422663789185196062134 . . 58100511470935387268299...
result:
wrong answer 1st lines differ - expected: '3578099829', found: '6877444193108673469872231339946530159'