QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#54249 | #4879. Standard Problem | flower_and_qingyu# | RE | 178ms | 40808kb | C++23 | 2.4kb | 2022-10-07 17:19:23 | 2022-10-07 17:19:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 50;
const int mod = 998244353;
inline int inc(int x, int y) { x += y - mod; return x + (x >> 31 & mod); }
inline int dec(int x, int y) { x -= y; return x + (x >> 31 & mod); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
struct value_t {
long long val;
int ways;
value_t() : val(-1e18), ways(0) {}
value_t(long long val, int ways) : val(val), ways(ways) {}
value_t operator+(const value_t &rhs) const {
if (val > rhs.val)
return *this;
if (val < rhs.val)
return rhs;
return value_t(val, inc(ways, rhs.ways));
}
} t[N << 2];
long long tag[N << 2];
inline int lc(int o) { return o << 1; }
inline int rc(int o) { return o << 1 | 1; }
void push_up(int o) {
t[o] = t[lc(o)] + t[rc(o)];
}
void assign(int o, int64_t val) {
tag[o] += val;
t[o].val += val;
}
void push_down(int o) {
if (tag[o]) {
assign(lc(o), tag[o]);
assign(rc(o), tag[o]);
tag[o] = 0;
}
}
void build(int o, int l, int r) {
tag[o] = 0;
if (l == r) {
t[o] = value_t();
}
else {
const int mid = l + r >> 1;
build(lc(o), l, mid);
build(rc(o), mid + 1, r);
push_up(o);
}
}
void add(int o, int l, int r, int ql, int qr, int64_t val) {
if (ql <= l && r <= qr) {
assign(o, val);
return;
}
push_down(o);
const int mid = l + r >> 1;
if (ql <= mid) add(lc(o), l, mid, ql, qr, val);
if (qr > mid) add(rc(o), mid + 1, r, ql, qr, val);
push_up(o);
}
value_t query(int o, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr)
return t[o];
const int mid = l + r >> 1;
push_down(o);
value_t ans;
if (ql <= mid)
ans = ans + query(lc(o), l, mid, ql, qr);
if (qr > mid)
ans = ans + query(rc(o), mid + 1, r, ql, qr);
return ans;
}
void assign(int o, int l, int r, int p, value_t x) {
if (l == r) {
t[o] = x;
return;
}
const int mid = l + r >> 1;
push_down(o);
if (p <= mid) assign(lc(o), l, mid, p, x);
else assign(rc(o), mid + 1, r, p, x);
push_up(o);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
build(1, 1, m);
for (int i = 0; i < n; ++i) {
int l, r, c;
cin >> l >> r >> c;
auto t = value_t(0, 1) + query(1, 1, n, 1, l);
assign(1, 1, n, l, t);
add(1, 1, n, l, r, c);
}
cout << t[1].val << " " << t[1].ways << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 35240kb
input:
2 3 4 1 2 1 2 3 1 2 2 1 2 5 1 4 3 2 5 3
output:
3 1 6 1
result:
ok 4 number(s): "3 1 6 1"
Test #2:
score: 0
Accepted
time: 7ms
memory: 35108kb
input:
30 3 3 1 3 1 1 3 1 1 3 1 3 3 1 2 1 1 3 1 1 3 1 3 3 2 2 1 1 3 1 1 3 1 3 3 1 3 1 1 2 1 1 3 1 3 3 2 3 1 1 2 1 1 3 1 3 3 2 2 1 1 3 1 1 3 1 3 3 2 2 1 1 2 1 1 3 1 3 3 1 3 1 2 3 1 1 3 1 3 3 2 3 1 1 3 1 2 2 1 3 3 1 2 1 1 2 1 1 2 1 3 3 1 3 1 1 3 1 1 3 1 3 3 1 3 1 1 2 1 1 3 1 3 3 2 3 1 1 2 1 1 3 1 3 3 1 3 1 1...
output:
3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 2 2 3 1 3 1 3 1 3 1 2 2 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1
result:
ok 60 numbers
Test #3:
score: 0
Accepted
time: 7ms
memory: 35096kb
input:
20 5 5 1 5 1 1 5 1 1 4 1 1 5 1 1 5 1 5 5 2 4 1 1 5 1 1 5 1 2 4 1 2 4 1 5 5 2 4 1 1 5 1 1 5 1 2 5 1 1 3 1 5 5 1 5 1 1 5 1 2 3 1 1 5 1 1 4 1 5 5 1 4 1 1 4 1 2 5 1 1 3 1 2 4 1 5 5 2 4 1 3 3 1 1 3 1 2 4 1 4 4 1 5 5 3 3 1 1 4 1 3 3 1 2 5 1 2 5 1 5 5 2 4 1 2 3 1 4 4 1 2 4 1 2 4 1 5 5 3 3 1 3 3 1 2 4 1 1 4...
output:
5 1 5 1 5 1 5 1 5 1 5 1 5 1 5 1 4 1 5 1 5 1 5 1 5 1 5 1 4 1 5 1 5 1 5 1 5 1 5 1
result:
ok 40 numbers
Test #4:
score: 0
Accepted
time: 2ms
memory: 34872kb
input:
10 10 10 1 10 1 1 10 1 1 9 1 2 7 1 1 9 1 1 10 1 1 9 1 1 9 1 1 9 1 1 10 1 10 10 1 8 1 1 10 1 2 10 1 3 10 1 1 10 1 4 10 1 1 8 1 1 10 1 1 9 1 1 10 1 10 10 1 7 1 4 7 1 1 8 1 4 6 1 1 10 1 2 10 1 2 10 1 1 10 1 3 10 1 5 7 1 10 10 3 7 1 1 10 1 1 6 1 1 9 1 2 9 1 2 6 1 2 9 1 1 10 1 2 10 1 4 8 1 10 10 3 8 1 4 ...
output:
10 1 10 1 10 1 10 1 10 1 10 1 10 1 9 1 9 1 10 1
result:
ok 20 numbers
Test #5:
score: 0
Accepted
time: 65ms
memory: 34876kb
input:
10000 20 20 2 3 1 2 3 1 1 6 1 1 6 1 1 2 1 1 1 1 1 5 1 4 4 1 1 2 1 2 4 1 1 2 1 1 6 1 1 2 1 1 9 1 1 4 1 8 11 1 2 11 1 1 8 1 2 4 1 2 7 1 20 20 4 8 1 1 2 1 2 3 1 2 2 1 1 5 1 3 7 1 1 4 1 2 7 1 3 4 1 1 2 1 5 5 1 1 6 1 1 7 1 1 8 1 1 1 1 1 1 1 3 3 1 2 3 1 1 1 1 1 2 1 20 20 1 1 1 3 11 1 1 8 1 2 9 1 2 7 1 3 9...
output:
17 1 13 1 17 2 12 6 16 1 20 1 20 1 19 1 17 1 13 9 13 4 14 3 12 1 11 3 12 9 19 2 20 1 20 1 19 2 13 4 13 2 13 7 16 2 16 1 18 1 20 1 20 1 20 1 16 5 18 1 13 2 14 4 13 2 14 2 13 6 20 1 20 1 19 1 17 2 15 2 13 4 15 2 16 1 13 2 12 6 20 1 20 1 20 1 18 1 14 4 15 2 15 2 13 5 13 6 16 1 20 1 20 1 20 1 20 1 18 1 ...
result:
ok 20000 numbers
Test #6:
score: 0
Accepted
time: 93ms
memory: 35864kb
input:
1000 200 200 1 21 1 93 108 1 52 55 1 61 67 1 1 23 1 70 72 1 1 8 1 21 78 1 1 20 1 6 31 1 71 85 1 4 57 1 9 15 1 63 101 1 48 60 1 93 100 1 55 77 1 94 96 1 59 59 1 3 4 1 6 7 1 3 21 1 14 20 1 88 93 1 46 52 1 1 29 1 1 19 1 45 46 1 3 35 1 3 16 1 79 105 1 84 104 1 16 17 1 41 48 1 4 7 1 2 48 1 101 117 1 14 7...
output:
74 24 68 16 73 12 88 12 111 2 198 1 195 1 190 3 177 2 140 9 70 140 74 14 84 4 93 32 109 14 196 3 197 4 195 1 175 1 130 28 74 124 68 6 84 2 104 8 119 2 194 2 194 2 194 1 172 6 135 4 62 360 74 36 82 180 87 6 107 4 197 2 197 1 189 2 177 2 139 2 71 8 76 20 82 8 102 2 107 208 196 2 198 1 192 3 178 3 135 ...
result:
ok 2000 numbers
Test #7:
score: 0
Accepted
time: 161ms
memory: 38888kb
input:
1 200000 70000 3758 4743 1 33161 33877 1 24037 24952 1 33131 33134 1 24741 25130 1 12964 13639 1 32062 32778 1 12046 12449 1 28229 29159 1 12021 12282 1 5329 6033 1 16581 16923 1 30368 31177 1 29343 29965 1 32647 33027 1 25775 26193 1 878 1026 1 17927 17950 1 16554 16592 1 30029 30096 1 19536 19742 ...
output:
4170 745614878
result:
ok 2 number(s): "4170 745614878"
Test #8:
score: 0
Accepted
time: 147ms
memory: 39448kb
input:
1 200000 200000 78834 78835 1 80528 80530 1 47499 47503 1 65196 65198 1 36003 36005 1 79144 79146 1 91460 91460 1 87949 87951 1 97054 97054 1 99216 99219 1 1043 1046 1 25088 25089 1 59424 59428 1 78742 78744 1 46264 46265 1 44746 44750 1 84877 84881 1 24091 24094 1 35772 35774 1 77841 77841 1 96537 ...
output:
898 862947721
result:
ok 2 number(s): "898 862947721"
Test #9:
score: 0
Accepted
time: 164ms
memory: 40708kb
input:
1 200000 200000 70228 70241 1 2243 2290 1 37711 37751 1 65609 65630 1 35069 35114 1 55461 55502 1 45322 45352 1 63193 63237 1 47993 48004 1 77797 77807 1 65933 65943 1 50756 50758 1 89846 89848 1 40757 40796 1 32542 32568 1 71472 71518 1 36752 36753 1 78477 78511 1 64720 64750 1 17369 17372 1 51635 ...
output:
958 258160284
result:
ok 2 number(s): "958 258160284"
Test #10:
score: 0
Accepted
time: 178ms
memory: 40808kb
input:
1 200000 200000 75340 75924 1 89847 90265 1 59883 60818 1 26303 26836 1 83285 84012 1 51579 51933 1 83631 83730 1 34162 35024 1 82604 83469 1 22334 22878 1 39351 40150 1 74106 74554 1 6193 6244 1 16427 16530 1 20013 20625 1 34653 35093 1 83885 84698 1 66234 67215 1 35548 36129 1 998 1540 1 86220 871...
output:
2172 380312816
result:
ok 2 number(s): "2172 380312816"
Test #11:
score: 0
Accepted
time: 115ms
memory: 39236kb
input:
1 200000 200000 1 4 1 3 4 1 1 3 1 1 2 1 4 7 1 7 10 1 6 8 1 3 6 1 7 7 1 2 3 1 6 6 1 8 10 1 4 6 1 9 11 1 2 3 1 10 14 1 6 7 1 11 11 1 19 20 1 1 5 1 8 8 1 6 9 1 2 3 1 16 19 1 18 20 1 23 27 1 6 9 1 6 10 1 30 32 1 19 23 1 17 21 1 7 9 1 15 19 1 3 5 1 1 2 1 37 38 1 14 16 1 14 16 1 26 28 1 5 9 1 34 38 1 26 2...
output:
31676 227442792
result:
ok 2 number(s): "31676 227442792"
Test #12:
score: 0
Accepted
time: 136ms
memory: 40484kb
input:
1 200000 200000 2 16 1 3 24 1 3 21 1 5 36 1 3 30 1 6 45 1 7 17 1 6 46 1 4 28 1 1 11 1 11 26 1 9 51 1 1 18 1 9 41 1 8 23 1 10 10 1 1 41 1 5 27 1 16 55 1 20 27 1 10 53 1 12 52 1 20 32 1 1 3 1 1 49 1 24 65 1 20 56 1 18 29 1 11 32 1 20 48 1 3 22 1 20 53 1 32 76 1 4 43 1 17 37 1 34 74 1 12 17 1 32 68 1 1...
output:
68340 480122735
result:
ok 2 number(s): "68340 480122735"
Test #13:
score: 0
Accepted
time: 139ms
memory: 40164kb
input:
1 200000 200000 1 105 1 3 24 1 3 742 1 3 689 1 5 445 1 5 384 1 1 796 1 3 880 1 8 984 1 4 907 1 8 79 1 12 887 1 1 731 1 8 154 1 6 745 1 6 328 1 7 487 1 7 526 1 2 819 1 6 698 1 10 464 1 13 222 1 3 885 1 10 222 1 14 627 1 20 133 1 13 600 1 22 507 1 23 342 1 14 58 1 21 546 1 27 283 1 7 720 1 22 337 1 1 ...
output:
98727 824244096
result:
ok 2 number(s): "98727 824244096"
Test #14:
score: -100
Runtime Error
input:
1 79364 198410 79365 79366 1 79367 79368 1 79369 79370 1 79371 79372 1 79373 79374 1 79375 79376 1 79377 79378 1 79379 79380 1 79381 79382 1 79383 79384 1 79385 79386 1 79387 79388 1 79389 79390 1 79391 79392 1 79393 79394 1 79395 79396 1 79397 79398 1 79399 79400 1 79401 79402 1 79403 79404 1 79405...