# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
932347 |
2024-02-23T08:33:02 Z |
LOLOLO |
Toll (BOI17_toll) |
C++17 |
|
724 ms |
96848 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 5e4 + 10;
int k;
vector <pair <int, int>> ed[N];
struct node{
int l, r;
vector < vector <ll>> D;
void ass(int L, int R) {
l = L;
r = R;
D.assign(k * 2, vector <ll> (k * 2, 1e16));
for (int i = 0; i < k * 2; i++) {
for (int j = 0; j < k * 2; j++) {
if (l + i == r - j)
D[i][j] = 0;
}
}
}
void process() {
for (int i = 0; i < k * 2; i++) {
for (int j = i; j < k * 2; j++) {
if (j + l <= r && D[i][r - j - l] < 1e16) {
for (auto x : ed[j + l]) {
if (x.f <= r) {
D[i][r - x.f] = min(D[i][r - j - l] + x.s, D[i][r - x.f]);
}
}
}
}
}
}
} seg[N * 4];
node add(node &L, node &R) {
node M;
M.ass(L.l, R.r);
for (int i = 0; i < k * 2; i++) {
for (int j = 0; j < k * 2; j++) {
int x = R.r - j;
if (x < R.l) {
if (x >= L.l) {
for (int f = 0; f < k * 2; f++) {
M.D[i][j] = min(M.D[i][j], L.D[i][L.r - x]);
}
}
continue;
}
for (int f = 0; f < k * 2; f++) {
int id = L.r - f;
if (id >= L.l && i + L.l <= L.r && L.D[i][f] < 1e16) {
for (auto x : ed[id]) {
if (x.f >= R.l) {
M.D[i][j] = min(M.D[i][j], L.D[i][f] + x.s + R.D[x.f - R.l][j]);
}
}
}
}
}
if (i + L.l >= R.l) {
for (int j = 0; j < k * 2; j++)
M.D[i][j] = min(M.D[i][j], R.D[i + L.l - R.l][j]);
}
}
return M;
}
void build(int id, int l, int r) {
if (l == r) {
seg[id].ass(l, r);
return;
}
int m = (l + r) / 2;
build(id * 2, l, m);
build(id * 2 + 1, m + 1, r);
seg[id] = add(seg[id * 2], seg[id * 2 + 1]);
}
node get(int id, int l, int r, int u, int v) {
if (l >= u && r <= v) {
return seg[id];
}
int m = (l + r) / 2;
if (m >= v)
return get(id * 2, l, m, u, v);
if (m + 1 <= u)
return get(id * 2 + 1, m + 1, r, u, v);
node L = get(id * 2, l, m, u, v), R = get(id * 2 + 1, m + 1, r, u, v);
return add(L, R);
}
ll solve() {
int n, m, q;
cin >> k >> n >> m >> q;
for (int i = 1; i <= m; i++) {
int a, b, t;
cin >> a >> b >> t;
a++;
b++;
ed[a].pb({b, t});
}
build(1, 1, n);
for (int i = 1; i <= q; i++) {
int a, b;
cin >> a >> b;
a++;
b++;
auto t = get(1, 1, n, a, b);
ll d = t.D[0][0];
if (d >= 1e15) {
d = -1;
}
cout << d << '\n';
}
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
//cout << solve() << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
22748 KB |
Output is correct |
2 |
Correct |
2 ms |
7768 KB |
Output is correct |
3 |
Correct |
2 ms |
7772 KB |
Output is correct |
4 |
Correct |
2 ms |
7768 KB |
Output is correct |
5 |
Correct |
4 ms |
8028 KB |
Output is correct |
6 |
Correct |
4 ms |
8028 KB |
Output is correct |
7 |
Correct |
5 ms |
8024 KB |
Output is correct |
8 |
Correct |
91 ms |
22868 KB |
Output is correct |
9 |
Correct |
80 ms |
22776 KB |
Output is correct |
10 |
Correct |
58 ms |
20556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
40844 KB |
Output is correct |
2 |
Correct |
2 ms |
7768 KB |
Output is correct |
3 |
Correct |
2 ms |
7768 KB |
Output is correct |
4 |
Correct |
2 ms |
7896 KB |
Output is correct |
5 |
Correct |
3 ms |
7772 KB |
Output is correct |
6 |
Correct |
2 ms |
7892 KB |
Output is correct |
7 |
Correct |
12 ms |
8028 KB |
Output is correct |
8 |
Correct |
28 ms |
8512 KB |
Output is correct |
9 |
Correct |
57 ms |
22864 KB |
Output is correct |
10 |
Correct |
259 ms |
65876 KB |
Output is correct |
11 |
Correct |
117 ms |
40856 KB |
Output is correct |
12 |
Correct |
187 ms |
63872 KB |
Output is correct |
13 |
Correct |
339 ms |
84192 KB |
Output is correct |
14 |
Correct |
105 ms |
42804 KB |
Output is correct |
15 |
Correct |
242 ms |
81896 KB |
Output is correct |
16 |
Correct |
282 ms |
81744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7768 KB |
Output is correct |
2 |
Correct |
2 ms |
7772 KB |
Output is correct |
3 |
Correct |
2 ms |
7772 KB |
Output is correct |
4 |
Correct |
3 ms |
7772 KB |
Output is correct |
5 |
Correct |
2 ms |
7772 KB |
Output is correct |
6 |
Correct |
3 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8540 KB |
Output is correct |
8 |
Correct |
11 ms |
10332 KB |
Output is correct |
9 |
Correct |
8 ms |
9560 KB |
Output is correct |
10 |
Correct |
40 ms |
22612 KB |
Output is correct |
11 |
Correct |
77 ms |
40476 KB |
Output is correct |
12 |
Correct |
132 ms |
65532 KB |
Output is correct |
13 |
Correct |
142 ms |
66204 KB |
Output is correct |
14 |
Correct |
124 ms |
64976 KB |
Output is correct |
15 |
Correct |
150 ms |
81744 KB |
Output is correct |
16 |
Correct |
132 ms |
81744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7768 KB |
Output is correct |
2 |
Correct |
2 ms |
7772 KB |
Output is correct |
3 |
Correct |
2 ms |
7772 KB |
Output is correct |
4 |
Correct |
3 ms |
7772 KB |
Output is correct |
5 |
Correct |
2 ms |
7772 KB |
Output is correct |
6 |
Correct |
3 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8540 KB |
Output is correct |
8 |
Correct |
11 ms |
10332 KB |
Output is correct |
9 |
Correct |
8 ms |
9560 KB |
Output is correct |
10 |
Correct |
40 ms |
22612 KB |
Output is correct |
11 |
Correct |
77 ms |
40476 KB |
Output is correct |
12 |
Correct |
132 ms |
65532 KB |
Output is correct |
13 |
Correct |
142 ms |
66204 KB |
Output is correct |
14 |
Correct |
124 ms |
64976 KB |
Output is correct |
15 |
Correct |
150 ms |
81744 KB |
Output is correct |
16 |
Correct |
132 ms |
81744 KB |
Output is correct |
17 |
Correct |
101 ms |
40568 KB |
Output is correct |
18 |
Correct |
2 ms |
7772 KB |
Output is correct |
19 |
Correct |
2 ms |
7772 KB |
Output is correct |
20 |
Correct |
2 ms |
7772 KB |
Output is correct |
21 |
Correct |
2 ms |
7772 KB |
Output is correct |
22 |
Correct |
2 ms |
7772 KB |
Output is correct |
23 |
Correct |
9 ms |
8028 KB |
Output is correct |
24 |
Correct |
15 ms |
8536 KB |
Output is correct |
25 |
Correct |
137 ms |
10332 KB |
Output is correct |
26 |
Correct |
70 ms |
9652 KB |
Output is correct |
27 |
Correct |
52 ms |
22608 KB |
Output is correct |
28 |
Correct |
200 ms |
65872 KB |
Output is correct |
29 |
Correct |
191 ms |
66132 KB |
Output is correct |
30 |
Correct |
192 ms |
64852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
22748 KB |
Output is correct |
2 |
Correct |
2 ms |
7768 KB |
Output is correct |
3 |
Correct |
2 ms |
7772 KB |
Output is correct |
4 |
Correct |
2 ms |
7768 KB |
Output is correct |
5 |
Correct |
4 ms |
8028 KB |
Output is correct |
6 |
Correct |
4 ms |
8028 KB |
Output is correct |
7 |
Correct |
5 ms |
8024 KB |
Output is correct |
8 |
Correct |
91 ms |
22868 KB |
Output is correct |
9 |
Correct |
80 ms |
22776 KB |
Output is correct |
10 |
Correct |
58 ms |
20556 KB |
Output is correct |
11 |
Correct |
129 ms |
40844 KB |
Output is correct |
12 |
Correct |
2 ms |
7768 KB |
Output is correct |
13 |
Correct |
2 ms |
7768 KB |
Output is correct |
14 |
Correct |
2 ms |
7896 KB |
Output is correct |
15 |
Correct |
3 ms |
7772 KB |
Output is correct |
16 |
Correct |
2 ms |
7892 KB |
Output is correct |
17 |
Correct |
12 ms |
8028 KB |
Output is correct |
18 |
Correct |
28 ms |
8512 KB |
Output is correct |
19 |
Correct |
57 ms |
22864 KB |
Output is correct |
20 |
Correct |
259 ms |
65876 KB |
Output is correct |
21 |
Correct |
117 ms |
40856 KB |
Output is correct |
22 |
Correct |
187 ms |
63872 KB |
Output is correct |
23 |
Correct |
339 ms |
84192 KB |
Output is correct |
24 |
Correct |
105 ms |
42804 KB |
Output is correct |
25 |
Correct |
242 ms |
81896 KB |
Output is correct |
26 |
Correct |
282 ms |
81744 KB |
Output is correct |
27 |
Correct |
2 ms |
7768 KB |
Output is correct |
28 |
Correct |
2 ms |
7772 KB |
Output is correct |
29 |
Correct |
2 ms |
7772 KB |
Output is correct |
30 |
Correct |
3 ms |
7772 KB |
Output is correct |
31 |
Correct |
2 ms |
7772 KB |
Output is correct |
32 |
Correct |
3 ms |
8028 KB |
Output is correct |
33 |
Correct |
4 ms |
8540 KB |
Output is correct |
34 |
Correct |
11 ms |
10332 KB |
Output is correct |
35 |
Correct |
8 ms |
9560 KB |
Output is correct |
36 |
Correct |
40 ms |
22612 KB |
Output is correct |
37 |
Correct |
77 ms |
40476 KB |
Output is correct |
38 |
Correct |
132 ms |
65532 KB |
Output is correct |
39 |
Correct |
142 ms |
66204 KB |
Output is correct |
40 |
Correct |
124 ms |
64976 KB |
Output is correct |
41 |
Correct |
150 ms |
81744 KB |
Output is correct |
42 |
Correct |
132 ms |
81744 KB |
Output is correct |
43 |
Correct |
101 ms |
40568 KB |
Output is correct |
44 |
Correct |
2 ms |
7772 KB |
Output is correct |
45 |
Correct |
2 ms |
7772 KB |
Output is correct |
46 |
Correct |
2 ms |
7772 KB |
Output is correct |
47 |
Correct |
2 ms |
7772 KB |
Output is correct |
48 |
Correct |
2 ms |
7772 KB |
Output is correct |
49 |
Correct |
9 ms |
8028 KB |
Output is correct |
50 |
Correct |
15 ms |
8536 KB |
Output is correct |
51 |
Correct |
137 ms |
10332 KB |
Output is correct |
52 |
Correct |
70 ms |
9652 KB |
Output is correct |
53 |
Correct |
52 ms |
22608 KB |
Output is correct |
54 |
Correct |
200 ms |
65872 KB |
Output is correct |
55 |
Correct |
191 ms |
66132 KB |
Output is correct |
56 |
Correct |
192 ms |
64852 KB |
Output is correct |
57 |
Correct |
724 ms |
96848 KB |
Output is correct |
58 |
Correct |
71 ms |
22864 KB |
Output is correct |
59 |
Correct |
160 ms |
41188 KB |
Output is correct |