# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1011585 |
2024-06-30T17:29:26 Z |
ByeWorld |
Toll (BOI17_toll) |
C++14 |
|
164 ms |
54184 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#define ll long long
#define int long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii, int> ipii;
typedef pair<vector<vector<int>>, int> iipii;
const int MAXN = 5e4+20;
const int MAXA = 9e3+20;
const ll INF = 1e18+10;
const int LOG = 19;
const int MOD = 1e15;
const int SQRT = 450;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const vector<int> dx = {1, -1, 0, 0};
const vector<int> dy = {0, 0, 1, -1};
void chmn(int &a, int b){
a = min(a, b);
}
int n, m, q, k;
vector<vector<int>> adj[MAXN];
vector<vector<int>> NOL;
struct seg {
vector<vector<int>> st[4*MAXN];
vector<vector<int>> mrg(vector<vector<int>> a, vector<vector<int>> b){
vector<vector<int>> ret = NOL;
for(int i=0; i<k; i++){
for(int j=0; j<k; j++){
for(int p=0; p<k; p++){
chmn(ret[i][j], a[i][p]+b[p][j]);
}
}
}
return ret;
}
void bd(int id, int l, int r){
if(l==r){
st[id] = adj[l]; return;
}
bd(lf, l, md); bd(rg, md+1, r);
st[id] = mrg(st[lf], st[rg]);
return;
}
iipii que(int id, int l, int r, int x, int y){
if(x<=l && r<=y) return iipii(st[id], 1);
if(r<x || y<l) return iipii(NOL, -1);
iipii le = que(lf,l,md,x,y);
iipii ri = que(rg,md+1,r,x,y);
if(le.se==-1) return ri;
if(ri.se==-1) return le;
return iipii(mrg(le.fi, ri.fi), 1);
}
} A;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> k >> n >> m >> q;
vector<int> TEM(k, INF); for(int i=0; i<k; i++) NOL.pb(TEM);
for(int i=1; i<=n; i++) adj[i] = NOL;
for(int i=1; i<=m; i++){
int x, y, w; cin >> x >> y >> w;
// cout << x/k+1 << " p\n";
chmn(adj[x/k+1][x%k][y%k], w);
}
A.bd(1, 1, n);
while(q--){
int a, b; cin >> a >> b;
if(a/k==b/k){
cout << "-1\n"; continue;
}
// cout << a/k+1 << ' ' << b/k << " que\n";
vector<vector<int>> ret = A.que(1,1,n,a/k+1, b/k).fi;
// cout << q << ' ' << ret[a%k][b%k] << " pp\n";
cout << (ret[a%k][b%k]>=MOD ? -1 : ret[a%k][b%k]) << '\n';
}
}
/*
5 14 5 5
0 5 9
5 12 10
0 7 7
7 12 8
4 7 10
0 12
0 5
0 7
7 12
0 13
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
15704 KB |
Output is correct |
2 |
Correct |
1 ms |
6236 KB |
Output is correct |
3 |
Correct |
1 ms |
6236 KB |
Output is correct |
4 |
Correct |
1 ms |
6236 KB |
Output is correct |
5 |
Correct |
3 ms |
6416 KB |
Output is correct |
6 |
Correct |
4 ms |
6492 KB |
Output is correct |
7 |
Correct |
3 ms |
6348 KB |
Output is correct |
8 |
Correct |
52 ms |
16648 KB |
Output is correct |
9 |
Correct |
57 ms |
16472 KB |
Output is correct |
10 |
Correct |
44 ms |
15708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
24920 KB |
Output is correct |
2 |
Correct |
2 ms |
6232 KB |
Output is correct |
3 |
Correct |
1 ms |
6236 KB |
Output is correct |
4 |
Correct |
2 ms |
6236 KB |
Output is correct |
5 |
Correct |
2 ms |
6232 KB |
Output is correct |
6 |
Correct |
1 ms |
6236 KB |
Output is correct |
7 |
Correct |
10 ms |
6420 KB |
Output is correct |
8 |
Correct |
14 ms |
6744 KB |
Output is correct |
9 |
Correct |
40 ms |
16568 KB |
Output is correct |
10 |
Correct |
89 ms |
34380 KB |
Output is correct |
11 |
Correct |
71 ms |
26708 KB |
Output is correct |
12 |
Correct |
86 ms |
33472 KB |
Output is correct |
13 |
Correct |
89 ms |
40936 KB |
Output is correct |
14 |
Correct |
51 ms |
23124 KB |
Output is correct |
15 |
Correct |
67 ms |
39844 KB |
Output is correct |
16 |
Correct |
85 ms |
39848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6236 KB |
Output is correct |
2 |
Correct |
2 ms |
6236 KB |
Output is correct |
3 |
Correct |
2 ms |
6236 KB |
Output is correct |
4 |
Correct |
2 ms |
6236 KB |
Output is correct |
5 |
Correct |
2 ms |
6236 KB |
Output is correct |
6 |
Correct |
2 ms |
6488 KB |
Output is correct |
7 |
Correct |
3 ms |
6492 KB |
Output is correct |
8 |
Correct |
4 ms |
7260 KB |
Output is correct |
9 |
Correct |
3 ms |
7260 KB |
Output is correct |
10 |
Correct |
30 ms |
16468 KB |
Output is correct |
11 |
Correct |
53 ms |
26524 KB |
Output is correct |
12 |
Correct |
68 ms |
34120 KB |
Output is correct |
13 |
Correct |
69 ms |
34368 KB |
Output is correct |
14 |
Correct |
80 ms |
33872 KB |
Output is correct |
15 |
Correct |
59 ms |
39760 KB |
Output is correct |
16 |
Correct |
59 ms |
39768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6236 KB |
Output is correct |
2 |
Correct |
2 ms |
6236 KB |
Output is correct |
3 |
Correct |
2 ms |
6236 KB |
Output is correct |
4 |
Correct |
2 ms |
6236 KB |
Output is correct |
5 |
Correct |
2 ms |
6236 KB |
Output is correct |
6 |
Correct |
2 ms |
6488 KB |
Output is correct |
7 |
Correct |
3 ms |
6492 KB |
Output is correct |
8 |
Correct |
4 ms |
7260 KB |
Output is correct |
9 |
Correct |
3 ms |
7260 KB |
Output is correct |
10 |
Correct |
30 ms |
16468 KB |
Output is correct |
11 |
Correct |
53 ms |
26524 KB |
Output is correct |
12 |
Correct |
68 ms |
34120 KB |
Output is correct |
13 |
Correct |
69 ms |
34368 KB |
Output is correct |
14 |
Correct |
80 ms |
33872 KB |
Output is correct |
15 |
Correct |
59 ms |
39760 KB |
Output is correct |
16 |
Correct |
59 ms |
39768 KB |
Output is correct |
17 |
Correct |
59 ms |
26452 KB |
Output is correct |
18 |
Correct |
3 ms |
6232 KB |
Output is correct |
19 |
Correct |
2 ms |
6236 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6236 KB |
Output is correct |
22 |
Correct |
2 ms |
6236 KB |
Output is correct |
23 |
Correct |
7 ms |
6492 KB |
Output is correct |
24 |
Correct |
13 ms |
6764 KB |
Output is correct |
25 |
Correct |
16 ms |
7260 KB |
Output is correct |
26 |
Correct |
13 ms |
7260 KB |
Output is correct |
27 |
Correct |
33 ms |
16464 KB |
Output is correct |
28 |
Correct |
83 ms |
34388 KB |
Output is correct |
29 |
Correct |
84 ms |
34384 KB |
Output is correct |
30 |
Correct |
79 ms |
33872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
15704 KB |
Output is correct |
2 |
Correct |
1 ms |
6236 KB |
Output is correct |
3 |
Correct |
1 ms |
6236 KB |
Output is correct |
4 |
Correct |
1 ms |
6236 KB |
Output is correct |
5 |
Correct |
3 ms |
6416 KB |
Output is correct |
6 |
Correct |
4 ms |
6492 KB |
Output is correct |
7 |
Correct |
3 ms |
6348 KB |
Output is correct |
8 |
Correct |
52 ms |
16648 KB |
Output is correct |
9 |
Correct |
57 ms |
16472 KB |
Output is correct |
10 |
Correct |
44 ms |
15708 KB |
Output is correct |
11 |
Correct |
57 ms |
24920 KB |
Output is correct |
12 |
Correct |
2 ms |
6232 KB |
Output is correct |
13 |
Correct |
1 ms |
6236 KB |
Output is correct |
14 |
Correct |
2 ms |
6236 KB |
Output is correct |
15 |
Correct |
2 ms |
6232 KB |
Output is correct |
16 |
Correct |
1 ms |
6236 KB |
Output is correct |
17 |
Correct |
10 ms |
6420 KB |
Output is correct |
18 |
Correct |
14 ms |
6744 KB |
Output is correct |
19 |
Correct |
40 ms |
16568 KB |
Output is correct |
20 |
Correct |
89 ms |
34380 KB |
Output is correct |
21 |
Correct |
71 ms |
26708 KB |
Output is correct |
22 |
Correct |
86 ms |
33472 KB |
Output is correct |
23 |
Correct |
89 ms |
40936 KB |
Output is correct |
24 |
Correct |
51 ms |
23124 KB |
Output is correct |
25 |
Correct |
67 ms |
39844 KB |
Output is correct |
26 |
Correct |
85 ms |
39848 KB |
Output is correct |
27 |
Correct |
2 ms |
6236 KB |
Output is correct |
28 |
Correct |
2 ms |
6236 KB |
Output is correct |
29 |
Correct |
2 ms |
6236 KB |
Output is correct |
30 |
Correct |
2 ms |
6236 KB |
Output is correct |
31 |
Correct |
2 ms |
6236 KB |
Output is correct |
32 |
Correct |
2 ms |
6488 KB |
Output is correct |
33 |
Correct |
3 ms |
6492 KB |
Output is correct |
34 |
Correct |
4 ms |
7260 KB |
Output is correct |
35 |
Correct |
3 ms |
7260 KB |
Output is correct |
36 |
Correct |
30 ms |
16468 KB |
Output is correct |
37 |
Correct |
53 ms |
26524 KB |
Output is correct |
38 |
Correct |
68 ms |
34120 KB |
Output is correct |
39 |
Correct |
69 ms |
34368 KB |
Output is correct |
40 |
Correct |
80 ms |
33872 KB |
Output is correct |
41 |
Correct |
59 ms |
39760 KB |
Output is correct |
42 |
Correct |
59 ms |
39768 KB |
Output is correct |
43 |
Correct |
59 ms |
26452 KB |
Output is correct |
44 |
Correct |
3 ms |
6232 KB |
Output is correct |
45 |
Correct |
2 ms |
6236 KB |
Output is correct |
46 |
Correct |
2 ms |
6492 KB |
Output is correct |
47 |
Correct |
2 ms |
6236 KB |
Output is correct |
48 |
Correct |
2 ms |
6236 KB |
Output is correct |
49 |
Correct |
7 ms |
6492 KB |
Output is correct |
50 |
Correct |
13 ms |
6764 KB |
Output is correct |
51 |
Correct |
16 ms |
7260 KB |
Output is correct |
52 |
Correct |
13 ms |
7260 KB |
Output is correct |
53 |
Correct |
33 ms |
16464 KB |
Output is correct |
54 |
Correct |
83 ms |
34388 KB |
Output is correct |
55 |
Correct |
84 ms |
34384 KB |
Output is correct |
56 |
Correct |
79 ms |
33872 KB |
Output is correct |
57 |
Correct |
164 ms |
54184 KB |
Output is correct |
58 |
Correct |
51 ms |
16472 KB |
Output is correct |
59 |
Correct |
84 ms |
26864 KB |
Output is correct |