답안 #523649

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523649 2022-02-08T02:49:05 Z Deepesson 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
241 ms 89164 KB
#include <bits/stdc++.h>
#define MAX 305000
using ll = long long;
typedef std::array<std::array<ll,2>,2> matriz;
matriz mul(matriz a,matriz b){
    matriz c = {};
    for(auto&x:c)for(auto&y:x)y=(-1LL<<60LL);
    for(int i=0;i!=2;++i){
        for(int j=0;j!=2;++j){
            for(int k=0;k!=2;++k){
                c[i][j]=std::max(c[i][j],a[i][k]+b[k][j]);
            }
        }
    }
    return c;
}
matriz montar(long long X){
    matriz u = {};
    for(auto&x:u)for(auto&y:x)y=(-(1LL<<60LL));
    u[0][0]=X;
    u[1][1]=0;
    u[1][0]=0;
    return u;
}
matriz neutro,base;
matriz tab[MAX*4];
void update(int t,matriz g,int la=0,int ra=MAX-1,int pos=1){
    if(t>ra||la>t)return;
    if(la==ra){
        tab[pos]=g;
        return;
    }
    int m = (la+ra)/2;
    update(t,g,la,m,pos*2);
    update(t,g,m+1,ra,(pos*2)+1);
 /*   std::cout<<"Tem "<<tab[pos*2][0][0]<<" "<<tab[(pos*2)+1][0][0]<<"\n";
    for(int i=0;i!=2;++i){
        for(int j=0;j!=2;++j){
            std::cout<<tab[pos*2][i][j]<<" ";
        }
        std::cout<<"\n";
    }
    std::cout<<"Direita:\n";
    for(int i=0;i!=2;++i){
        for(int j=0;j!=2;++j){
            std::cout<<tab[(pos*2)+1][i][j]<<" ";
        }
        std::cout<<"\n";
    }
    std::cout<<"\n";*/
    tab[pos]=mul(tab[pos*2],tab[(pos*2)+1]);
   /// std::cout<<"Atualiza "<<tab[pos][0][0]<<"\n";
}
matriz query(int l,int r,int la=0,int ra=MAX-1,int pos=1){
    if(l>ra||la>r)return neutro;
    if(la>=l&&ra<=r){
        return tab[pos];
    }
    int m=(la+ra)/2;
    return mul(query(l,r,la,m,pos*2),query(l,r,m+1,ra,(pos*2)+1));
}
long long ft[MAX];
#define LSB(A) (A&(-A))
void add(long long x,long long y){
    x+=6;
    while(x<MAX){
        ft[x]+=y;
        x+=LSB(x);
    }
}
ll query(long long x){
    x+=6;
    ll ans=0;
    while(x>0){
        ans+=ft[x];
        x-=LSB(x);
    }
    return ans;
}
typedef std::pair<long long,matriz> pim;
typedef std::pair<long long,long long> pii;
typedef std::pair<pii,long long> ppi;
std::vector<pim> matupdate[MAX];
std::vector<pii> ftupdate[MAX];
std::vector<ppi> queries[MAX];
long long grupo[MAX];
long long respostas[MAX];
int main()
{
    neutro[0][1]=neutro[1][0]=(-(1LL<<60LL));
    for(auto&x:tab)x=neutro;
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    long long N,M,Q;
    std::cin>>N>>M>>Q;
    long long cur=0;
    for(int i=0;i!=Q;++i){
        long long t;
        std::cin>>t;
        if(t==1){
            long long L,R,C,K;
            std::cin>>L>>R>>C>>K;
            --L;
            grupo[i]=C;
            ftupdate[L].push_back({i,K});
            ftupdate[R].push_back({i,-K});
            matupdate[L].push_back({i,montar(K)});
            matupdate[R].push_back({i,neutro});
        }else if(t==2){
            long long L,R,K;
            std::cin>>L>>R>>K;
            --L;
            matupdate[L].push_back({i,montar(-K)});
            matupdate[R].push_back({i,neutro});
        }else {
            long long A,B;
            std::cin>>A>>B;--A;
            queries[A].push_back({{B,i},cur});
            ++cur;
        }
    }
    for(int i=0;i!=M+5;++i){
        for(auto&x:ftupdate[i]){
            add(x.first,x.second);
        }
        for(auto&x:matupdate[i]){
        ///    std::cout<<"Add "<<x.first<<" "<<x.second[0][0]<<"\n";
            update(x.first,x.second);
         ///   std::cout<<"Novo "<<tab[1][0][0]<<"\n";
        }
        for(auto&x:queries[i]){
            long long escolhido = x.first.first;
            long long tempo = x.first.second;
            long long indice = x.second;
            matriz q = mul(base,query(0,tempo));
            long long nafila = q[0][0];
         ///   std::cout<<"Na fila: "<<nafila<<" "<<tempo<<"\n";
            if(nafila<escolhido){
                respostas[indice]=0;
                continue;
            }
            long long soma = query(tempo);
            long long retirar = nafila-escolhido;
            long long pegar = soma - retirar;
          ///  std::cout<<soma<<" "<<nafila<<"\n";
            long long l=0,r=tempo;
            while(l<r){
                long long m = (l+r)/2;
                long long g = query(m);
                if(g>=pegar){
                    r=m;
                }else l=m+1;
            }
          ///  std::cout<<"Achou "<<l<<"\n";
            respostas[indice]=grupo[l];
        }
    }

    for(int i=0;i!=cur;++i){
        std::cout<<respostas[i]<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 60104 KB Output is correct
2 Correct 32 ms 60236 KB Output is correct
3 Correct 29 ms 60096 KB Output is correct
4 Correct 31 ms 60392 KB Output is correct
5 Correct 33 ms 60360 KB Output is correct
6 Correct 30 ms 60236 KB Output is correct
7 Correct 31 ms 60268 KB Output is correct
8 Correct 30 ms 60236 KB Output is correct
9 Correct 30 ms 60296 KB Output is correct
10 Correct 30 ms 60236 KB Output is correct
11 Correct 30 ms 60296 KB Output is correct
12 Correct 30 ms 60288 KB Output is correct
13 Correct 31 ms 60236 KB Output is correct
14 Correct 31 ms 60356 KB Output is correct
15 Correct 30 ms 60180 KB Output is correct
16 Correct 30 ms 60216 KB Output is correct
17 Correct 30 ms 60160 KB Output is correct
18 Correct 30 ms 60196 KB Output is correct
19 Correct 32 ms 60236 KB Output is correct
20 Correct 30 ms 60256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 60104 KB Output is correct
2 Correct 32 ms 60236 KB Output is correct
3 Correct 29 ms 60096 KB Output is correct
4 Correct 31 ms 60392 KB Output is correct
5 Correct 33 ms 60360 KB Output is correct
6 Correct 30 ms 60236 KB Output is correct
7 Correct 31 ms 60268 KB Output is correct
8 Correct 30 ms 60236 KB Output is correct
9 Correct 30 ms 60296 KB Output is correct
10 Correct 30 ms 60236 KB Output is correct
11 Correct 30 ms 60296 KB Output is correct
12 Correct 30 ms 60288 KB Output is correct
13 Correct 31 ms 60236 KB Output is correct
14 Correct 31 ms 60356 KB Output is correct
15 Correct 30 ms 60180 KB Output is correct
16 Correct 30 ms 60216 KB Output is correct
17 Correct 30 ms 60160 KB Output is correct
18 Correct 30 ms 60196 KB Output is correct
19 Correct 32 ms 60236 KB Output is correct
20 Correct 30 ms 60256 KB Output is correct
21 Correct 30 ms 60236 KB Output is correct
22 Correct 30 ms 60224 KB Output is correct
23 Correct 30 ms 60236 KB Output is correct
24 Correct 30 ms 60236 KB Output is correct
25 Correct 30 ms 60340 KB Output is correct
26 Correct 30 ms 60308 KB Output is correct
27 Correct 31 ms 60228 KB Output is correct
28 Correct 30 ms 60236 KB Output is correct
29 Correct 30 ms 60260 KB Output is correct
30 Correct 31 ms 60236 KB Output is correct
31 Correct 33 ms 60244 KB Output is correct
32 Correct 32 ms 60264 KB Output is correct
33 Correct 31 ms 60448 KB Output is correct
34 Correct 34 ms 60352 KB Output is correct
35 Correct 29 ms 60236 KB Output is correct
36 Correct 31 ms 60280 KB Output is correct
37 Correct 29 ms 60232 KB Output is correct
38 Correct 30 ms 60376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 67388 KB Output is correct
2 Correct 149 ms 68292 KB Output is correct
3 Correct 149 ms 67356 KB Output is correct
4 Correct 129 ms 67340 KB Output is correct
5 Correct 146 ms 68292 KB Output is correct
6 Correct 140 ms 68288 KB Output is correct
7 Correct 100 ms 66576 KB Output is correct
8 Correct 94 ms 67068 KB Output is correct
9 Correct 151 ms 67536 KB Output is correct
10 Correct 141 ms 67908 KB Output is correct
11 Correct 155 ms 67800 KB Output is correct
12 Correct 153 ms 67960 KB Output is correct
13 Correct 115 ms 67328 KB Output is correct
14 Correct 131 ms 68116 KB Output is correct
15 Correct 155 ms 69896 KB Output is correct
16 Correct 163 ms 69700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 241 ms 89164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 60104 KB Output is correct
2 Correct 32 ms 60236 KB Output is correct
3 Correct 29 ms 60096 KB Output is correct
4 Correct 31 ms 60392 KB Output is correct
5 Correct 33 ms 60360 KB Output is correct
6 Correct 30 ms 60236 KB Output is correct
7 Correct 31 ms 60268 KB Output is correct
8 Correct 30 ms 60236 KB Output is correct
9 Correct 30 ms 60296 KB Output is correct
10 Correct 30 ms 60236 KB Output is correct
11 Correct 30 ms 60296 KB Output is correct
12 Correct 30 ms 60288 KB Output is correct
13 Correct 31 ms 60236 KB Output is correct
14 Correct 31 ms 60356 KB Output is correct
15 Correct 30 ms 60180 KB Output is correct
16 Correct 30 ms 60216 KB Output is correct
17 Correct 30 ms 60160 KB Output is correct
18 Correct 30 ms 60196 KB Output is correct
19 Correct 32 ms 60236 KB Output is correct
20 Correct 30 ms 60256 KB Output is correct
21 Correct 130 ms 67388 KB Output is correct
22 Correct 149 ms 68292 KB Output is correct
23 Correct 149 ms 67356 KB Output is correct
24 Correct 129 ms 67340 KB Output is correct
25 Correct 146 ms 68292 KB Output is correct
26 Correct 140 ms 68288 KB Output is correct
27 Correct 100 ms 66576 KB Output is correct
28 Correct 94 ms 67068 KB Output is correct
29 Correct 151 ms 67536 KB Output is correct
30 Correct 141 ms 67908 KB Output is correct
31 Correct 155 ms 67800 KB Output is correct
32 Correct 153 ms 67960 KB Output is correct
33 Correct 115 ms 67328 KB Output is correct
34 Correct 131 ms 68116 KB Output is correct
35 Correct 155 ms 69896 KB Output is correct
36 Correct 163 ms 69700 KB Output is correct
37 Correct 144 ms 66708 KB Output is correct
38 Correct 120 ms 66624 KB Output is correct
39 Correct 91 ms 65816 KB Output is correct
40 Correct 96 ms 67164 KB Output is correct
41 Correct 156 ms 67400 KB Output is correct
42 Correct 149 ms 68004 KB Output is correct
43 Correct 144 ms 67912 KB Output is correct
44 Correct 143 ms 67684 KB Output is correct
45 Correct 153 ms 67908 KB Output is correct
46 Correct 158 ms 67916 KB Output is correct
47 Correct 111 ms 66396 KB Output is correct
48 Correct 121 ms 69060 KB Output is correct
49 Correct 103 ms 65732 KB Output is correct
50 Correct 122 ms 66884 KB Output is correct
51 Correct 152 ms 68224 KB Output is correct
52 Correct 152 ms 68212 KB Output is correct
53 Correct 127 ms 67588 KB Output is correct
54 Correct 148 ms 69792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 68000 KB Output is correct
2 Correct 142 ms 68808 KB Output is correct
3 Correct 151 ms 69016 KB Output is correct
4 Correct 120 ms 66304 KB Output is correct
5 Correct 124 ms 67788 KB Output is correct
6 Correct 152 ms 68984 KB Output is correct
7 Correct 91 ms 66780 KB Output is correct
8 Correct 88 ms 66168 KB Output is correct
9 Correct 111 ms 67592 KB Output is correct
10 Correct 97 ms 66884 KB Output is correct
11 Correct 123 ms 69148 KB Output is correct
12 Correct 122 ms 69180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 60104 KB Output is correct
2 Correct 32 ms 60236 KB Output is correct
3 Correct 29 ms 60096 KB Output is correct
4 Correct 31 ms 60392 KB Output is correct
5 Correct 33 ms 60360 KB Output is correct
6 Correct 30 ms 60236 KB Output is correct
7 Correct 31 ms 60268 KB Output is correct
8 Correct 30 ms 60236 KB Output is correct
9 Correct 30 ms 60296 KB Output is correct
10 Correct 30 ms 60236 KB Output is correct
11 Correct 30 ms 60296 KB Output is correct
12 Correct 30 ms 60288 KB Output is correct
13 Correct 31 ms 60236 KB Output is correct
14 Correct 31 ms 60356 KB Output is correct
15 Correct 30 ms 60180 KB Output is correct
16 Correct 30 ms 60216 KB Output is correct
17 Correct 30 ms 60160 KB Output is correct
18 Correct 30 ms 60196 KB Output is correct
19 Correct 32 ms 60236 KB Output is correct
20 Correct 30 ms 60256 KB Output is correct
21 Correct 30 ms 60236 KB Output is correct
22 Correct 30 ms 60224 KB Output is correct
23 Correct 30 ms 60236 KB Output is correct
24 Correct 30 ms 60236 KB Output is correct
25 Correct 30 ms 60340 KB Output is correct
26 Correct 30 ms 60308 KB Output is correct
27 Correct 31 ms 60228 KB Output is correct
28 Correct 30 ms 60236 KB Output is correct
29 Correct 30 ms 60260 KB Output is correct
30 Correct 31 ms 60236 KB Output is correct
31 Correct 33 ms 60244 KB Output is correct
32 Correct 32 ms 60264 KB Output is correct
33 Correct 31 ms 60448 KB Output is correct
34 Correct 34 ms 60352 KB Output is correct
35 Correct 29 ms 60236 KB Output is correct
36 Correct 31 ms 60280 KB Output is correct
37 Correct 29 ms 60232 KB Output is correct
38 Correct 30 ms 60376 KB Output is correct
39 Correct 130 ms 67388 KB Output is correct
40 Correct 149 ms 68292 KB Output is correct
41 Correct 149 ms 67356 KB Output is correct
42 Correct 129 ms 67340 KB Output is correct
43 Correct 146 ms 68292 KB Output is correct
44 Correct 140 ms 68288 KB Output is correct
45 Correct 100 ms 66576 KB Output is correct
46 Correct 94 ms 67068 KB Output is correct
47 Correct 151 ms 67536 KB Output is correct
48 Correct 141 ms 67908 KB Output is correct
49 Correct 155 ms 67800 KB Output is correct
50 Correct 153 ms 67960 KB Output is correct
51 Correct 115 ms 67328 KB Output is correct
52 Correct 131 ms 68116 KB Output is correct
53 Correct 155 ms 69896 KB Output is correct
54 Correct 163 ms 69700 KB Output is correct
55 Correct 144 ms 66708 KB Output is correct
56 Correct 120 ms 66624 KB Output is correct
57 Correct 91 ms 65816 KB Output is correct
58 Correct 96 ms 67164 KB Output is correct
59 Correct 156 ms 67400 KB Output is correct
60 Correct 149 ms 68004 KB Output is correct
61 Correct 144 ms 67912 KB Output is correct
62 Correct 143 ms 67684 KB Output is correct
63 Correct 153 ms 67908 KB Output is correct
64 Correct 158 ms 67916 KB Output is correct
65 Correct 111 ms 66396 KB Output is correct
66 Correct 121 ms 69060 KB Output is correct
67 Correct 103 ms 65732 KB Output is correct
68 Correct 122 ms 66884 KB Output is correct
69 Correct 152 ms 68224 KB Output is correct
70 Correct 152 ms 68212 KB Output is correct
71 Correct 127 ms 67588 KB Output is correct
72 Correct 148 ms 69792 KB Output is correct
73 Correct 131 ms 68000 KB Output is correct
74 Correct 142 ms 68808 KB Output is correct
75 Correct 151 ms 69016 KB Output is correct
76 Correct 120 ms 66304 KB Output is correct
77 Correct 124 ms 67788 KB Output is correct
78 Correct 152 ms 68984 KB Output is correct
79 Correct 91 ms 66780 KB Output is correct
80 Correct 88 ms 66168 KB Output is correct
81 Correct 111 ms 67592 KB Output is correct
82 Correct 97 ms 66884 KB Output is correct
83 Correct 123 ms 69148 KB Output is correct
84 Correct 122 ms 69180 KB Output is correct
85 Correct 135 ms 68164 KB Output is correct
86 Correct 156 ms 69108 KB Output is correct
87 Correct 131 ms 68772 KB Output is correct
88 Correct 150 ms 70016 KB Output is correct
89 Correct 100 ms 66080 KB Output is correct
90 Correct 164 ms 69596 KB Output is correct
91 Correct 121 ms 67948 KB Output is correct
92 Correct 120 ms 67440 KB Output is correct
93 Correct 148 ms 69548 KB Output is correct
94 Correct 153 ms 69236 KB Output is correct
95 Correct 148 ms 69420 KB Output is correct
96 Correct 151 ms 69604 KB Output is correct
97 Correct 160 ms 69572 KB Output is correct
98 Correct 126 ms 68216 KB Output is correct
99 Correct 111 ms 67776 KB Output is correct
100 Correct 107 ms 67920 KB Output is correct
101 Correct 128 ms 70612 KB Output is correct
102 Correct 141 ms 70808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 60104 KB Output is correct
2 Correct 32 ms 60236 KB Output is correct
3 Correct 29 ms 60096 KB Output is correct
4 Correct 31 ms 60392 KB Output is correct
5 Correct 33 ms 60360 KB Output is correct
6 Correct 30 ms 60236 KB Output is correct
7 Correct 31 ms 60268 KB Output is correct
8 Correct 30 ms 60236 KB Output is correct
9 Correct 30 ms 60296 KB Output is correct
10 Correct 30 ms 60236 KB Output is correct
11 Correct 30 ms 60296 KB Output is correct
12 Correct 30 ms 60288 KB Output is correct
13 Correct 31 ms 60236 KB Output is correct
14 Correct 31 ms 60356 KB Output is correct
15 Correct 30 ms 60180 KB Output is correct
16 Correct 30 ms 60216 KB Output is correct
17 Correct 30 ms 60160 KB Output is correct
18 Correct 30 ms 60196 KB Output is correct
19 Correct 32 ms 60236 KB Output is correct
20 Correct 30 ms 60256 KB Output is correct
21 Correct 30 ms 60236 KB Output is correct
22 Correct 30 ms 60224 KB Output is correct
23 Correct 30 ms 60236 KB Output is correct
24 Correct 30 ms 60236 KB Output is correct
25 Correct 30 ms 60340 KB Output is correct
26 Correct 30 ms 60308 KB Output is correct
27 Correct 31 ms 60228 KB Output is correct
28 Correct 30 ms 60236 KB Output is correct
29 Correct 30 ms 60260 KB Output is correct
30 Correct 31 ms 60236 KB Output is correct
31 Correct 33 ms 60244 KB Output is correct
32 Correct 32 ms 60264 KB Output is correct
33 Correct 31 ms 60448 KB Output is correct
34 Correct 34 ms 60352 KB Output is correct
35 Correct 29 ms 60236 KB Output is correct
36 Correct 31 ms 60280 KB Output is correct
37 Correct 29 ms 60232 KB Output is correct
38 Correct 30 ms 60376 KB Output is correct
39 Correct 130 ms 67388 KB Output is correct
40 Correct 149 ms 68292 KB Output is correct
41 Correct 149 ms 67356 KB Output is correct
42 Correct 129 ms 67340 KB Output is correct
43 Correct 146 ms 68292 KB Output is correct
44 Correct 140 ms 68288 KB Output is correct
45 Correct 100 ms 66576 KB Output is correct
46 Correct 94 ms 67068 KB Output is correct
47 Correct 151 ms 67536 KB Output is correct
48 Correct 141 ms 67908 KB Output is correct
49 Correct 155 ms 67800 KB Output is correct
50 Correct 153 ms 67960 KB Output is correct
51 Correct 115 ms 67328 KB Output is correct
52 Correct 131 ms 68116 KB Output is correct
53 Correct 155 ms 69896 KB Output is correct
54 Correct 163 ms 69700 KB Output is correct
55 Incorrect 241 ms 89164 KB Output isn't correct
56 Halted 0 ms 0 KB -