ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#211270 | #2401. 移动 | _Alexande_ | 0 | 3339ms | 117592kb | C++11 | 7.7kb | 2024-08-10 11:15:08 | 2024-08-10 12:38:17 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define lep( i, l, r ) for ( int i = ( l ); i <= ( r ); ++ i )
#define rep( i, r, l ) for ( int i = ( r ); i >= ( l ); -- i )
typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
char _c; bool _f; template < class type > inline void read ( type &x ) {
_f = 0, x = 0;
while ( _c = getchar (), !isdigit ( _c ) ) if ( _c == '-' ) _f = 1;
while ( isdigit ( _c ) ) x = x * 10 + _c - '0', _c = getchar (); if ( _f ) { x = -x; }
}
template < class type > inline void chkmin ( type &x, type y ) { x = ( x <= y ? x : y ); }
template < class type > inline void chkmax ( type &x, type y ) { x = ( x >= y ? x : y ); }
const int N = 205;
const int M = 4e5 + 5;
int n, m, c, k, a, t;
int dis[N][N], p[M][5], res[5];
int tmp[5], link[5][5];
struct Node {
int val[5][5];
Node () {
for ( int i = 1; i <= k; i ++ ) {
for ( int j = 1; j <= k; j ++ ) {
val[i][j] = 1e18;
}
}
}
} tree[M << 2];
Node merge ( Node ls, Node rs, int lt, int rt, int mid ) {
memset ( link, 0x3f, sizeof ( link ) );
vector < int > f, g;
for ( int i = 1; i <= k; i ++ ) {
for ( int j = 1; j <= k; j ++ ) {
if ( dis[p[mid][i]][p[mid + 1][j]] < 1e9 ) {
f.clear (), g.clear ();
f.push_back ( 0 ), g.push_back ( 0 );
for ( int l = 1; l <= k; l ++ ) {
if ( l != i ) {
f.push_back ( l );
}
}
for ( int l = 1; l <= k; l ++ ) {
if ( l != j ) {
g.push_back ( l );
}
}
if ( k - 1 == 0 ) {
link[i][j] = min ( link[i][j], a * dis[p[mid][i]][p[mid + 1][j]] );
}
else if ( k - 1 == 1 ) {
link[i][j] = min ( link[i][j], a * dis[p[mid][i]][p[mid + 1][j]] + dis[p[mid][f[1]]][p[mid + 1][g[1]]] );
}
else if ( k - 1 == 2 ) {
link[i][j] = min ( link[i][j], a * dis[p[mid][i]][p[mid + 1][j]] + dis[p[mid][f[1]]][p[mid + 1][g[1]]] + dis[p[mid][f[2]]][p[mid + 1][g[2]]] );
link[i][j] = min ( link[i][j], a * dis[p[mid][i]][p[mid + 1][j]] + dis[p[mid][f[1]]][p[mid + 1][g[2]]] + dis[p[mid][f[2]]][p[mid + 1][g[1]]] );
}
else if ( k - 1 == 3 ) {
link[i][j] = min ( link[i][j], a * dis[p[mid][i]][p[mid + 1][j]] + dis[p[mid][f[1]]][p[mid + 1][g[1]]] + dis[p[mid][f[2]]][p[mid + 1][g[2]]] + dis[p[mid][f[3]]][p[mid + 1][g[3]]] );
link[i][j] = min ( link[i][j], a * dis[p[mid][i]][p[mid + 1][j]] + dis[p[mid][f[1]]][p[mid + 1][g[1]]] + dis[p[mid][f[2]]][p[mid + 1][g[3]]] + dis[p[mid][f[3]]][p[mid + 1][g[2]]] );
link[i][j] = min ( link[i][j], a * dis[p[mid][i]][p[mid + 1][j]] + dis[p[mid][f[1]]][p[mid + 1][g[2]]] + dis[p[mid][f[2]]][p[mid + 1][g[1]]] + dis[p[mid][f[3]]][p[mid + 1][g[3]]] );
link[i][j] = min ( link[i][j], a * dis[p[mid][i]][p[mid + 1][j]] + dis[p[mid][f[1]]][p[mid + 1][g[2]]] + dis[p[mid][f[2]]][p[mid + 1][g[3]]] + dis[p[mid][f[3]]][p[mid + 1][g[1]]] );
link[i][j] = min ( link[i][j], a * dis[p[mid][i]][p[mid + 1][j]] + dis[p[mid][f[1]]][p[mid + 1][g[3]]] + dis[p[mid][f[2]]][p[mid + 1][g[2]]] + dis[p[mid][f[3]]][p[mid + 1][g[1]]] );
link[i][j] = min ( link[i][j], a * dis[p[mid][i]][p[mid + 1][j]] + dis[p[mid][f[1]]][p[mid + 1][g[3]]] + dis[p[mid][f[2]]][p[mid + 1][g[1]]] + dis[p[mid][f[3]]][p[mid + 1][g[2]]] );
}
}
}
}
// cout << "cy\n";
// cout << mid << '\n';
// for ( int i = 1; i <= k; i ++ ) {
// for ( int j = 1; j <= k; j ++ ) {
// cout << link[i][j] << " ";
// }
// cout << '\n';
// }
Node ans;
if ( rt - lt + 1 <= 2 ) {
for ( int i = 1; i <= k; i ++ ) {
for ( int j = 1; j <= k; j ++ ) {
ans.val[i][j] = link[i][j];
}
}
}
else if ( mid - lt + 1 == 1 ) {
for ( int i = 1; i <= k; i ++ ) {
for ( int j = 1; j <= k; j ++ ) {
for ( int l = 1; l <= k; l ++ ) {
ans.val[i][j] = min ( ans.val[i][j], rs.val[j][l] + link[i][j] );
}
}
}
}
else if ( rt - mid == 1 ) {
for ( int i = 1; i <= k; i ++ ) {
for ( int j = 1; j <= k; j ++ ) {
for ( int l = 1; l <= k; l ++ ) {
ans.val[i][l] = min ( ans.val[i][l], ls.val[i][j] + link[j][l] );
}
}
}
}
else {
for ( int i = 1; i <= k; i ++ ) {
for ( int j = 1; j <= k; j ++ ) {
for ( int l = 1; l <= k; l ++ ) {
for ( int o = 1; o <= k; o ++ ) {
ans.val[i][o] = min ( ans.val[i][0], ls.val[i][j] + rs.val[l][o] + link[j][l] );
}
}
}
}
}
// cout << mid << '\n';
// for ( int i = 1; i <= k; i ++ ) {
// for ( int j = 1; j <= k; j ++ ) {
// cout << ans.val[i][j] << " ";
// }
// cout << '\n';
// }
return ans;
}
void build ( int node, int lt, int rt ) {
if ( lt == rt ) {
return ;
}
int mid = lt + rt >> 1;
build ( node << 1, lt, mid ), build ( node << 1 | 1, mid + 1, rt );
tree[node] = merge ( tree[node << 1], tree[node << 1 | 1], lt, rt, lt + rt >> 1 );
}
void update ( int node, int lt, int rt, int x ) {
if ( x < lt || x > rt ) {
return ;
}
if ( lt == rt && lt == x ) {
for ( int i = 1; i <= k; i ++ ) {
p[lt][i] = tmp[i];
}
return ;
}
int mid = lt + rt >> 1;
update ( node << 1, lt, mid, x ), update ( node << 1 | 1, mid + 1, rt, x );
tree[node] = merge ( tree[node << 1], tree[node << 1 | 1], lt, rt, lt + rt >> 1 );
}
Node query ( int node, int lt, int rt, int x, int y ) {
if ( x <= lt && rt <= y ) {
return tree[node];
}
int mid = lt + rt >> 1;
if ( x <= mid && mid + 1 <= y ) {
return merge ( query ( node << 1, lt, mid, x, y ), query ( node << 1 | 1, mid + 1, rt, x, y ), lt, rt, mid );
}
else if ( x <= mid ) {
return query ( node << 1, lt, mid, x, y );
}
else if ( mid + 1 <= y ) {
return query ( node << 1 | 1, mid + 1, rt, x, y );
}
}
void Solve () {
ios :: sync_with_stdio ( false );
cin.tie ( 0 ), cout.tie ( 0 );
cin >> n >> m >> c >> k >> a >> t;
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= n; j ++ ) {
if ( i != j ) {
dis[i][j] = 1e18;
}
}
}
for ( int i = 1; i <= m; i ++ ) {
int u, v, w;
cin >> u >> v >> w;
dis[u][v] = dis[v][u] = min ( dis[u][v], w );
}
for ( int k = 1; k <= n; k ++ ) {
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= n; j ++ ) {
dis[i][j] = min ( dis[i][j], dis[i][k] + dis[k][j] );
}
}
}
// for ( int i = 1; i <= n; i ++ ) {
// for ( int j = 1; j <= n; j ++ ) {
// cout << dis[i][j] << " ";
// }
// cout << '\n';
// }
for ( int i = 1; i <= c; i ++ ) {
for ( int j = 1; j <= k; j ++ ) {
cin >> p[i][j];
}
}
build ( 1, 1, c );
// for ( int i = 1; i < c; i ++ ) {
// cout << query ( 1, 1, c, i, i + 1 ).val[1][1] << " ";
// }
while ( t -- ) {
int op;
cin >> op;
if ( op == 1 ) {
int x;
cin >> x;
for ( int i = 1; i <= k; i ++ ) {
cin >> tmp[i];
}
update ( 1, 1, c, x );
}
else {
int l, r;
cin >> l >> r;
Node res = query ( 1, 1, c, l, r );
int ans = 1e18;
for ( int i = 1; i <= k; i ++ ) {
for ( int j = 1; j <= k; j ++ ) {
ans = min ( ans, res.val[i][j] );
}
}
cout << ans << '\n';
}
}
}
signed main () {
#ifdef judge
freopen ( "Code.in", "r", stdin );
freopen ( "Code.out", "w", stdout );
freopen ( "Code.err", "w", stderr );
#endif
Solve ();
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 1476kb
input:
100 4950 100 3 8 100 1 2 100000 1 3 100000 1 4 100000 1 5 100000 1 6 100000 1 7 100000 1 8 100000 1 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
result:
wrong answer 1st lines differ - expected: '19200000', found: '1'
Subtask #2:
score: 0
Wrong Answer
Test #10:
score: 0
Wrong Answer
time: 1670ms
memory: 117592kb
input:
100 4950 351493 3 10 100000 1 2 100000 1 3 100000 1 4 100000 1 5 100000 1 6 100000 1 7 100000 1 8 10...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 1st lines differ - expected: '240622197023', found: '1'
Subtask #3:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 955ms
memory: 117576kb
input:
100 4950 351493 1 10 100000 1 2 100000 1 3 100000 1 4 100000 1 5 100000 1 6 100000 1 7 100000 1 8 10...
output:
42700042706 77690036664 9333636831 20738125084 64049837786 31847538534 21324184309 5201176 527932037...
result:
wrong answer 1st lines differ - expected: '88025960740', found: '42700042706'
Subtask #4:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 700ms
memory: 117572kb
input:
100 4950 351493 1 10 100000 1 2 100000 1 3 100000 1 4 100000 1 5 100000 1 6 100000 1 7 100000 1 8 10...
output:
42700042706 77690036664 9333636831 20738125084 64049837786 31847538534 21324184309 5201176 527932037...
result:
wrong answer 1st lines differ - expected: '88025960740', found: '42700042706'
Subtask #5:
score: 0
Time Limit Exceeded
Test #46:
score: 0
Time Limit Exceeded
input:
100 4950 351493 3 10 100000 1 2 100000 1 3 100000 1 4 100000 1 5 100000 1 6 100000 1 7 100000 1 8 10...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
Subtask #6:
score: 0
Wrong Answer
Test #64:
score: 0
Wrong Answer
time: 9ms
memory: 1476kb
input:
100 4950 100 3 8 100 1 2 100000 1 3 100000 1 4 100000 1 5 100000 1 6 100000 1 7 100000 1 8 100000 1 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
result:
wrong answer 1st lines differ - expected: '19200000', found: '1'