QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#418213 | #4322. rsraogps / 雪に咲く花 | oscaryangzj | ML | 2351ms | 517748kb | C++17 | 3.2kb | 2024-05-23 11:45:52 | 2024-05-23 11:45:52 |
Judging History
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 <pair <int, ll> > q[N];
vc <pair <int, ll> > o[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 ;
o[L].pb (mkp (l, v));
o[R + 1].pb (mkp (l, - v));
}
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;
}
}
}
}
inline void calc () {
rep (i, 1, n) {
for (auto [u, v] : o[i])
K.add (u, v), B.add (u, (i128) v * (ll) (1 - i));
for (auto [l, id] : q[i])
ans[id] = K.ask (l) * (ll) i + B.ask (l);
}
}
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[r].pb (mkp (l, i));
prework ();
calc ();
rep (i, 1, m) write (ans[i]), putchar (10);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1752ms
memory: 299836kb
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:
3578099829 247368737 4134953488 123772255 4271316421 2664004035 1981625521 4161064085 2301764273 3633218207 446408196 4089220553 2146535877 2604957438 3629218607 861849275 2324734025 926506509 652453278 2182055877 4151704810 1597517111 4271912484 2355275472 3461746888 548698842 2016320224 3911771642...
result:
ok 4999998 lines
Test #2:
score: 0
Accepted
time: 2351ms
memory: 517748kb
input:
999998 4999996 148476 933817 864076 191969 417231 462700 788827 950163 335378 379496 488829 873292 674723 936352 247899 950658 425452 840996 362963 260838 362545 281279 425178 922053 555678 230269 421254 27589 706638 989848 143104 701781 516547 911894 563207 927853 991791 523934 307480 220695 177834...
output:
4047299131 1051838109 3042044620 1558935111 1922407201 1863823247 2914705420 2124780582 4203879976 1785092444 2759734979 4070466544 1369322115 1659410325 4213137446 1668610392 1639252119 1374451942 2112308793 2665853985 2065466007 1116739408 1109187438 2946166785 1779189545 243189148 3803243245 2351...
result:
ok 4999996 lines
Test #3:
score: -100
Memory Limit Exceeded
input:
1000000 4999995 931616 451627 120237 821848 952685 820911 815844 532508 577534 854247 662620 828334 73938 275051 693099 935029 7291 912115 629721 109400 854959 821474 633595 172529 811334 202115 216622 710254 430042 382387 231224 945397 487320 601716 141624 713279 35449 454713 718139 667184 647847 1...
output:
1854807511 1453890769 829715466 2750235612 2667615988 2011865121 3886268553 81652698 2457883979 3659326530 3810577703 1430781613 2476318782 355131279 1910386131 1675955906 73042715 2580008178 3970786863 1183731076 431877656 1623138021 4112331510 1909031133 2098507060 1572114178 943542298 2024138600 ...