QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#203173 | #4253. Robot | KHIN | 40 | 770ms | 125736kb | C++17 | 4.6kb | 2023-10-06 15:57:38 | 2023-10-06 15:57:38 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
namespace kh {
constexpr int N(100'000);
constexpr int C(100'000);
constexpr int Q(500'000);
constexpr long T(1'000'000'000);
struct lfn {
long a, b;
constexpr lfn() : a(), b() {}
constexpr lfn(long const b) : a(), b(b) {}
constexpr lfn(long const a, long const b) : a(a), b(b) {}
constexpr long operator()(long const x) const { return a * x + b; }
};
class segtree0 {
struct info {
int p; lfn f;
info() = default;
info(int p, lfn f) : p(p), f(f) {}
};
int q;
long x[Q];
lfn fn[Q];
lfn fx[Q];
vector<vector<info>> hn;
vector<vector<info>> hx;
public:
void init(int const q, long const* const x) {
assert(is_sorted(x, x + q));
memcpy(this->x, x, sizeof(long) * (this->q = q));
}
void ins(lfn const f) {
// fprintf(stderr, "ins %li %li\n", f.a, f.b);
hn.emplace_back();
hx.emplace_back();
lfn g;
g = f;
for (int l(0), r(q); l != r;) {
// fprintf(stderr, "l, r : %i, %i\n", l, r);
int const m((l + r) / 2);
if (long const x(this->x[m]); g(x) < fn[m](x))
hn.back().emplace_back(m, fn[m]), swap(fn[m], g);
if (g.a > fn[m].a) { r = m + 0; continue; }
if (g.a < fn[m].a) { l = m + 1; continue; }
break;
}
g = f;
for (int l(0), r(q); l != r;) {
// fprintf(stderr, "l, r : %i, %i\n", l, r);
int const m((l + r) / 2);
if (long const x(this->x[m]); g(x) > fn[m](x))
hx.back().emplace_back(m, fx[m]), swap(fx[m], g);
if (g.a < fx[m].a) { r = m + 0; continue; }
if (g.a > fn[m].a) { l = m + 1; continue; }
break;
}
}
long query(int const p) const {
// cerr << __func__ << '\n';
int l(0), r(q);
long res(0);
while (l != r) {
// fprintf(stderr, "l, r : %i, %i\n", l, r);
int const m((l + r) / 2);
res = max(res, -fn[m](x[p]));
res = max(res, +fx[m](x[p]));
if (p < m) { r = m + 0; continue; }
if (p > m) { l = m + 1; continue; }
break;
}
// fprintf(stderr, "query %i : %li\n", p, res);
return res;
}
void undo(int const k = 1) {
// fprintf(stderr, "undo %i\n", k);
for (int j(0); j != k; ++j) {
for (info const& i : hn.back()) fn[i.p] = i.f;
for (info const& i : hx.back()) fx[i.p] = i.f;
hn.pop_back(), hx.pop_back();
}
}
};
class segtree1 {
int q;
long x[Q];
vector<lfn> f[4 * Q];
segtree0 seg;
long res[Q];
void ins(int x, int l, int r, int tl, int tr, lfn g) {
if (tl <= l && r <= tr) return f[x].emplace_back(g), void();
if (tr <= l || r <= tl) return;
ins(x << 1 | 0, l, (l + r) / 2, tl, tr, g);
ins(x << 1 | 1, (l + r) / 2, r, tl, tr, g);
}
void se(int const x, int const l, int const r) {
for (lfn const f : f[x]) seg.ins(f);
if (r - l == 1) res[l] = seg.query(l);
else {
se(x << 1 | 0, l, (l + r) / 2);
se(x << 1 | 1, (l + r) / 2, r);
}
seg.undo(f[x].size());
}
public:
void init(int const q, long const* const x) {
memcpy(this->x, x, sizeof(long) * (this->q = q));
assert(is_sorted(x, x + q)), seg.init(q, x);
}
void ins(lfn const f, long const l, long const r) {
int const i(lower_bound(x, x + q, l) - x);
int const j(upper_bound(x, x + q, r) - x);
// fprintf(stderr, "[%li, %li] : %li %li\n", l, r, f.a, f.b);
// fprintf(stderr, "-> %i, %i\n", i, j);
ins(1, 0, q, i, j, f);
}
void se() { se(1, 0, q); }
long const& operator[](int const i) const { return res[i]; }
};
int n, m, c, q;
long a[N + 1];
long ct[C];
int ck[C];
long cx[C];
long lst[N + 1];
lfn cur[N + 1];
long t[Q];
segtree1 seg;
void main() {
cin >> n >> m;
for (int i(1); i <= n; ++i)
cin >> a[i], cur[i] = a[i];
for (int i(0); i != m; ++i) {
long t; char s[8];
switch (cin >> t >> s, s[0]) {
case 'c': cin >> ck[c] >> cx[c], ct[c++] = t; break;
case 'q': kh::t[q++] = t; break;
}
}
seg.init(q, t);
for (int i(0); i != c; ++i) {
seg.ins(cur[ck[i]], lst[ck[i]], ct[i]), lst[ck[i]] = ct[i];
cur[ck[i]] = lfn(cx[i], cur[ck[i]](ct[i]) - ct[i] * cx[i]);
}
for (int i(1); i <= n; ++i) seg.ins(cur[i], lst[i], T);
seg.se();
for (int i(0); i != q; ++i) cout << seg[i] << '\n';
}
}
int main() { kh::main(); }
详细
Test #1:
score: 0
Wrong Answer
time: 14ms
memory: 77992kb
input:
1999 2000 199 8854 -9513 9848 8434 -6615 -6770 4057 -9730 686 1586 6806 -511 -6328 -2250 2785 -4083 -3961 -711 9606 -9391 1041 -2844 -4889 993 -6955 -1982 -5300 9053 -5275 3950 -7977 -3652 8624 -716 -2013 -5229 -3686 -4602 -5031 9777 3802 491 -1354 -26 -3366 5285 5805 -7098 2233 -5967 -1318 -4553 63...
output:
86968438 360434523 838136414 913544563 969488608 1039885818 1109817781 1176515896 1251176599 1310476524 1510654766 1541254290 1558186230 1650869534 1683894444 1758250067 1785951331 1924000031 1993298953 2050165865 2254081337 2698178666 2750011758 2975976887 3216807039 3276625600 3332455240 335270492...
result:
wrong answer 74th numbers differ - expected: '6989710672', found: '6983751831'
Test #2:
score: 0
Wrong Answer
time: 11ms
memory: 77972kb
input:
1999 2000 6817 4353 -8180 954 -2553 1768 4986 -889 7032 -450 1234 -7637 9636 380 3607 -2296 -4881 -9025 2375 -1561 -8807 -3103 4385 8883 -2887 -1185 1960 6711 3478 -1056 -1717 -534 -9885 -6301 6011 5965 -9833 -5181 5329 3688 -6837 9023 64 -8326 3021 -7193 -9218 -4699 2354 -4720 1621 7361 -5233 9211 ...
output:
9984 6877566 19288910 55025322 107854958 134986598 145516466 162179306 245223062 449495371 579270371 680620171 691440721 916515321 994219221 1088623821 1106452221 1194699221 1241337671 1340915371 1413759421 1576022921 1664672671 1707990671 1778999971 1838562221 1977886871 2055492321 2318326971 23506...
result:
wrong answer 1st numbers differ - expected: '9999', found: '9984'
Test #3:
score: 10
Accepted
time: 171ms
memory: 105400kb
input:
99659 99039 -39276177 -64464963 -70081363 -443045475 -655771408 -409419920 -285052520 -312069074 -936205590 -10621715 -908116392 -660740279 -953732094 -591542519 -194540162 -139991296 -705911340 -778931920 -474438963 -518208970 -59960466 -981034014 -514533441 -217486555 -711871023 -615144144 -631291...
output:
999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 999962473 ...
result:
ok 49673 numbers
Test #4:
score: 10
Accepted
time: 424ms
memory: 110680kb
input:
99572 579859 -100705410 -669206879 -432488010 -384767624 -742351351 -839681487 -968882737 -976751481 57117493 -959321678 -819420190 -325014480 -636525861 -382469947 -876672604 -213012287 -209210199 -875230847 -920443172 -731589320 -946964322 -789362448 -872075805 -828546101 51836817 -913319025 -8404...
output:
999981953 999981953 999981953 999981953 999981953 999981953 999981953 999981953 999981953 999981953 999981953 999981953 999981953 999981953 999981953 999964257 999964257 999964257 999964257 999964257 999964257 999964257 999964257 999959652 999959652 999959652 999959652 999959652 999959652 999959652 ...
result:
ok 480125 numbers
Test #5:
score: 10
Accepted
time: 402ms
memory: 110532kb
input:
99320 577219 -525813544 -959369807 -718451747 -533082399 -787662356 -531754846 -650759294 -381852570 -979346470 -644489626 -425559804 -332888497 -203462089 -292970440 -958637976 -533593640 53499163 -331134986 -296264838 -806780896 -651958364 -547743072 -590243769 -75974484 -843772303 -367318307 -443...
output:
999992360 999992301 999992301 999992301 999992301 999992301 999992301 999992301 999992301 999992301 999991856 999987050 999984469 999983401 999980820 999978927 999978927 999978927 999978927 999978927 999978927 999978927 999978927 999978927 999978927 999978927 999978927 999978927 999978927 999978927 ...
result:
ok 478076 numbers
Test #6:
score: 0
Wrong Answer
time: 102ms
memory: 98240kb
input:
90498 99230 -33558917 30715649 81001133 -12438113 81315374 -70949846 -71212693 66569129 -16194103 -63049353 -79869090 97189792 61301532 53180861 -26423528 -30279746 32502058 7951680 -97121356 -5044511 -4113729 82719257 96311627 80260870 -29075735 -31473462 -27928703 81572824 -89715849 85470402 -5284...
output:
106162364 109925960 118234906 121367000 126950298 127385670 131531644 136824694 139373310 142012380 151153204 153389704 159335812 164235238 167092988 175428672 184580430 185865672 186596262 195286804 204059848 206569698 213013800 220209366 225761850 229889932 231119510 233514056 239911440 243446104 ...
result:
wrong answer 1st numbers differ - expected: '106294952', found: '106162364'
Test #7:
score: 0
Wrong Answer
time: 104ms
memory: 99772kb
input:
99124 99428 -29121705 73122072 14759978 -93785828 -52964748 50664810 -67789167 38732351 -57330970 48764999 -73647685 92261655 2267455 -21312555 -51092994 33675829 40607569 -85559394 -93024695 24124094 -45466947 -66665193 -99870070 -58435829 -56724651 -98854388 86610996 59912463 -27223092 85984568 94...
output:
106340510 113640698 116739890 122754640 124220766 127865950 128705560 135657138 142279746 142690222 150231982 157449682 162202562 171120104 179745010 181387896 184482178 193596120 200146060 208222028 209548710 211674740 212319914 221084264 224026336 229799514 237891194 247535419 248911115 249266967 ...
result:
wrong answer 7th numbers differ - expected: '128706392', found: '128705560'
Test #8:
score: 10
Accepted
time: 264ms
memory: 111344kb
input:
99538 99031 -501609067 -774687736 -928215759 -477038092 -823455674 -871460165 -852927043 -704708804 -775793387 -521621627 -923721630 -811686668 -952989802 -841891941 -482572032 -509003031 -595485934 -831251065 -616219801 -580804479 -951849211 -783134298 -505096225 -625789647 -520043618 -798430551 -6...
output:
999996555 999996555 999996555 999996555 999996555 999996555 999996555 999996555 999996555 999996555 999996555 999996555 999996555 1003771859 1005263811 1005937379 1006453139 1010634605 1020280585 1024269825 1028141905 1038638165 1047767365 1050993325 1054639205 1056180845 1067217665 1072164485 10888...
result:
ok 49771 numbers
Test #9:
score: 0
Wrong Answer
time: 770ms
memory: 125648kb
input:
99483 590517 -508842 -191922 830365 -321837 163127 -225035 -3981 -222030 721775 -244372 -342954 -692168 -156349 -853744 -606213 687012 -401837 -920227 -198596 -14000 -345069 -628969 -386394 -590462 97339 -974255 -551821 -623120 -673402 -567398 278012 511781 29418 -975780 -416796 902045 -565858 -2455...
output:
999991 999991 1007282 1017211 1027140 1056927 1056927 1076785 1076785 1076785 1086714 1096643 1146288 1146288 1156217 1186004 1195933 1195933 1195933 1195933 1205862 1205862 1235649 1235649 1245578 1245578 1245578 1245578 1245578 1255507 1265436 1265436 1285294 1295223 1305152 1315081 1325010 135479...
result:
wrong answer 3989th numbers differ - expected: '9997315', found: '9994689'
Test #10:
score: 0
Wrong Answer
time: 756ms
memory: 125736kb
input:
99801 597343 -32417 984702 259080 747296 807167 169192 454040 -426594 582296 321692 800273 962596 -968901 42596 -304443 574664 936854 271860 902411 38804 -688175 55613 31189 -930407 -544084 -164683 -442201 118338 -858190 -109300 682685 896380 -887043 357053 -908865 890420 -680972 632527 -106741 -668...
output:
999982 999982 999982 999982 1009495 1019216 1019216 1028937 1058100 1067821 1077542 1096984 1096984 1096984 1096984 1096984 1106705 1145589 1145589 1145589 1155310 1155310 1155310 1155310 1165031 1165031 1174752 1174752 1184473 1184473 1184473 1203915 1203915 1213636 1213636 1213636 1213636 1233078 ...
result:
wrong answer 1st numbers differ - expected: '999992', found: '999982'