답안 #1033283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033283 2024-07-24T15:59:43 Z alexdd 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 87468 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()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    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=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 12632 KB Output is correct
2 Correct 9 ms 12636 KB Output is correct
3 Correct 7 ms 12636 KB Output is correct
4 Correct 8 ms 12836 KB Output is correct
5 Correct 7 ms 12888 KB Output is correct
6 Correct 7 ms 12636 KB Output is correct
7 Correct 9 ms 12636 KB Output is correct
8 Correct 9 ms 12836 KB Output is correct
9 Correct 13 ms 12632 KB Output is correct
10 Correct 11 ms 12636 KB Output is correct
11 Correct 8 ms 12592 KB Output is correct
12 Correct 9 ms 12636 KB Output is correct
13 Correct 7 ms 12844 KB Output is correct
14 Correct 8 ms 12632 KB Output is correct
15 Correct 7 ms 12804 KB Output is correct
16 Correct 8 ms 12720 KB Output is correct
17 Correct 8 ms 12888 KB Output is correct
18 Correct 8 ms 12632 KB Output is correct
19 Correct 7 ms 12636 KB Output is correct
20 Correct 11 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12632 KB Output is correct
2 Correct 9 ms 12636 KB Output is correct
3 Correct 7 ms 12636 KB Output is correct
4 Correct 8 ms 12836 KB Output is correct
5 Correct 7 ms 12888 KB Output is correct
6 Correct 7 ms 12636 KB Output is correct
7 Correct 9 ms 12636 KB Output is correct
8 Correct 9 ms 12836 KB Output is correct
9 Correct 13 ms 12632 KB Output is correct
10 Correct 11 ms 12636 KB Output is correct
11 Correct 8 ms 12592 KB Output is correct
12 Correct 9 ms 12636 KB Output is correct
13 Correct 7 ms 12844 KB Output is correct
14 Correct 8 ms 12632 KB Output is correct
15 Correct 7 ms 12804 KB Output is correct
16 Correct 8 ms 12720 KB Output is correct
17 Correct 8 ms 12888 KB Output is correct
18 Correct 8 ms 12632 KB Output is correct
19 Correct 7 ms 12636 KB Output is correct
20 Correct 11 ms 12636 KB Output is correct
21 Correct 11 ms 12636 KB Output is correct
22 Correct 9 ms 12740 KB Output is correct
23 Correct 8 ms 12636 KB Output is correct
24 Correct 8 ms 12636 KB Output is correct
25 Correct 7 ms 12632 KB Output is correct
26 Correct 7 ms 12600 KB Output is correct
27 Correct 13 ms 12636 KB Output is correct
28 Correct 8 ms 12632 KB Output is correct
29 Correct 8 ms 12636 KB Output is correct
30 Correct 8 ms 12608 KB Output is correct
31 Correct 8 ms 12636 KB Output is correct
32 Correct 8 ms 12632 KB Output is correct
33 Correct 8 ms 12636 KB Output is correct
34 Correct 8 ms 12632 KB Output is correct
35 Correct 8 ms 12636 KB Output is correct
36 Correct 9 ms 12632 KB Output is correct
37 Correct 7 ms 12636 KB Output is correct
38 Correct 8 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 211 ms 31320 KB Output is correct
2 Correct 202 ms 31500 KB Output is correct
3 Correct 214 ms 31312 KB Output is correct
4 Correct 197 ms 31500 KB Output is correct
5 Correct 204 ms 31568 KB Output is correct
6 Correct 197 ms 31592 KB Output is correct
7 Correct 123 ms 30124 KB Output is correct
8 Correct 140 ms 30556 KB Output is correct
9 Correct 185 ms 31312 KB Output is correct
10 Correct 184 ms 31568 KB Output is correct
11 Correct 205 ms 31316 KB Output is correct
12 Correct 194 ms 31576 KB Output is correct
13 Correct 175 ms 31060 KB Output is correct
14 Correct 240 ms 31512 KB Output is correct
15 Correct 216 ms 31592 KB Output is correct
16 Correct 197 ms 31572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1096 ms 87468 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12632 KB Output is correct
2 Correct 9 ms 12636 KB Output is correct
3 Correct 7 ms 12636 KB Output is correct
4 Correct 8 ms 12836 KB Output is correct
5 Correct 7 ms 12888 KB Output is correct
6 Correct 7 ms 12636 KB Output is correct
7 Correct 9 ms 12636 KB Output is correct
8 Correct 9 ms 12836 KB Output is correct
9 Correct 13 ms 12632 KB Output is correct
10 Correct 11 ms 12636 KB Output is correct
11 Correct 8 ms 12592 KB Output is correct
12 Correct 9 ms 12636 KB Output is correct
13 Correct 7 ms 12844 KB Output is correct
14 Correct 8 ms 12632 KB Output is correct
15 Correct 7 ms 12804 KB Output is correct
16 Correct 8 ms 12720 KB Output is correct
17 Correct 8 ms 12888 KB Output is correct
18 Correct 8 ms 12632 KB Output is correct
19 Correct 7 ms 12636 KB Output is correct
20 Correct 11 ms 12636 KB Output is correct
21 Correct 211 ms 31320 KB Output is correct
22 Correct 202 ms 31500 KB Output is correct
23 Correct 214 ms 31312 KB Output is correct
24 Correct 197 ms 31500 KB Output is correct
25 Correct 204 ms 31568 KB Output is correct
26 Correct 197 ms 31592 KB Output is correct
27 Correct 123 ms 30124 KB Output is correct
28 Correct 140 ms 30556 KB Output is correct
29 Correct 185 ms 31312 KB Output is correct
30 Correct 184 ms 31568 KB Output is correct
31 Correct 205 ms 31316 KB Output is correct
32 Correct 194 ms 31576 KB Output is correct
33 Correct 175 ms 31060 KB Output is correct
34 Correct 240 ms 31512 KB Output is correct
35 Correct 216 ms 31592 KB Output is correct
36 Correct 197 ms 31572 KB Output is correct
37 Correct 218 ms 31056 KB Output is correct
38 Correct 177 ms 30792 KB Output is correct
39 Correct 101 ms 30160 KB Output is correct
40 Correct 133 ms 30312 KB Output is correct
41 Correct 200 ms 31328 KB Output is correct
42 Correct 221 ms 31572 KB Output is correct
43 Correct 213 ms 31576 KB Output is correct
44 Correct 200 ms 31320 KB Output is correct
45 Correct 199 ms 31572 KB Output is correct
46 Correct 200 ms 31588 KB Output is correct
47 Correct 158 ms 30516 KB Output is correct
48 Correct 197 ms 31644 KB Output is correct
49 Correct 130 ms 30448 KB Output is correct
50 Correct 154 ms 31060 KB Output is correct
51 Correct 182 ms 31572 KB Output is correct
52 Correct 190 ms 31640 KB Output is correct
53 Correct 128 ms 30800 KB Output is correct
54 Correct 149 ms 31568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 258 ms 30952 KB Output is correct
2 Correct 250 ms 31312 KB Output is correct
3 Correct 266 ms 31312 KB Output is correct
4 Correct 200 ms 30288 KB Output is correct
5 Correct 243 ms 30824 KB Output is correct
6 Correct 260 ms 31260 KB Output is correct
7 Correct 160 ms 30136 KB Output is correct
8 Correct 168 ms 29852 KB Output is correct
9 Correct 202 ms 30656 KB Output is correct
10 Correct 156 ms 30136 KB Output is correct
11 Correct 258 ms 31056 KB Output is correct
12 Correct 266 ms 30940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12632 KB Output is correct
2 Correct 9 ms 12636 KB Output is correct
3 Correct 7 ms 12636 KB Output is correct
4 Correct 8 ms 12836 KB Output is correct
5 Correct 7 ms 12888 KB Output is correct
6 Correct 7 ms 12636 KB Output is correct
7 Correct 9 ms 12636 KB Output is correct
8 Correct 9 ms 12836 KB Output is correct
9 Correct 13 ms 12632 KB Output is correct
10 Correct 11 ms 12636 KB Output is correct
11 Correct 8 ms 12592 KB Output is correct
12 Correct 9 ms 12636 KB Output is correct
13 Correct 7 ms 12844 KB Output is correct
14 Correct 8 ms 12632 KB Output is correct
15 Correct 7 ms 12804 KB Output is correct
16 Correct 8 ms 12720 KB Output is correct
17 Correct 8 ms 12888 KB Output is correct
18 Correct 8 ms 12632 KB Output is correct
19 Correct 7 ms 12636 KB Output is correct
20 Correct 11 ms 12636 KB Output is correct
21 Correct 11 ms 12636 KB Output is correct
22 Correct 9 ms 12740 KB Output is correct
23 Correct 8 ms 12636 KB Output is correct
24 Correct 8 ms 12636 KB Output is correct
25 Correct 7 ms 12632 KB Output is correct
26 Correct 7 ms 12600 KB Output is correct
27 Correct 13 ms 12636 KB Output is correct
28 Correct 8 ms 12632 KB Output is correct
29 Correct 8 ms 12636 KB Output is correct
30 Correct 8 ms 12608 KB Output is correct
31 Correct 8 ms 12636 KB Output is correct
32 Correct 8 ms 12632 KB Output is correct
33 Correct 8 ms 12636 KB Output is correct
34 Correct 8 ms 12632 KB Output is correct
35 Correct 8 ms 12636 KB Output is correct
36 Correct 9 ms 12632 KB Output is correct
37 Correct 7 ms 12636 KB Output is correct
38 Correct 8 ms 12636 KB Output is correct
39 Correct 211 ms 31320 KB Output is correct
40 Correct 202 ms 31500 KB Output is correct
41 Correct 214 ms 31312 KB Output is correct
42 Correct 197 ms 31500 KB Output is correct
43 Correct 204 ms 31568 KB Output is correct
44 Correct 197 ms 31592 KB Output is correct
45 Correct 123 ms 30124 KB Output is correct
46 Correct 140 ms 30556 KB Output is correct
47 Correct 185 ms 31312 KB Output is correct
48 Correct 184 ms 31568 KB Output is correct
49 Correct 205 ms 31316 KB Output is correct
50 Correct 194 ms 31576 KB Output is correct
51 Correct 175 ms 31060 KB Output is correct
52 Correct 240 ms 31512 KB Output is correct
53 Correct 216 ms 31592 KB Output is correct
54 Correct 197 ms 31572 KB Output is correct
55 Correct 218 ms 31056 KB Output is correct
56 Correct 177 ms 30792 KB Output is correct
57 Correct 101 ms 30160 KB Output is correct
58 Correct 133 ms 30312 KB Output is correct
59 Correct 200 ms 31328 KB Output is correct
60 Correct 221 ms 31572 KB Output is correct
61 Correct 213 ms 31576 KB Output is correct
62 Correct 200 ms 31320 KB Output is correct
63 Correct 199 ms 31572 KB Output is correct
64 Correct 200 ms 31588 KB Output is correct
65 Correct 158 ms 30516 KB Output is correct
66 Correct 197 ms 31644 KB Output is correct
67 Correct 130 ms 30448 KB Output is correct
68 Correct 154 ms 31060 KB Output is correct
69 Correct 182 ms 31572 KB Output is correct
70 Correct 190 ms 31640 KB Output is correct
71 Correct 128 ms 30800 KB Output is correct
72 Correct 149 ms 31568 KB Output is correct
73 Correct 258 ms 30952 KB Output is correct
74 Correct 250 ms 31312 KB Output is correct
75 Correct 266 ms 31312 KB Output is correct
76 Correct 200 ms 30288 KB Output is correct
77 Correct 243 ms 30824 KB Output is correct
78 Correct 260 ms 31260 KB Output is correct
79 Correct 160 ms 30136 KB Output is correct
80 Correct 168 ms 29852 KB Output is correct
81 Correct 202 ms 30656 KB Output is correct
82 Correct 156 ms 30136 KB Output is correct
83 Correct 258 ms 31056 KB Output is correct
84 Correct 266 ms 30940 KB Output is correct
85 Correct 179 ms 31064 KB Output is correct
86 Correct 230 ms 31568 KB Output is correct
87 Correct 158 ms 31056 KB Output is correct
88 Correct 202 ms 31568 KB Output is correct
89 Correct 127 ms 30040 KB Output is correct
90 Correct 179 ms 31604 KB Output is correct
91 Correct 157 ms 30852 KB Output is correct
92 Correct 155 ms 30556 KB Output is correct
93 Correct 188 ms 31488 KB Output is correct
94 Correct 179 ms 31324 KB Output is correct
95 Correct 188 ms 31476 KB Output is correct
96 Correct 185 ms 31568 KB Output is correct
97 Correct 195 ms 31568 KB Output is correct
98 Correct 152 ms 31056 KB Output is correct
99 Correct 157 ms 30516 KB Output is correct
100 Correct 188 ms 30660 KB Output is correct
101 Correct 228 ms 31580 KB Output is correct
102 Correct 161 ms 31832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12632 KB Output is correct
2 Correct 9 ms 12636 KB Output is correct
3 Correct 7 ms 12636 KB Output is correct
4 Correct 8 ms 12836 KB Output is correct
5 Correct 7 ms 12888 KB Output is correct
6 Correct 7 ms 12636 KB Output is correct
7 Correct 9 ms 12636 KB Output is correct
8 Correct 9 ms 12836 KB Output is correct
9 Correct 13 ms 12632 KB Output is correct
10 Correct 11 ms 12636 KB Output is correct
11 Correct 8 ms 12592 KB Output is correct
12 Correct 9 ms 12636 KB Output is correct
13 Correct 7 ms 12844 KB Output is correct
14 Correct 8 ms 12632 KB Output is correct
15 Correct 7 ms 12804 KB Output is correct
16 Correct 8 ms 12720 KB Output is correct
17 Correct 8 ms 12888 KB Output is correct
18 Correct 8 ms 12632 KB Output is correct
19 Correct 7 ms 12636 KB Output is correct
20 Correct 11 ms 12636 KB Output is correct
21 Correct 11 ms 12636 KB Output is correct
22 Correct 9 ms 12740 KB Output is correct
23 Correct 8 ms 12636 KB Output is correct
24 Correct 8 ms 12636 KB Output is correct
25 Correct 7 ms 12632 KB Output is correct
26 Correct 7 ms 12600 KB Output is correct
27 Correct 13 ms 12636 KB Output is correct
28 Correct 8 ms 12632 KB Output is correct
29 Correct 8 ms 12636 KB Output is correct
30 Correct 8 ms 12608 KB Output is correct
31 Correct 8 ms 12636 KB Output is correct
32 Correct 8 ms 12632 KB Output is correct
33 Correct 8 ms 12636 KB Output is correct
34 Correct 8 ms 12632 KB Output is correct
35 Correct 8 ms 12636 KB Output is correct
36 Correct 9 ms 12632 KB Output is correct
37 Correct 7 ms 12636 KB Output is correct
38 Correct 8 ms 12636 KB Output is correct
39 Correct 211 ms 31320 KB Output is correct
40 Correct 202 ms 31500 KB Output is correct
41 Correct 214 ms 31312 KB Output is correct
42 Correct 197 ms 31500 KB Output is correct
43 Correct 204 ms 31568 KB Output is correct
44 Correct 197 ms 31592 KB Output is correct
45 Correct 123 ms 30124 KB Output is correct
46 Correct 140 ms 30556 KB Output is correct
47 Correct 185 ms 31312 KB Output is correct
48 Correct 184 ms 31568 KB Output is correct
49 Correct 205 ms 31316 KB Output is correct
50 Correct 194 ms 31576 KB Output is correct
51 Correct 175 ms 31060 KB Output is correct
52 Correct 240 ms 31512 KB Output is correct
53 Correct 216 ms 31592 KB Output is correct
54 Correct 197 ms 31572 KB Output is correct
55 Execution timed out 1096 ms 87468 KB Time limit exceeded
56 Halted 0 ms 0 KB -