Submission #269904

# Submission time Handle Problem Language Result Execution time Memory
269904 2020-08-17T11:09:22 Z brcode Toll (BOI17_toll) C++14
100 / 100
857 ms 32760 KB
#include <iostream>

using namespace std;
const int MAXN = 5e4+5;
struct node{
    int weight[6][6];
    bool realnode = false;
    void init(){
        for(int i=0;i<=5;i++){
            for(int j=0;j<=5;j++){
                weight[i][j] = 1e9;
            }
        }
        
    }
    void init2(){
        for(int i=0;i<=5;i++){
            for(int j=0;j<=5;j++){
                weight[i][j] = 0;
            }
        }
        
    }
    void upd(int x,int y,int w){
        //cout<<x<<" "<<y<<" "<<weight[x][y]<<endl;
        weight[x][y] = min(weight[x][y],w);
        
    }
};
node seg[4*MAXN];
 int k,n,m,o;
void build(int curr,int l,int r){
    if(l==r){
        seg[curr].init();
        seg[curr].realnode = true;
        return;
    }
    int mid = (l+r)/2;
    build(2*curr,l,mid);
    build(2*curr+1,mid+1,r);
    seg[curr].init();
    seg[curr].realnode = true;
}
void update(int curr,int l,int r,int pos,int from,int to,int val){
    
    if(l==r){
        
        seg[curr].upd(from,to,val);
      
        return;
    }
    int mid = (l+r)/2;
    if(pos<=mid){
        update(2*curr,l,mid,pos,from,to,val);
    }else{
        update(2*curr+1,mid+1,r,pos,from,to,val);
    }
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            for(int newmid=0;newmid<5;newmid++){
                seg[curr].weight[i][j] = min(seg[curr].weight[i][j],seg[2*curr].weight[i][newmid]+seg[2*curr+1].weight[newmid][j]);
                
            }
        }
    }
    
}
node query(int curr,int l,int r,int tl,int tr){
    if(r<tl||l>tr){
        node tmp;
        
        tmp.init();
        return tmp;
    }
    if(tl<=l && r<=tr){
       // cout<<l<<" "<<r<<" "<<tl<<" "<<tr<<endl;
       // cout<<seg[curr].weight[0][0]<<endl;
        return seg[curr];
    }
    int mid = (l+r)/2;
    node templ = query(2*curr,l,mid,tl,tr);
    node tempr = query(2*curr+1,mid+1,r,tl,tr);
    
    node resnode;
    resnode.realnode = true;
    resnode.init();
    if(templ.realnode == false){
        return tempr;
    }
    if(tempr.realnode == false){
        return templ;
    }
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            for(int newmid=0;newmid<5;newmid++){
                
                    resnode.weight[i][j] = min(resnode.weight[i][j],templ.weight[i][newmid]+tempr.weight[newmid][j]);
               
                
            }
        }
    }
   // cout<<l<<" "<<mid<<endl;
   // cout<<mid+1<<" "<<r<<endl;
    //cout<<tempr.weight[0][0]<<endl;
    return resnode;
}
int main(){
   
    cin>>k>>n>>m>>o;
    build(1,0,(n-1)/k);
    for(int i=1;i<=m;i++){
        int x,y,w;
        cin>>x>>y>>w;
        update(1,0,(n-1)/k,x/k,x%k,y%k,w);
    }
    while(o--){
        int x,y;
        cin>>x>>y;
        if(y/k<=x/k){
            cout<<-1<<endl;
            continue;
        }
        //cout<<x%k<<" "<<y%k<<endl;
        int res = query(1,0,(n-1)/k,x/k,(y/k)-1).weight[x%k][y%k];
        //cout<<x/k<<" "<<(y/k)-1<<endl;
        if(res == 1e9){
            cout<<-1<<endl;
            continue;
        }
        cout<<res<<endl;
    }
    
}
# Verdict Execution time Memory Grader output
1 Correct 330 ms 30328 KB Output is correct
2 Correct 15 ms 29312 KB Output is correct
3 Correct 15 ms 29312 KB Output is correct
4 Correct 15 ms 29312 KB Output is correct
5 Correct 23 ms 29312 KB Output is correct
6 Correct 23 ms 29312 KB Output is correct
7 Correct 23 ms 29312 KB Output is correct
8 Correct 333 ms 30200 KB Output is correct
9 Correct 333 ms 30220 KB Output is correct
10 Correct 98 ms 29472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 528 ms 30992 KB Output is correct
2 Correct 16 ms 29312 KB Output is correct
3 Correct 19 ms 29312 KB Output is correct
4 Correct 15 ms 29312 KB Output is correct
5 Correct 16 ms 29312 KB Output is correct
6 Correct 17 ms 29312 KB Output is correct
7 Correct 60 ms 29432 KB Output is correct
8 Correct 61 ms 29440 KB Output is correct
9 Correct 304 ms 30200 KB Output is correct
10 Correct 648 ms 31672 KB Output is correct
11 Correct 551 ms 31228 KB Output is correct
12 Correct 421 ms 30712 KB Output is correct
13 Correct 630 ms 32120 KB Output is correct
14 Correct 382 ms 30712 KB Output is correct
15 Correct 317 ms 30476 KB Output is correct
16 Correct 305 ms 30456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 29312 KB Output is correct
2 Correct 15 ms 29312 KB Output is correct
3 Correct 16 ms 29312 KB Output is correct
4 Correct 15 ms 29312 KB Output is correct
5 Correct 16 ms 29312 KB Output is correct
6 Correct 18 ms 29312 KB Output is correct
7 Correct 21 ms 29312 KB Output is correct
8 Correct 28 ms 29440 KB Output is correct
9 Correct 26 ms 29312 KB Output is correct
10 Correct 244 ms 30072 KB Output is correct
11 Correct 424 ms 30968 KB Output is correct
12 Correct 551 ms 31760 KB Output is correct
13 Correct 648 ms 32020 KB Output is correct
14 Correct 473 ms 31096 KB Output is correct
15 Correct 288 ms 30536 KB Output is correct
16 Correct 309 ms 30588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 29312 KB Output is correct
2 Correct 15 ms 29312 KB Output is correct
3 Correct 16 ms 29312 KB Output is correct
4 Correct 15 ms 29312 KB Output is correct
5 Correct 16 ms 29312 KB Output is correct
6 Correct 18 ms 29312 KB Output is correct
7 Correct 21 ms 29312 KB Output is correct
8 Correct 28 ms 29440 KB Output is correct
9 Correct 26 ms 29312 KB Output is correct
10 Correct 244 ms 30072 KB Output is correct
11 Correct 424 ms 30968 KB Output is correct
12 Correct 551 ms 31760 KB Output is correct
13 Correct 648 ms 32020 KB Output is correct
14 Correct 473 ms 31096 KB Output is correct
15 Correct 288 ms 30536 KB Output is correct
16 Correct 309 ms 30588 KB Output is correct
17 Correct 482 ms 30984 KB Output is correct
18 Correct 18 ms 29312 KB Output is correct
19 Correct 20 ms 29312 KB Output is correct
20 Correct 17 ms 29312 KB Output is correct
21 Correct 15 ms 29312 KB Output is correct
22 Correct 16 ms 29312 KB Output is correct
23 Correct 36 ms 29364 KB Output is correct
24 Correct 39 ms 29312 KB Output is correct
25 Correct 47 ms 29432 KB Output is correct
26 Correct 39 ms 29312 KB Output is correct
27 Correct 282 ms 30200 KB Output is correct
28 Correct 661 ms 31480 KB Output is correct
29 Correct 637 ms 32036 KB Output is correct
30 Correct 485 ms 31096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 330 ms 30328 KB Output is correct
2 Correct 15 ms 29312 KB Output is correct
3 Correct 15 ms 29312 KB Output is correct
4 Correct 15 ms 29312 KB Output is correct
5 Correct 23 ms 29312 KB Output is correct
6 Correct 23 ms 29312 KB Output is correct
7 Correct 23 ms 29312 KB Output is correct
8 Correct 333 ms 30200 KB Output is correct
9 Correct 333 ms 30220 KB Output is correct
10 Correct 98 ms 29472 KB Output is correct
11 Correct 528 ms 30992 KB Output is correct
12 Correct 16 ms 29312 KB Output is correct
13 Correct 19 ms 29312 KB Output is correct
14 Correct 15 ms 29312 KB Output is correct
15 Correct 16 ms 29312 KB Output is correct
16 Correct 17 ms 29312 KB Output is correct
17 Correct 60 ms 29432 KB Output is correct
18 Correct 61 ms 29440 KB Output is correct
19 Correct 304 ms 30200 KB Output is correct
20 Correct 648 ms 31672 KB Output is correct
21 Correct 551 ms 31228 KB Output is correct
22 Correct 421 ms 30712 KB Output is correct
23 Correct 630 ms 32120 KB Output is correct
24 Correct 382 ms 30712 KB Output is correct
25 Correct 317 ms 30476 KB Output is correct
26 Correct 305 ms 30456 KB Output is correct
27 Correct 16 ms 29312 KB Output is correct
28 Correct 15 ms 29312 KB Output is correct
29 Correct 16 ms 29312 KB Output is correct
30 Correct 15 ms 29312 KB Output is correct
31 Correct 16 ms 29312 KB Output is correct
32 Correct 18 ms 29312 KB Output is correct
33 Correct 21 ms 29312 KB Output is correct
34 Correct 28 ms 29440 KB Output is correct
35 Correct 26 ms 29312 KB Output is correct
36 Correct 244 ms 30072 KB Output is correct
37 Correct 424 ms 30968 KB Output is correct
38 Correct 551 ms 31760 KB Output is correct
39 Correct 648 ms 32020 KB Output is correct
40 Correct 473 ms 31096 KB Output is correct
41 Correct 288 ms 30536 KB Output is correct
42 Correct 309 ms 30588 KB Output is correct
43 Correct 482 ms 30984 KB Output is correct
44 Correct 18 ms 29312 KB Output is correct
45 Correct 20 ms 29312 KB Output is correct
46 Correct 17 ms 29312 KB Output is correct
47 Correct 15 ms 29312 KB Output is correct
48 Correct 16 ms 29312 KB Output is correct
49 Correct 36 ms 29364 KB Output is correct
50 Correct 39 ms 29312 KB Output is correct
51 Correct 47 ms 29432 KB Output is correct
52 Correct 39 ms 29312 KB Output is correct
53 Correct 282 ms 30200 KB Output is correct
54 Correct 661 ms 31480 KB Output is correct
55 Correct 637 ms 32036 KB Output is correct
56 Correct 485 ms 31096 KB Output is correct
57 Correct 857 ms 32760 KB Output is correct
58 Correct 338 ms 30200 KB Output is correct
59 Correct 548 ms 31036 KB Output is correct