# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1101948 |
2024-10-17T08:34:00 Z |
InvMOD |
Toll (BOI17_toll) |
C++14 |
|
165 ms |
59224 KB |
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define int long long
using namespace std;
template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}
const int N = 5e5+5, Q = 1e6+5;
const int K = 6, inf = 1e15+1;
struct Query{
int a,b,id;
Query(int a = 0, int b = 0, int id = 0): a(a), b(b), id(id) {}
};
int n, m, q, k;
int answer[N], d[11][N];
vector<pair<int,int>> adj[N], r_adj[N];
void Dnc(int l, int r, vector<Query>& Q){
if(l == r){
for(Query cur_q : Q){
answer[cur_q.id] = 0;
}
return;
}
int m = l+r>>1;
for(int i = l; i <= r; i++){
for(int j = 0; j < 2*k; j++){
d[j][i] = inf;
}
}
for(int id = 0, i = max(l, m-k*2+1); i <= m; i++, id++){
for(pair<int,int> e : adj[i]){
int v = e.fi, w = e.se;
if(v > m){
d[id][i] = 0;
ckmn(d[id][v], w);
}
}
}
for(int i = m; i >= l; i--){
for(pair<int,int> e : r_adj[i]){
int v = e.fi, w = e.se;
for(int j = 0; j < 2*k; j++){
ckmn(d[j][v], d[j][i] + w);
}
}
}
for(int i = m+1; i <= r; i++){
for(pair<int,int> e : adj[i]){
int v = e.fi, w = e.se;
for(int j = 0; j < 2*k; j++){
ckmn(d[j][v], d[j][i] + w);
}
}
}
vector<Query> Qleft, Qright;
for(Query cur_q : Q){
int l = cur_q.a, r = cur_q.b;
if(l <= m && r > m){
for(int i = 0; i < 2*k; i++){
ckmn(answer[cur_q.id], d[i][l] + d[i][r]);
}
}
else{
if(r <= m){
Qleft.pb(cur_q);
}
else Qright.pb(cur_q);
}
}
Dnc(l, m, Qleft);
Dnc(m+1, r, Qright);
return;
}
void solve()
{
cin >> k >> n >> m >> q;
for(int i = 1; i <= m; i++){
int a,b,t; cin >> a >> b >> t;
adj[a].pb(make_pair(b, t));
r_adj[b].pb(make_pair(a, t));
}
vector<Query> Q;
for(int i = 1; i <= q; i++){
int a,b; cin >> a >> b;
Q.pb(Query(a, b, i));
answer[i] = inf;
}
Dnc(0, n, Q);
for(int i = 1; i <= q; i++){
cout << (answer[i] == inf ? -1 : answer[i]) <<"\n";
} cout <<"\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
solve();
return 0;
}
Compilation message
toll.cpp: In function 'void Dnc(long long int, long long int, std::vector<Query>&)':
toll.cpp:33:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | int m = l+r>>1;
| ~^~
toll.cpp: In function 'int32_t main()':
toll.cpp:119:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
119 | freopen(name".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:120:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
120 | freopen(name".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
33072 KB |
Output is correct |
2 |
Correct |
7 ms |
29264 KB |
Output is correct |
3 |
Correct |
6 ms |
29264 KB |
Output is correct |
4 |
Correct |
7 ms |
29264 KB |
Output is correct |
5 |
Correct |
5 ms |
29264 KB |
Output is correct |
6 |
Correct |
7 ms |
29264 KB |
Output is correct |
7 |
Correct |
6 ms |
29264 KB |
Output is correct |
8 |
Correct |
27 ms |
32984 KB |
Output is correct |
9 |
Correct |
29 ms |
32840 KB |
Output is correct |
10 |
Correct |
10 ms |
29776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
38984 KB |
Output is correct |
2 |
Correct |
6 ms |
29264 KB |
Output is correct |
3 |
Correct |
6 ms |
33360 KB |
Output is correct |
4 |
Correct |
6 ms |
37456 KB |
Output is correct |
5 |
Correct |
7 ms |
41552 KB |
Output is correct |
6 |
Correct |
7 ms |
45896 KB |
Output is correct |
7 |
Correct |
8 ms |
29776 KB |
Output is correct |
8 |
Correct |
8 ms |
34128 KB |
Output is correct |
9 |
Correct |
27 ms |
32844 KB |
Output is correct |
10 |
Correct |
87 ms |
50000 KB |
Output is correct |
11 |
Correct |
54 ms |
39248 KB |
Output is correct |
12 |
Correct |
52 ms |
46156 KB |
Output is correct |
13 |
Correct |
117 ms |
59224 KB |
Output is correct |
14 |
Correct |
58 ms |
47076 KB |
Output is correct |
15 |
Correct |
60 ms |
54100 KB |
Output is correct |
16 |
Correct |
62 ms |
53840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29264 KB |
Output is correct |
2 |
Correct |
5 ms |
33360 KB |
Output is correct |
3 |
Correct |
6 ms |
37628 KB |
Output is correct |
4 |
Correct |
7 ms |
41600 KB |
Output is correct |
5 |
Correct |
7 ms |
45660 KB |
Output is correct |
6 |
Correct |
5 ms |
29408 KB |
Output is correct |
7 |
Correct |
8 ms |
33372 KB |
Output is correct |
8 |
Correct |
10 ms |
45916 KB |
Output is correct |
9 |
Correct |
8 ms |
41820 KB |
Output is correct |
10 |
Correct |
31 ms |
32348 KB |
Output is correct |
11 |
Correct |
59 ms |
38484 KB |
Output is correct |
12 |
Correct |
88 ms |
49248 KB |
Output is correct |
13 |
Correct |
90 ms |
50252 KB |
Output is correct |
14 |
Correct |
72 ms |
47952 KB |
Output is correct |
15 |
Correct |
65 ms |
53840 KB |
Output is correct |
16 |
Correct |
62 ms |
53840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29264 KB |
Output is correct |
2 |
Correct |
5 ms |
33360 KB |
Output is correct |
3 |
Correct |
6 ms |
37628 KB |
Output is correct |
4 |
Correct |
7 ms |
41600 KB |
Output is correct |
5 |
Correct |
7 ms |
45660 KB |
Output is correct |
6 |
Correct |
5 ms |
29408 KB |
Output is correct |
7 |
Correct |
8 ms |
33372 KB |
Output is correct |
8 |
Correct |
10 ms |
45916 KB |
Output is correct |
9 |
Correct |
8 ms |
41820 KB |
Output is correct |
10 |
Correct |
31 ms |
32348 KB |
Output is correct |
11 |
Correct |
59 ms |
38484 KB |
Output is correct |
12 |
Correct |
88 ms |
49248 KB |
Output is correct |
13 |
Correct |
90 ms |
50252 KB |
Output is correct |
14 |
Correct |
72 ms |
47952 KB |
Output is correct |
15 |
Correct |
65 ms |
53840 KB |
Output is correct |
16 |
Correct |
62 ms |
53840 KB |
Output is correct |
17 |
Correct |
54 ms |
38472 KB |
Output is correct |
18 |
Correct |
6 ms |
29264 KB |
Output is correct |
19 |
Correct |
5 ms |
33360 KB |
Output is correct |
20 |
Correct |
6 ms |
37628 KB |
Output is correct |
21 |
Correct |
6 ms |
41552 KB |
Output is correct |
22 |
Correct |
7 ms |
45648 KB |
Output is correct |
23 |
Correct |
8 ms |
29520 KB |
Output is correct |
24 |
Correct |
6 ms |
33764 KB |
Output is correct |
25 |
Correct |
10 ms |
46160 KB |
Output is correct |
26 |
Correct |
9 ms |
41808 KB |
Output is correct |
27 |
Correct |
26 ms |
32668 KB |
Output is correct |
28 |
Correct |
86 ms |
49524 KB |
Output is correct |
29 |
Correct |
102 ms |
50504 KB |
Output is correct |
30 |
Correct |
93 ms |
47944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
33072 KB |
Output is correct |
2 |
Correct |
7 ms |
29264 KB |
Output is correct |
3 |
Correct |
6 ms |
29264 KB |
Output is correct |
4 |
Correct |
7 ms |
29264 KB |
Output is correct |
5 |
Correct |
5 ms |
29264 KB |
Output is correct |
6 |
Correct |
7 ms |
29264 KB |
Output is correct |
7 |
Correct |
6 ms |
29264 KB |
Output is correct |
8 |
Correct |
27 ms |
32984 KB |
Output is correct |
9 |
Correct |
29 ms |
32840 KB |
Output is correct |
10 |
Correct |
10 ms |
29776 KB |
Output is correct |
11 |
Correct |
56 ms |
38984 KB |
Output is correct |
12 |
Correct |
6 ms |
29264 KB |
Output is correct |
13 |
Correct |
6 ms |
33360 KB |
Output is correct |
14 |
Correct |
6 ms |
37456 KB |
Output is correct |
15 |
Correct |
7 ms |
41552 KB |
Output is correct |
16 |
Correct |
7 ms |
45896 KB |
Output is correct |
17 |
Correct |
8 ms |
29776 KB |
Output is correct |
18 |
Correct |
8 ms |
34128 KB |
Output is correct |
19 |
Correct |
27 ms |
32844 KB |
Output is correct |
20 |
Correct |
87 ms |
50000 KB |
Output is correct |
21 |
Correct |
54 ms |
39248 KB |
Output is correct |
22 |
Correct |
52 ms |
46156 KB |
Output is correct |
23 |
Correct |
117 ms |
59224 KB |
Output is correct |
24 |
Correct |
58 ms |
47076 KB |
Output is correct |
25 |
Correct |
60 ms |
54100 KB |
Output is correct |
26 |
Correct |
62 ms |
53840 KB |
Output is correct |
27 |
Correct |
5 ms |
29264 KB |
Output is correct |
28 |
Correct |
5 ms |
33360 KB |
Output is correct |
29 |
Correct |
6 ms |
37628 KB |
Output is correct |
30 |
Correct |
7 ms |
41600 KB |
Output is correct |
31 |
Correct |
7 ms |
45660 KB |
Output is correct |
32 |
Correct |
5 ms |
29408 KB |
Output is correct |
33 |
Correct |
8 ms |
33372 KB |
Output is correct |
34 |
Correct |
10 ms |
45916 KB |
Output is correct |
35 |
Correct |
8 ms |
41820 KB |
Output is correct |
36 |
Correct |
31 ms |
32348 KB |
Output is correct |
37 |
Correct |
59 ms |
38484 KB |
Output is correct |
38 |
Correct |
88 ms |
49248 KB |
Output is correct |
39 |
Correct |
90 ms |
50252 KB |
Output is correct |
40 |
Correct |
72 ms |
47952 KB |
Output is correct |
41 |
Correct |
65 ms |
53840 KB |
Output is correct |
42 |
Correct |
62 ms |
53840 KB |
Output is correct |
43 |
Correct |
54 ms |
38472 KB |
Output is correct |
44 |
Correct |
6 ms |
29264 KB |
Output is correct |
45 |
Correct |
5 ms |
33360 KB |
Output is correct |
46 |
Correct |
6 ms |
37628 KB |
Output is correct |
47 |
Correct |
6 ms |
41552 KB |
Output is correct |
48 |
Correct |
7 ms |
45648 KB |
Output is correct |
49 |
Correct |
8 ms |
29520 KB |
Output is correct |
50 |
Correct |
6 ms |
33764 KB |
Output is correct |
51 |
Correct |
10 ms |
46160 KB |
Output is correct |
52 |
Correct |
9 ms |
41808 KB |
Output is correct |
53 |
Correct |
26 ms |
32668 KB |
Output is correct |
54 |
Correct |
86 ms |
49524 KB |
Output is correct |
55 |
Correct |
102 ms |
50504 KB |
Output is correct |
56 |
Correct |
93 ms |
47944 KB |
Output is correct |
57 |
Correct |
165 ms |
54852 KB |
Output is correct |
58 |
Correct |
40 ms |
32844 KB |
Output is correct |
59 |
Correct |
57 ms |
39180 KB |
Output is correct |