답안 #1033282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033282 2024-07-24T15:58:57 Z alexdd 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 87376 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
int n,m,q;
pair<pair<int,int>,pair<int,int>> aint[530000][3];
int lazy[530000][3];
pair<pair<int,int>,pair<int,int>> emp = {{INF,INF},{-INF,-INF}};
pair<pair<int,int>,pair<int,int>> combine(pair<pair<int,int>,pair<int,int>> x, pair<pair<int,int>,pair<int,int>> y)
{
    return {min(x.first,y.first),max(x.second,y.second)};
}
void build(int nod, int st, int dr)
{
    if(st==dr)
    {
        aint[nod][0] = aint[nod][1] = aint[nod][2] = {{0,st},{0,st}};
        return;
    }
    int mij=(st+dr)/2;
    build(nod*2,st,mij);
    build(nod*2+1,mij+1,dr);
    aint[nod][0] = combine(aint[nod*2][0], aint[nod*2+1][0]);
    aint[nod][1] = combine(aint[nod*2][1], aint[nod*2+1][1]);
    aint[nod][2] = combine(aint[nod*2][2], aint[nod*2+1][2]);
}
void propagate(int nod, int c)
{
    if(!lazy[nod][c])
        return;
    lazy[nod*2][c]+=lazy[nod][c];
    lazy[nod*2+1][c]+=lazy[nod][c];
    aint[nod*2][c].first.first+=lazy[nod][c];
    aint[nod*2][c].second.first+=lazy[nod][c];
    aint[nod*2+1][c].first.first+=lazy[nod][c];
    aint[nod*2+1][c].second.first+=lazy[nod][c];
    lazy[nod][c]=0;
}
void upd(int nod, int st, int dr, int le, int ri, int newv, int c)
{
    if(le>ri)
        return;
    if(le==st && dr==ri)
    {
        lazy[nod][c]+=newv;
        aint[nod][c].first.first+=newv;
        aint[nod][c].second.first+=newv;
        return;
    }
    propagate(nod,c);
    int mij=(st+dr)/2;
    upd(nod*2,st,mij,le,min(mij,ri),newv,c);
    upd(nod*2+1,mij+1,dr,max(mij+1,le),ri,newv,c);
    aint[nod][c] = combine(aint[nod*2][c], aint[nod*2+1][c]);
}
pair<pair<int,int>,pair<int,int>> qry(int nod, int st, int dr, int le, int ri, int c)
{
    if(le>ri)
        return emp;
    if(le==st && dr==ri)
        return aint[nod][c];
    propagate(nod,c);
    int mij=(st+dr)/2;
    return combine(qry(nod*2,st,mij,le,min(mij,ri),c),
                   qry(nod*2+1,mij+1,dr,max(mij+1,le),ri,c));
}
vector<pair<int,int>> upds[250005];
vector<pair<int,int>> qrys[250005];
int rez[250005];
int cit[250005];
signed main()
{
    cin>>n>>m>>q;
    int tip,le,ri,c,k,a,b;
    for(int i=1;i<=q;i++)
    {
        cin>>tip;
        rez[i] = -7;
        if(tip==1)
        {
            cin>>le>>ri>>c>>k;
            upds[le].push_back({i,k});
            upds[ri+1].push_back({i,-k});
            cit[i]=c;
        }
        else if(tip==2)
        {
            cin>>le>>ri>>k;
            upds[le].push_back({-i,k});
            upds[ri+1].push_back({-i,-k});
        }
        else
        {
            cin>>a>>b;
            qrys[a].push_back({b,i});
        }
    }
    build(1,0,q);
    for(int i=1;i<=n;i++)
    {
        for(auto [t,newv]:upds[i])
        {
            if(t < 0)
            {
                t = -t;
                upd(1,0,q,t,q,-newv,0);
                upd(1,0,q,t,q,newv,2);
            }
            else
            {
                upd(1,0,q,t,q,newv,0);
                upd(1,0,q,t,q,newv,1);
            }
        }
        for(auto [x,t]:qrys[i])
        {
            pair<pair<int,int>,pair<int,int>> aux = qry(1,0,q,0,t,0);
            int ult = aux.first.second;
            int scazute = qry(1,0,q,t,t,2).first.first - qry(1,0,q,ult,ult,2).first.first;
            int pref1 = qry(1,0,q,ult,ult,1).first.first;
            int st=ult+1,dr=t,ans=-1;
            while(st<=dr)
            {
                int mij=(st+dr)/2;
                if(qry(1,0,q,mij,mij,1).first.first >= x + pref1 + scazute)
                {
                    ans=mij;
                    dr=mij-1;
                }
                else
                    st=mij+1;
            }
            if(ans==-1)
            {
                rez[t]=0;
            }
            else
            {
                rez[t]=cit[ans];
            }
        }
    }
    for(int i=1;i<=q;i++)
    {
        if(rez[i]==-7)
            continue;
        cout<<rez[i]<<"\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12780 KB Output is correct
2 Correct 9 ms 12632 KB Output is correct
3 Correct 9 ms 12636 KB Output is correct
4 Correct 9 ms 12792 KB Output is correct
5 Correct 8 ms 12636 KB Output is correct
6 Correct 8 ms 12636 KB Output is correct
7 Correct 9 ms 12688 KB Output is correct
8 Correct 10 ms 12636 KB Output is correct
9 Correct 9 ms 12988 KB Output is correct
10 Correct 11 ms 12636 KB Output is correct
11 Correct 9 ms 12820 KB Output is correct
12 Correct 10 ms 12672 KB Output is correct
13 Correct 8 ms 12636 KB Output is correct
14 Correct 9 ms 12636 KB Output is correct
15 Correct 9 ms 12532 KB Output is correct
16 Correct 9 ms 12636 KB Output is correct
17 Correct 9 ms 12636 KB Output is correct
18 Correct 9 ms 12632 KB Output is correct
19 Correct 9 ms 12636 KB Output is correct
20 Correct 10 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12780 KB Output is correct
2 Correct 9 ms 12632 KB Output is correct
3 Correct 9 ms 12636 KB Output is correct
4 Correct 9 ms 12792 KB Output is correct
5 Correct 8 ms 12636 KB Output is correct
6 Correct 8 ms 12636 KB Output is correct
7 Correct 9 ms 12688 KB Output is correct
8 Correct 10 ms 12636 KB Output is correct
9 Correct 9 ms 12988 KB Output is correct
10 Correct 11 ms 12636 KB Output is correct
11 Correct 9 ms 12820 KB Output is correct
12 Correct 10 ms 12672 KB Output is correct
13 Correct 8 ms 12636 KB Output is correct
14 Correct 9 ms 12636 KB Output is correct
15 Correct 9 ms 12532 KB Output is correct
16 Correct 9 ms 12636 KB Output is correct
17 Correct 9 ms 12636 KB Output is correct
18 Correct 9 ms 12632 KB Output is correct
19 Correct 9 ms 12636 KB Output is correct
20 Correct 10 ms 12636 KB Output is correct
21 Correct 9 ms 12796 KB Output is correct
22 Correct 11 ms 12636 KB Output is correct
23 Correct 11 ms 12808 KB Output is correct
24 Correct 10 ms 12632 KB Output is correct
25 Correct 7 ms 12820 KB Output is correct
26 Correct 8 ms 12688 KB Output is correct
27 Correct 9 ms 12632 KB Output is correct
28 Correct 9 ms 12636 KB Output is correct
29 Correct 9 ms 12636 KB Output is correct
30 Correct 9 ms 12636 KB Output is correct
31 Correct 9 ms 12808 KB Output is correct
32 Correct 9 ms 12636 KB Output is correct
33 Correct 8 ms 12636 KB Output is correct
34 Correct 8 ms 12636 KB Output is correct
35 Correct 9 ms 12804 KB Output is correct
36 Correct 8 ms 12740 KB Output is correct
37 Correct 8 ms 12636 KB Output is correct
38 Correct 8 ms 12776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 31512 KB Output is correct
2 Correct 152 ms 31572 KB Output is correct
3 Correct 186 ms 31312 KB Output is correct
4 Correct 176 ms 31304 KB Output is correct
5 Correct 164 ms 31568 KB Output is correct
6 Correct 163 ms 31568 KB Output is correct
7 Correct 88 ms 30288 KB Output is correct
8 Correct 102 ms 30436 KB Output is correct
9 Correct 175 ms 31316 KB Output is correct
10 Correct 158 ms 31572 KB Output is correct
11 Correct 174 ms 31316 KB Output is correct
12 Correct 149 ms 31540 KB Output is correct
13 Correct 142 ms 31052 KB Output is correct
14 Correct 216 ms 31300 KB Output is correct
15 Correct 164 ms 31572 KB Output is correct
16 Correct 150 ms 31572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1049 ms 87376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12780 KB Output is correct
2 Correct 9 ms 12632 KB Output is correct
3 Correct 9 ms 12636 KB Output is correct
4 Correct 9 ms 12792 KB Output is correct
5 Correct 8 ms 12636 KB Output is correct
6 Correct 8 ms 12636 KB Output is correct
7 Correct 9 ms 12688 KB Output is correct
8 Correct 10 ms 12636 KB Output is correct
9 Correct 9 ms 12988 KB Output is correct
10 Correct 11 ms 12636 KB Output is correct
11 Correct 9 ms 12820 KB Output is correct
12 Correct 10 ms 12672 KB Output is correct
13 Correct 8 ms 12636 KB Output is correct
14 Correct 9 ms 12636 KB Output is correct
15 Correct 9 ms 12532 KB Output is correct
16 Correct 9 ms 12636 KB Output is correct
17 Correct 9 ms 12636 KB Output is correct
18 Correct 9 ms 12632 KB Output is correct
19 Correct 9 ms 12636 KB Output is correct
20 Correct 10 ms 12636 KB Output is correct
21 Correct 177 ms 31512 KB Output is correct
22 Correct 152 ms 31572 KB Output is correct
23 Correct 186 ms 31312 KB Output is correct
24 Correct 176 ms 31304 KB Output is correct
25 Correct 164 ms 31568 KB Output is correct
26 Correct 163 ms 31568 KB Output is correct
27 Correct 88 ms 30288 KB Output is correct
28 Correct 102 ms 30436 KB Output is correct
29 Correct 175 ms 31316 KB Output is correct
30 Correct 158 ms 31572 KB Output is correct
31 Correct 174 ms 31316 KB Output is correct
32 Correct 149 ms 31540 KB Output is correct
33 Correct 142 ms 31052 KB Output is correct
34 Correct 216 ms 31300 KB Output is correct
35 Correct 164 ms 31572 KB Output is correct
36 Correct 150 ms 31572 KB Output is correct
37 Correct 187 ms 31056 KB Output is correct
38 Correct 143 ms 30800 KB Output is correct
39 Correct 106 ms 30016 KB Output is correct
40 Correct 124 ms 30308 KB Output is correct
41 Correct 225 ms 31316 KB Output is correct
42 Correct 205 ms 31556 KB Output is correct
43 Correct 225 ms 31440 KB Output is correct
44 Correct 215 ms 31316 KB Output is correct
45 Correct 194 ms 31808 KB Output is correct
46 Correct 197 ms 31572 KB Output is correct
47 Correct 172 ms 30648 KB Output is correct
48 Correct 220 ms 31572 KB Output is correct
49 Correct 124 ms 30288 KB Output is correct
50 Correct 165 ms 31132 KB Output is correct
51 Correct 178 ms 31572 KB Output is correct
52 Correct 173 ms 31576 KB Output is correct
53 Correct 141 ms 31016 KB Output is correct
54 Correct 175 ms 31572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 249 ms 30800 KB Output is correct
2 Correct 372 ms 31136 KB Output is correct
3 Correct 265 ms 31196 KB Output is correct
4 Correct 210 ms 30288 KB Output is correct
5 Correct 292 ms 30804 KB Output is correct
6 Correct 279 ms 31336 KB Output is correct
7 Correct 179 ms 29984 KB Output is correct
8 Correct 173 ms 29848 KB Output is correct
9 Correct 250 ms 30552 KB Output is correct
10 Correct 177 ms 30032 KB Output is correct
11 Correct 264 ms 31060 KB Output is correct
12 Correct 277 ms 31056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12780 KB Output is correct
2 Correct 9 ms 12632 KB Output is correct
3 Correct 9 ms 12636 KB Output is correct
4 Correct 9 ms 12792 KB Output is correct
5 Correct 8 ms 12636 KB Output is correct
6 Correct 8 ms 12636 KB Output is correct
7 Correct 9 ms 12688 KB Output is correct
8 Correct 10 ms 12636 KB Output is correct
9 Correct 9 ms 12988 KB Output is correct
10 Correct 11 ms 12636 KB Output is correct
11 Correct 9 ms 12820 KB Output is correct
12 Correct 10 ms 12672 KB Output is correct
13 Correct 8 ms 12636 KB Output is correct
14 Correct 9 ms 12636 KB Output is correct
15 Correct 9 ms 12532 KB Output is correct
16 Correct 9 ms 12636 KB Output is correct
17 Correct 9 ms 12636 KB Output is correct
18 Correct 9 ms 12632 KB Output is correct
19 Correct 9 ms 12636 KB Output is correct
20 Correct 10 ms 12636 KB Output is correct
21 Correct 9 ms 12796 KB Output is correct
22 Correct 11 ms 12636 KB Output is correct
23 Correct 11 ms 12808 KB Output is correct
24 Correct 10 ms 12632 KB Output is correct
25 Correct 7 ms 12820 KB Output is correct
26 Correct 8 ms 12688 KB Output is correct
27 Correct 9 ms 12632 KB Output is correct
28 Correct 9 ms 12636 KB Output is correct
29 Correct 9 ms 12636 KB Output is correct
30 Correct 9 ms 12636 KB Output is correct
31 Correct 9 ms 12808 KB Output is correct
32 Correct 9 ms 12636 KB Output is correct
33 Correct 8 ms 12636 KB Output is correct
34 Correct 8 ms 12636 KB Output is correct
35 Correct 9 ms 12804 KB Output is correct
36 Correct 8 ms 12740 KB Output is correct
37 Correct 8 ms 12636 KB Output is correct
38 Correct 8 ms 12776 KB Output is correct
39 Correct 177 ms 31512 KB Output is correct
40 Correct 152 ms 31572 KB Output is correct
41 Correct 186 ms 31312 KB Output is correct
42 Correct 176 ms 31304 KB Output is correct
43 Correct 164 ms 31568 KB Output is correct
44 Correct 163 ms 31568 KB Output is correct
45 Correct 88 ms 30288 KB Output is correct
46 Correct 102 ms 30436 KB Output is correct
47 Correct 175 ms 31316 KB Output is correct
48 Correct 158 ms 31572 KB Output is correct
49 Correct 174 ms 31316 KB Output is correct
50 Correct 149 ms 31540 KB Output is correct
51 Correct 142 ms 31052 KB Output is correct
52 Correct 216 ms 31300 KB Output is correct
53 Correct 164 ms 31572 KB Output is correct
54 Correct 150 ms 31572 KB Output is correct
55 Correct 187 ms 31056 KB Output is correct
56 Correct 143 ms 30800 KB Output is correct
57 Correct 106 ms 30016 KB Output is correct
58 Correct 124 ms 30308 KB Output is correct
59 Correct 225 ms 31316 KB Output is correct
60 Correct 205 ms 31556 KB Output is correct
61 Correct 225 ms 31440 KB Output is correct
62 Correct 215 ms 31316 KB Output is correct
63 Correct 194 ms 31808 KB Output is correct
64 Correct 197 ms 31572 KB Output is correct
65 Correct 172 ms 30648 KB Output is correct
66 Correct 220 ms 31572 KB Output is correct
67 Correct 124 ms 30288 KB Output is correct
68 Correct 165 ms 31132 KB Output is correct
69 Correct 178 ms 31572 KB Output is correct
70 Correct 173 ms 31576 KB Output is correct
71 Correct 141 ms 31016 KB Output is correct
72 Correct 175 ms 31572 KB Output is correct
73 Correct 249 ms 30800 KB Output is correct
74 Correct 372 ms 31136 KB Output is correct
75 Correct 265 ms 31196 KB Output is correct
76 Correct 210 ms 30288 KB Output is correct
77 Correct 292 ms 30804 KB Output is correct
78 Correct 279 ms 31336 KB Output is correct
79 Correct 179 ms 29984 KB Output is correct
80 Correct 173 ms 29848 KB Output is correct
81 Correct 250 ms 30552 KB Output is correct
82 Correct 177 ms 30032 KB Output is correct
83 Correct 264 ms 31060 KB Output is correct
84 Correct 277 ms 31056 KB Output is correct
85 Correct 201 ms 31088 KB Output is correct
86 Correct 229 ms 31572 KB Output is correct
87 Correct 186 ms 31044 KB Output is correct
88 Correct 226 ms 31568 KB Output is correct
89 Correct 155 ms 29996 KB Output is correct
90 Correct 238 ms 31596 KB Output is correct
91 Correct 162 ms 30868 KB Output is correct
92 Correct 153 ms 30548 KB Output is correct
93 Correct 252 ms 31648 KB Output is correct
94 Correct 222 ms 31312 KB Output is correct
95 Correct 215 ms 31320 KB Output is correct
96 Correct 229 ms 31508 KB Output is correct
97 Correct 226 ms 31568 KB Output is correct
98 Correct 179 ms 30804 KB Output is correct
99 Correct 185 ms 30772 KB Output is correct
100 Correct 183 ms 30712 KB Output is correct
101 Correct 212 ms 31568 KB Output is correct
102 Correct 193 ms 31800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12780 KB Output is correct
2 Correct 9 ms 12632 KB Output is correct
3 Correct 9 ms 12636 KB Output is correct
4 Correct 9 ms 12792 KB Output is correct
5 Correct 8 ms 12636 KB Output is correct
6 Correct 8 ms 12636 KB Output is correct
7 Correct 9 ms 12688 KB Output is correct
8 Correct 10 ms 12636 KB Output is correct
9 Correct 9 ms 12988 KB Output is correct
10 Correct 11 ms 12636 KB Output is correct
11 Correct 9 ms 12820 KB Output is correct
12 Correct 10 ms 12672 KB Output is correct
13 Correct 8 ms 12636 KB Output is correct
14 Correct 9 ms 12636 KB Output is correct
15 Correct 9 ms 12532 KB Output is correct
16 Correct 9 ms 12636 KB Output is correct
17 Correct 9 ms 12636 KB Output is correct
18 Correct 9 ms 12632 KB Output is correct
19 Correct 9 ms 12636 KB Output is correct
20 Correct 10 ms 12636 KB Output is correct
21 Correct 9 ms 12796 KB Output is correct
22 Correct 11 ms 12636 KB Output is correct
23 Correct 11 ms 12808 KB Output is correct
24 Correct 10 ms 12632 KB Output is correct
25 Correct 7 ms 12820 KB Output is correct
26 Correct 8 ms 12688 KB Output is correct
27 Correct 9 ms 12632 KB Output is correct
28 Correct 9 ms 12636 KB Output is correct
29 Correct 9 ms 12636 KB Output is correct
30 Correct 9 ms 12636 KB Output is correct
31 Correct 9 ms 12808 KB Output is correct
32 Correct 9 ms 12636 KB Output is correct
33 Correct 8 ms 12636 KB Output is correct
34 Correct 8 ms 12636 KB Output is correct
35 Correct 9 ms 12804 KB Output is correct
36 Correct 8 ms 12740 KB Output is correct
37 Correct 8 ms 12636 KB Output is correct
38 Correct 8 ms 12776 KB Output is correct
39 Correct 177 ms 31512 KB Output is correct
40 Correct 152 ms 31572 KB Output is correct
41 Correct 186 ms 31312 KB Output is correct
42 Correct 176 ms 31304 KB Output is correct
43 Correct 164 ms 31568 KB Output is correct
44 Correct 163 ms 31568 KB Output is correct
45 Correct 88 ms 30288 KB Output is correct
46 Correct 102 ms 30436 KB Output is correct
47 Correct 175 ms 31316 KB Output is correct
48 Correct 158 ms 31572 KB Output is correct
49 Correct 174 ms 31316 KB Output is correct
50 Correct 149 ms 31540 KB Output is correct
51 Correct 142 ms 31052 KB Output is correct
52 Correct 216 ms 31300 KB Output is correct
53 Correct 164 ms 31572 KB Output is correct
54 Correct 150 ms 31572 KB Output is correct
55 Execution timed out 1049 ms 87376 KB Time limit exceeded
56 Halted 0 ms 0 KB -