Submission #896348

# Submission time Handle Problem Language Result Execution time Memory
896348 2024-01-01T09:51:33 Z pcc Toll (BOI17_toll) C++14
0 / 100
122 ms 246704 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>

const int mxc = 5;
const int mxn = 5e5+10;
const int inf = 1e9;

struct mat{
	int arr[mxc][mxc];
	mat(){
		for(auto &i:arr)for(auto &j:i)j = inf;
	}
	int* operator[](int k){
		return (int*)arr[k];
	}
	mat operator*(mat b)const{
		mat re = mat();
		for(int i = 0;i<mxc;i++)for(int j = 0;j<mxc;j++)for(int k = 0;k<mxc;k++){
			re[j][k] = min(re[j][k],arr[j][i]+b[i][k]);
		}
		return re;
	}
};

int N,K,Q,M,blk;
mat segtree[mxn*4];
mat paths[mxn];

void build(int now,int l,int r){
	if(l == r){
		segtree[now] = paths[l];
		return;
	}
	int mid = (l+r)>>1;
	build(now*2+1,l,mid);
	build(now*2+2,mid+1,r);
	segtree[now] = segtree[now*2+1]*segtree[now*2+2];
	return;
}

mat getval(int now,int l,int r,int s,int e){
	if(l>=s&&e>=r)return segtree[now];
	int mid = (l+r)>>1;
	if(mid>=e)return getval(now*2+1,l,mid,s,e);
	else if(mid<e)return getval(now*2+2,mid+1,r,s,e);
	else return getval(now*2+1,l,mid,s,e)*getval(now*2+2,mid+1,r,s,e);
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>K>>N>>M>>Q;
	int blk = (N+K-1)/K;
	for(int i = 0;i<M;i++){
		int a,b,c;
		cin>>a>>b>>c;
		paths[a/K][a%K][b%K] = min(paths[a/K][a%K][b%K],c);
	}
	build(0,0,blk);
	while(Q--){
		int a,b;
		cin>>a>>b;
		if(a/K>=b/K){
			cout<<"-1\n";
			continue;
		}
		auto re = getval(0,0,blk,a/K,b/K-1);
		if(re[a%K][b%K]>=inf)cout<<"-1\n";
		else cout<<re[a%K][b%K]<<'\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 122 ms 245840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 102 ms 246704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 244820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 244820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 122 ms 245840 KB Output isn't correct
2 Halted 0 ms 0 KB -