QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#21588 | #2849. 弗雷兹的玩具商店 | gogo# | AC ✓ | 545ms | 322448kb | C++20 | 3.2kb | 2022-03-07 15:35:51 | 2022-05-08 03:40:29 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i ++)
#define per(i, r, l) for(int i = (r); i >= (l); i --)
#define trv(i, u, v) for(int i = head[u], v = e[i].to; i; v = e[i = e[i].nxt].to)
#define fi first
#define se second
#define all(s) s.begin(), s.end()
#define sz(s) (int)(s.size())
#define lb(s) ((s) & -(s))
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
mt19937_64 hua(time(0));
template<typename T> inline bool chkmx(T &x, T y) {return x < y ? x = y, 1 : 0;}
template<typename T> inline bool chkmn(T &x, T y) {return y < x ? x = y, 1 : 0;}
template<int T> using A = array<int, T>;
inline int read() {
int x = 0, f = 1; char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = 0;
for(; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return f ? x : -x;
}
const int maxm = 70;
const int maxn = 2e5;
const ll inf = 1e18;
int n, m, q, c[maxn + 5], v[maxn + 5];
struct Tag {
ll d, c;
friend Tag operator + (Tag x, Tag y) {
return (Tag){x.d + y.d, (x.c + y.c) % m};
}
};
struct Node {
ll mx[maxm + 5];
friend Node operator + (Node x, Node y) {
Node z;
rep(i, 1, m) {
z.mx[i] = max(x.mx[i], y.mx[i]);
}
return z;
}
friend Node operator + (Node x, Tag y) {
Node z;
rep(i, 1, m) {
z.mx[i + y.c > m ? i + y.c - m : i + y.c] = x.mx[i] + y.d;
}
return z;
}
};
struct Segment{
#define ls u << 1
#define rs u << 1 | 1
#define mid (l + r >> 1)
Node a[maxn + 5 << 2];
Tag tag[maxn + 5 << 2];
void seta(int u, Tag k) {a[u] = a[u] + k, tag[u] = tag[u] + k;}
void pushdown(int u) {
if(tag[u].c || tag[u].d) {
seta(ls, tag[u]), seta(rs, tag[u]);
tag[u] = {0, 0};
}
}
void build(int u, int l, int r) {
if(l == r) {
rep(i, 1, m) a[u].mx[i] = -inf;
a[u].mx[c[l]] = v[l];
return ;
}
build(ls, l, mid), build(rs, mid + 1, r);
a[u] = a[ls] + a[rs];
}
void upd(int u, int l, int r, int ql, int qr, Tag x) {
if(l >= ql && r <= qr) return seta(u, x);
pushdown(u);
if(qr <= mid) upd(ls, l, mid, ql, qr, x);
else if(ql > mid) upd(rs, mid + 1, r, ql, qr, x);
else upd(ls, l, mid, ql, qr, x), upd(rs, mid + 1, r, ql, qr, x);
a[u] = a[ls] + a[rs];
}
Node qry(int u, int l, int r, int ql, int qr) {
if(l >= ql && r <= qr) return a[u];
pushdown(u);
if(qr <= mid) return qry(ls, l, mid, ql, qr);
else if(ql > mid) return qry(rs, mid + 1, r, ql, qr);
else return qry(ls, l, mid, ql, qr) + qry(rs, mid + 1, r, ql, qr);
}
}ds;
ll f[maxm + 5];
int main() {
//freopen("in.txt", "r", stdin);
n = read(), m = read();
rep(i, 1, n) c[i] = read();
rep(i, 1, n) v[i] = read();
ds.build(1, 1, n);
q = read();
rep(i, 1, q) {
int opt = read(), l = read(), r = read();
if(opt == 1) {
int d = read();
ds.upd(1, 1, n, l, r, {0, d});
}
else if(opt == 2) {
int d = read();
ds.upd(1, 1, n, l, r, {d, 0});
}
else if(opt == 3) {
Node x = ds.qry(1, 1, n, l, r);
rep(i, 0, m) f[i] = 0;
rep(i, 1, m) {
rep(j, 0, m - i) {
chkmx(f[i + j], f[j] + x.mx[i]);
}
}
ll sum = 0, xr = 0;
rep(i, 1, m) sum += f[i], xr ^= f[i];
cout << sum << ' ' << xr << '\n';
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7812kb
input:
4 10 1 6 10 2 100 2333 666 300 7 3 1 4 3 1 3 1 2 4 1 3 1 4 2 2 3 -1000 2 2 3 -600 3 2 4
output:
15165 2865 14165 2169 36630 798 4899 1273
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 419ms
memory: 322180kb
input:
200000 60 21 16 58 5 26 44 30 40 31 27 50 21 59 50 37 39 26 9 15 14 9 59 40 29 32 5 2 25 57 18 4 9 25 1 13 42 36 34 21 6 53 2 18 51 51 55 29 17 3 36 22 11 26 1 40 58 57 33 22 53 42 26 1 6 18 6 47 54 31 59 51 23 60 1 13 43 55 34 59 49 9 12 51 34 4 22 31 1 47 45 45 28 10 38 34 19 35 12 4 5 11 47 28 2 ...
output:
304478979 5965183 302725180 6346266 263891804 12270170 206665590 7376160 224407908 12588660 302401755 6812441 298016030 8641780 187482000 7499280 276575975 13386421 302685395 8377169 304347825 5950953 296928490 9925716 273952510 11264178 185846328 1238664 276368626 13405014 200927082 49156 84257215 ...
result:
ok 12000 lines
Test #3:
score: 0
Accepted
time: 395ms
memory: 321844kb
input:
200000 60 57 29 46 22 35 43 48 2 13 60 12 52 47 43 49 57 30 17 40 4 20 14 35 21 33 8 35 59 60 41 18 56 2 3 17 36 45 57 29 50 56 41 41 42 23 29 31 44 45 10 40 56 16 14 9 48 13 43 38 12 16 55 7 17 58 15 44 42 3 13 31 58 45 3 32 59 23 54 42 59 55 13 47 10 26 55 58 30 29 27 41 44 22 39 52 11 46 36 44 48...
output:
245896079 6068859 7453280730 109395456 299208442 12214644 15727298160 338668128 300735460 5273264 104504104 2951944 6429284100 14749696 5195500 207820 300832767 4973071 76444590 0 8389986360 180213040 14910263550 222855612 1135513960 40554070 3213555030 6818364 16545690630 605369404 628381762 122970...
result:
ok 11923 lines
Test #4:
score: 0
Accepted
time: 545ms
memory: 321600kb
input:
200000 60 17 3 45 43 24 16 55 11 42 51 41 6 34 59 21 19 13 35 3 14 43 16 3 39 2 24 13 29 53 1 31 9 3 7 44 19 22 38 21 56 29 1 53 54 60 13 12 4 48 6 18 22 22 12 53 15 35 57 43 28 57 5 28 52 11 11 2 24 41 22 19 1 14 4 54 5 16 57 9 55 54 18 17 7 21 9 21 55 57 55 14 54 51 42 37 53 44 38 17 16 51 27 16 4...
output:
304366111 5999263 303982560 5326968 4499488710 95327356 17018778570 854203488 17018778570 854203488 16228225890 4704768 16228225890 4704768 16914258120 283903424 17400178020 35520992 14496800670 499908668 9098146950 430211132 14899327470 232956940 3442777170 133538416 15824033790 268612028 177867417...
result:
ok 11986 lines
Test #5:
score: 0
Accepted
time: 455ms
memory: 322448kb
input:
200000 60 24 42 26 35 33 51 57 27 20 47 20 15 27 34 48 10 30 51 26 12 40 52 38 51 35 24 46 11 51 28 28 6 10 53 40 34 36 36 60 47 15 11 53 33 36 40 34 5 23 59 9 54 42 46 45 9 10 22 19 52 50 38 49 51 22 20 24 57 48 15 35 2 17 28 26 52 7 59 48 21 49 56 15 31 34 51 39 43 12 49 26 53 26 6 35 39 25 58 36 ...
output:
300623925 8478447 288038958 5549058 299253584 10401260 301351350 6564740 296935022 13146298 1953430200 65114340 8665750950 24440384 6713799690 48314464 2792329380 96287220 294004077 14653557 17155891320 980795632 11188713330 304365680 282263336 6494582 17178325290 978450432 17884674180 522191360 760...
result:
ok 11948 lines
Test #6:
score: 0
Accepted
time: 211ms
memory: 312536kb
input:
200000 60 35 45 19 30 4 18 58 12 5 20 33 21 55 50 23 24 18 19 8 9 37 25 33 1 4 52 31 14 44 18 1 10 54 11 39 50 29 28 1 25 47 25 46 41 6 60 56 24 18 56 32 54 20 56 46 24 48 17 29 23 26 21 25 20 32 55 9 52 23 1 16 9 25 53 42 22 52 29 45 10 24 8 55 36 4 41 51 43 57 11 57 22 31 21 33 54 16 33 37 30 33 5...
output:
304285716 6096866 303953352 5280862 303500343 6133699 304255551 6280473 304341230 6119124 302277595 6814259 304332500 6073362 304342564 6082334 303668399 5820953 304285716 6096866 304334020 6118902 304353284 6107710 304353284 6107710 304297840 6124550 304342564 6082334 304236428 5250414 304297840 61...
result:
ok 30000 lines
Test #7:
score: 0
Accepted
time: 382ms
memory: 315184kb
input:
200000 60 4 29 15 53 55 33 30 8 53 27 34 10 31 7 52 20 11 37 32 4 57 42 12 1 22 4 24 56 45 47 13 40 16 27 24 2 52 53 1 44 20 34 45 42 32 36 2 35 4 33 38 60 6 49 52 19 45 16 15 21 2 19 52 9 46 16 10 37 60 10 12 11 36 56 53 7 23 54 41 18 18 11 18 23 51 9 33 35 24 47 47 18 58 39 26 43 54 36 11 45 37 14...
output:
304679290 5861350 304679290 5861350 304679290 5861350 304679290 5861350 304911989 5985233 9228424650 471883872 17198909130 1051959648 17197231020 1050677880 15691097100 402528376 15450693660 503977624 17463550920 50382272 15260382810 1447936 11285756400 334537184 16504138650 545371264 10862887320 51...
result:
ok 12108 lines
Test #8:
score: 0
Accepted
time: 293ms
memory: 322256kb
input:
200000 60 60 48 42 53 59 1 19 21 33 55 23 33 25 38 60 37 33 35 22 51 35 34 19 37 24 59 45 8 45 20 14 36 59 56 28 50 56 38 10 28 32 24 52 48 54 43 16 26 10 38 16 44 11 26 20 26 24 56 33 60 15 39 35 5 34 54 54 21 31 56 48 54 19 31 33 12 13 48 29 14 17 44 57 27 1 16 45 24 3 9 15 17 47 49 14 20 42 7 40 ...
output:
281075081 9400269 304394633 5970735 292007564 1248934 296038582 11214564 296771657 10524421 196910269 6675189 303972890 5248928 282720698 13506650 303600239 5095147 124599690 4487720 222667140 7752616 268438502 8498696 146797408 8638254 236547710 9375160 304517066 5984200 299186274 9823392 304532989...
result:
ok 29693 lines
Test #9:
score: 0
Accepted
time: 296ms
memory: 322036kb
input:
200000 60 57 59 20 41 4 17 5 22 47 30 12 11 37 58 50 27 45 59 5 15 27 16 2 16 5 1 41 14 29 52 58 17 51 18 50 46 26 54 7 12 15 11 15 43 60 4 10 36 2 14 42 21 21 36 36 26 36 16 31 4 7 28 12 49 37 1 34 2 47 33 14 53 35 20 36 26 23 37 1 16 50 42 36 3 17 11 20 52 18 50 47 17 17 51 5 46 43 31 47 21 55 52 ...
output:
240392587 4080701 270792477 12211235 288950001 16341277 303890277 5559017 131207805 7382481 295377969 2645227 51316260 0 288755220 16413406 291716450 8634408 301578913 6512093 304238124 5735536 156620145 4655415 304277747 5716267 197870376 3876326 300454814 6777642 303704370 5539792 303868511 510707...
result:
ok 29687 lines
Test #10:
score: 0
Accepted
time: 367ms
memory: 320696kb
input:
200000 60 30 6 48 9 8 32 17 20 4 37 36 10 13 19 42 39 7 58 41 47 50 27 41 43 27 19 28 40 48 35 36 17 32 23 18 31 47 34 42 50 2 18 51 15 28 33 53 34 30 33 13 11 51 53 53 9 3 20 40 50 46 15 58 17 38 7 39 16 32 21 5 34 30 48 48 57 20 32 31 41 56 43 52 46 27 36 46 29 56 25 10 33 39 59 42 8 6 20 23 37 40...
output:
304750529 5905713 304731691 5898747 303531075 5539909 304712730 5932120 302205678 6426704 304639086 5861140 303950390 5653200 304705218 5933568 304187944 5826486 303550859 5552799 304699554 5910242 302799932 7872088 304270018 6078266 304764722 5904658 304626540 5775464 304617484 5789068 304731691 58...
result:
ok 29702 lines
Test #11:
score: 0
Accepted
time: 326ms
memory: 321948kb
input:
200000 60 32 50 37 60 33 22 42 13 51 5 37 21 18 12 47 25 13 52 19 8 10 16 19 54 2 51 25 35 20 26 14 44 15 50 43 40 11 16 52 54 20 28 6 37 39 44 54 44 35 12 43 44 19 53 30 20 43 54 46 55 11 59 30 18 49 12 57 51 19 48 36 38 7 33 7 45 16 52 20 51 3 3 26 13 55 47 32 30 33 9 24 43 7 53 60 47 56 56 38 6 3...
output:
304242958 6195622 301753463 7201295 304275309 6197211 290861765 188173 52975201 8227571 259224251 9982269 304275309 6197211 281101128 9017074 303167210 7667784 119589030 0 272686737 9035605 267702692 14765706 300340348 7570818 39089944 2577362 241241740 8172400 251133247 2584233 282104088 4732710 30...
result:
ok 29716 lines
Test #12:
score: 0
Accepted
time: 434ms
memory: 320712kb
input:
200000 60 19 31 52 25 50 11 38 6 53 56 31 49 26 54 54 5 29 58 59 36 12 2 55 18 58 22 31 29 36 10 15 46 40 58 2 22 8 39 27 53 34 49 41 52 34 26 56 2 23 46 38 26 39 24 43 28 45 5 56 12 15 3 50 46 52 51 7 52 22 26 44 47 14 16 38 48 41 34 41 55 11 10 20 50 25 54 17 2 59 5 13 13 7 2 50 50 45 49 41 6 14 1...
output:
227711393 11681881 296150005 9928609 243438164 11190766 2871764100 39907840 282261747 2525509 291924336 2078514 2965174620 124313752 991137600 33037920 95967922 4585038 1269356916 26251776 10328139360 342936512 859875660 8978500 1244552251 66707129 5908783500 196959450 17004667440 839685088 11024888...
result:
ok 282 lines
Test #13:
score: 0
Accepted
time: 443ms
memory: 322308kb
input:
200000 60 48 32 21 53 19 44 22 15 17 20 34 9 22 47 52 58 5 33 17 33 40 39 5 23 28 58 51 36 43 3 5 30 34 17 14 44 52 35 50 9 46 23 17 60 1 60 57 58 33 13 30 4 52 26 18 11 23 8 39 5 10 43 26 35 51 40 11 43 14 60 51 52 15 7 51 7 6 47 4 30 59 34 33 42 51 50 45 14 49 23 10 50 5 36 17 55 15 19 29 20 18 19...
output:
16216693230 132905996 3469643834 120688982 1254705300 43265700 17977232 0 17592496380 574640248 216488580 2097232 8078452650 61440 9091773060 159748096 16759368750 352822860 1363290580 17115136 17248178220 606840 10714801890 497102592 4621453388 247432572 17819818980 584198880 15552999810 503727104 ...
result:
ok 327 lines
Test #14:
score: 0
Accepted
time: 544ms
memory: 320772kb
input:
200000 60 60 53 5 11 11 58 22 20 53 21 54 20 50 39 10 9 22 52 14 19 14 21 40 59 42 4 13 57 4 60 27 3 53 23 5 55 12 27 14 5 39 59 16 29 30 25 37 51 9 50 1 22 11 33 12 44 36 25 32 39 16 50 33 60 4 29 55 16 47 60 20 26 59 27 46 28 51 22 10 59 3 10 12 5 42 16 48 9 32 19 39 47 8 3 47 12 32 33 19 18 32 30...
output:
17891048070 520635964 17660301540 587410144 17969560560 463602144 17414010990 34605580 16875537150 320208828 17435315850 63599712 17221897590 1054363740 17562193410 576094592 17684543550 574503996 17402994390 36042812 17266339140 640 17189449860 984089088 17705200590 559736140 16606523490 576495616 ...
result:
ok 305 lines
Test #15:
score: 0
Accepted
time: 459ms
memory: 320624kb
input:
200000 60 43 33 11 49 50 10 9 9 28 43 36 19 32 42 39 39 2 22 30 15 11 57 1 3 37 48 30 50 14 24 45 48 49 48 28 38 49 36 39 16 11 14 34 42 55 4 13 49 26 42 3 28 38 3 30 14 51 51 55 56 7 32 43 55 11 10 24 59 38 54 14 48 7 39 21 54 42 33 42 59 14 44 27 51 39 48 56 21 39 43 16 45 6 50 31 16 51 46 14 28 4...
output:
16985317020 858360216 86207796 4079458 13272415380 322965952 16597946280 585139200 16180252440 121450992 7841621370 197002752 17585509440 585230336 5315227680 113317888 16777235040 361853888 16982813580 818955512 16029112740 65540832 17373480150 65143868 3293617530 68175360 204251859 9726279 1389070...
result:
ok 309 lines