답안 #1033279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033279 2024-07-24T15:57:12 Z alexdd 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 92756 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 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 - qry(1,0,q,ult,ult,1).first.first) - scazute >= x)
                {
                    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 9 ms 12632 KB Output is correct
2 Correct 10 ms 12760 KB Output is correct
3 Correct 10 ms 12636 KB Output is correct
4 Correct 9 ms 12636 KB Output is correct
5 Correct 8 ms 12636 KB Output is correct
6 Correct 8 ms 12648 KB Output is correct
7 Correct 9 ms 12636 KB Output is correct
8 Correct 10 ms 12636 KB Output is correct
9 Correct 13 ms 12716 KB Output is correct
10 Correct 10 ms 12636 KB Output is correct
11 Correct 10 ms 12740 KB Output is correct
12 Correct 10 ms 12636 KB Output is correct
13 Correct 8 ms 12636 KB Output is correct
14 Correct 9 ms 12636 KB Output is correct
15 Correct 8 ms 12636 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 12636 KB Output is correct
19 Correct 9 ms 12636 KB Output is correct
20 Correct 10 ms 12888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12632 KB Output is correct
2 Correct 10 ms 12760 KB Output is correct
3 Correct 10 ms 12636 KB Output is correct
4 Correct 9 ms 12636 KB Output is correct
5 Correct 8 ms 12636 KB Output is correct
6 Correct 8 ms 12648 KB Output is correct
7 Correct 9 ms 12636 KB Output is correct
8 Correct 10 ms 12636 KB Output is correct
9 Correct 13 ms 12716 KB Output is correct
10 Correct 10 ms 12636 KB Output is correct
11 Correct 10 ms 12740 KB Output is correct
12 Correct 10 ms 12636 KB Output is correct
13 Correct 8 ms 12636 KB Output is correct
14 Correct 9 ms 12636 KB Output is correct
15 Correct 8 ms 12636 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 12636 KB Output is correct
19 Correct 9 ms 12636 KB Output is correct
20 Correct 10 ms 12888 KB Output is correct
21 Correct 10 ms 12636 KB Output is correct
22 Correct 10 ms 12636 KB Output is correct
23 Correct 9 ms 12852 KB Output is correct
24 Correct 10 ms 12836 KB Output is correct
25 Correct 8 ms 12888 KB Output is correct
26 Correct 9 ms 12636 KB Output is correct
27 Correct 10 ms 12632 KB Output is correct
28 Correct 10 ms 12632 KB Output is correct
29 Correct 9 ms 12636 KB Output is correct
30 Correct 10 ms 12852 KB Output is correct
31 Correct 13 ms 12636 KB Output is correct
32 Correct 11 ms 12636 KB Output is correct
33 Correct 8 ms 12848 KB Output is correct
34 Correct 10 ms 12636 KB Output is correct
35 Correct 9 ms 12840 KB Output is correct
36 Correct 10 ms 12632 KB Output is correct
37 Correct 10 ms 12636 KB Output is correct
38 Correct 9 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 32596 KB Output is correct
2 Correct 171 ms 32848 KB Output is correct
3 Correct 185 ms 32616 KB Output is correct
4 Correct 178 ms 32488 KB Output is correct
5 Correct 173 ms 32596 KB Output is correct
6 Correct 183 ms 32596 KB Output is correct
7 Correct 87 ms 30796 KB Output is correct
8 Correct 100 ms 31160 KB Output is correct
9 Correct 192 ms 32520 KB Output is correct
10 Correct 168 ms 32852 KB Output is correct
11 Correct 178 ms 32596 KB Output is correct
12 Correct 168 ms 32756 KB Output is correct
13 Correct 151 ms 31828 KB Output is correct
14 Correct 166 ms 32596 KB Output is correct
15 Correct 160 ms 32848 KB Output is correct
16 Correct 219 ms 33148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 92756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12632 KB Output is correct
2 Correct 10 ms 12760 KB Output is correct
3 Correct 10 ms 12636 KB Output is correct
4 Correct 9 ms 12636 KB Output is correct
5 Correct 8 ms 12636 KB Output is correct
6 Correct 8 ms 12648 KB Output is correct
7 Correct 9 ms 12636 KB Output is correct
8 Correct 10 ms 12636 KB Output is correct
9 Correct 13 ms 12716 KB Output is correct
10 Correct 10 ms 12636 KB Output is correct
11 Correct 10 ms 12740 KB Output is correct
12 Correct 10 ms 12636 KB Output is correct
13 Correct 8 ms 12636 KB Output is correct
14 Correct 9 ms 12636 KB Output is correct
15 Correct 8 ms 12636 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 12636 KB Output is correct
19 Correct 9 ms 12636 KB Output is correct
20 Correct 10 ms 12888 KB Output is correct
21 Correct 179 ms 32596 KB Output is correct
22 Correct 171 ms 32848 KB Output is correct
23 Correct 185 ms 32616 KB Output is correct
24 Correct 178 ms 32488 KB Output is correct
25 Correct 173 ms 32596 KB Output is correct
26 Correct 183 ms 32596 KB Output is correct
27 Correct 87 ms 30796 KB Output is correct
28 Correct 100 ms 31160 KB Output is correct
29 Correct 192 ms 32520 KB Output is correct
30 Correct 168 ms 32852 KB Output is correct
31 Correct 178 ms 32596 KB Output is correct
32 Correct 168 ms 32756 KB Output is correct
33 Correct 151 ms 31828 KB Output is correct
34 Correct 166 ms 32596 KB Output is correct
35 Correct 160 ms 32848 KB Output is correct
36 Correct 219 ms 33148 KB Output is correct
37 Correct 219 ms 32084 KB Output is correct
38 Correct 194 ms 31572 KB Output is correct
39 Correct 148 ms 30672 KB Output is correct
40 Correct 192 ms 30724 KB Output is correct
41 Correct 266 ms 32336 KB Output is correct
42 Correct 258 ms 32580 KB Output is correct
43 Correct 255 ms 32580 KB Output is correct
44 Correct 323 ms 32464 KB Output is correct
45 Correct 292 ms 32620 KB Output is correct
46 Correct 262 ms 32596 KB Output is correct
47 Correct 262 ms 31440 KB Output is correct
48 Correct 295 ms 32544 KB Output is correct
49 Correct 152 ms 31064 KB Output is correct
50 Correct 199 ms 31824 KB Output is correct
51 Correct 200 ms 32704 KB Output is correct
52 Correct 193 ms 32648 KB Output is correct
53 Correct 144 ms 31828 KB Output is correct
54 Correct 181 ms 32848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 407 ms 32316 KB Output is correct
2 Correct 364 ms 32772 KB Output is correct
3 Correct 374 ms 33080 KB Output is correct
4 Correct 235 ms 31312 KB Output is correct
5 Correct 297 ms 32136 KB Output is correct
6 Correct 364 ms 32920 KB Output is correct
7 Correct 245 ms 31268 KB Output is correct
8 Correct 263 ms 31048 KB Output is correct
9 Correct 299 ms 32016 KB Output is correct
10 Correct 227 ms 31140 KB Output is correct
11 Correct 376 ms 32596 KB Output is correct
12 Correct 316 ms 32596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12632 KB Output is correct
2 Correct 10 ms 12760 KB Output is correct
3 Correct 10 ms 12636 KB Output is correct
4 Correct 9 ms 12636 KB Output is correct
5 Correct 8 ms 12636 KB Output is correct
6 Correct 8 ms 12648 KB Output is correct
7 Correct 9 ms 12636 KB Output is correct
8 Correct 10 ms 12636 KB Output is correct
9 Correct 13 ms 12716 KB Output is correct
10 Correct 10 ms 12636 KB Output is correct
11 Correct 10 ms 12740 KB Output is correct
12 Correct 10 ms 12636 KB Output is correct
13 Correct 8 ms 12636 KB Output is correct
14 Correct 9 ms 12636 KB Output is correct
15 Correct 8 ms 12636 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 12636 KB Output is correct
19 Correct 9 ms 12636 KB Output is correct
20 Correct 10 ms 12888 KB Output is correct
21 Correct 10 ms 12636 KB Output is correct
22 Correct 10 ms 12636 KB Output is correct
23 Correct 9 ms 12852 KB Output is correct
24 Correct 10 ms 12836 KB Output is correct
25 Correct 8 ms 12888 KB Output is correct
26 Correct 9 ms 12636 KB Output is correct
27 Correct 10 ms 12632 KB Output is correct
28 Correct 10 ms 12632 KB Output is correct
29 Correct 9 ms 12636 KB Output is correct
30 Correct 10 ms 12852 KB Output is correct
31 Correct 13 ms 12636 KB Output is correct
32 Correct 11 ms 12636 KB Output is correct
33 Correct 8 ms 12848 KB Output is correct
34 Correct 10 ms 12636 KB Output is correct
35 Correct 9 ms 12840 KB Output is correct
36 Correct 10 ms 12632 KB Output is correct
37 Correct 10 ms 12636 KB Output is correct
38 Correct 9 ms 12636 KB Output is correct
39 Correct 179 ms 32596 KB Output is correct
40 Correct 171 ms 32848 KB Output is correct
41 Correct 185 ms 32616 KB Output is correct
42 Correct 178 ms 32488 KB Output is correct
43 Correct 173 ms 32596 KB Output is correct
44 Correct 183 ms 32596 KB Output is correct
45 Correct 87 ms 30796 KB Output is correct
46 Correct 100 ms 31160 KB Output is correct
47 Correct 192 ms 32520 KB Output is correct
48 Correct 168 ms 32852 KB Output is correct
49 Correct 178 ms 32596 KB Output is correct
50 Correct 168 ms 32756 KB Output is correct
51 Correct 151 ms 31828 KB Output is correct
52 Correct 166 ms 32596 KB Output is correct
53 Correct 160 ms 32848 KB Output is correct
54 Correct 219 ms 33148 KB Output is correct
55 Correct 219 ms 32084 KB Output is correct
56 Correct 194 ms 31572 KB Output is correct
57 Correct 148 ms 30672 KB Output is correct
58 Correct 192 ms 30724 KB Output is correct
59 Correct 266 ms 32336 KB Output is correct
60 Correct 258 ms 32580 KB Output is correct
61 Correct 255 ms 32580 KB Output is correct
62 Correct 323 ms 32464 KB Output is correct
63 Correct 292 ms 32620 KB Output is correct
64 Correct 262 ms 32596 KB Output is correct
65 Correct 262 ms 31440 KB Output is correct
66 Correct 295 ms 32544 KB Output is correct
67 Correct 152 ms 31064 KB Output is correct
68 Correct 199 ms 31824 KB Output is correct
69 Correct 200 ms 32704 KB Output is correct
70 Correct 193 ms 32648 KB Output is correct
71 Correct 144 ms 31828 KB Output is correct
72 Correct 181 ms 32848 KB Output is correct
73 Correct 407 ms 32316 KB Output is correct
74 Correct 364 ms 32772 KB Output is correct
75 Correct 374 ms 33080 KB Output is correct
76 Correct 235 ms 31312 KB Output is correct
77 Correct 297 ms 32136 KB Output is correct
78 Correct 364 ms 32920 KB Output is correct
79 Correct 245 ms 31268 KB Output is correct
80 Correct 263 ms 31048 KB Output is correct
81 Correct 299 ms 32016 KB Output is correct
82 Correct 227 ms 31140 KB Output is correct
83 Correct 376 ms 32596 KB Output is correct
84 Correct 316 ms 32596 KB Output is correct
85 Correct 260 ms 32596 KB Output is correct
86 Correct 263 ms 33084 KB Output is correct
87 Correct 220 ms 32592 KB Output is correct
88 Correct 272 ms 33108 KB Output is correct
89 Correct 204 ms 31056 KB Output is correct
90 Correct 281 ms 33364 KB Output is correct
91 Correct 193 ms 32084 KB Output is correct
92 Correct 177 ms 31824 KB Output is correct
93 Correct 264 ms 33104 KB Output is correct
94 Correct 242 ms 33108 KB Output is correct
95 Correct 252 ms 33012 KB Output is correct
96 Correct 251 ms 33104 KB Output is correct
97 Correct 229 ms 33144 KB Output is correct
98 Correct 197 ms 32340 KB Output is correct
99 Correct 221 ms 31872 KB Output is correct
100 Correct 198 ms 31824 KB Output is correct
101 Correct 254 ms 33132 KB Output is correct
102 Correct 224 ms 33384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12632 KB Output is correct
2 Correct 10 ms 12760 KB Output is correct
3 Correct 10 ms 12636 KB Output is correct
4 Correct 9 ms 12636 KB Output is correct
5 Correct 8 ms 12636 KB Output is correct
6 Correct 8 ms 12648 KB Output is correct
7 Correct 9 ms 12636 KB Output is correct
8 Correct 10 ms 12636 KB Output is correct
9 Correct 13 ms 12716 KB Output is correct
10 Correct 10 ms 12636 KB Output is correct
11 Correct 10 ms 12740 KB Output is correct
12 Correct 10 ms 12636 KB Output is correct
13 Correct 8 ms 12636 KB Output is correct
14 Correct 9 ms 12636 KB Output is correct
15 Correct 8 ms 12636 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 12636 KB Output is correct
19 Correct 9 ms 12636 KB Output is correct
20 Correct 10 ms 12888 KB Output is correct
21 Correct 10 ms 12636 KB Output is correct
22 Correct 10 ms 12636 KB Output is correct
23 Correct 9 ms 12852 KB Output is correct
24 Correct 10 ms 12836 KB Output is correct
25 Correct 8 ms 12888 KB Output is correct
26 Correct 9 ms 12636 KB Output is correct
27 Correct 10 ms 12632 KB Output is correct
28 Correct 10 ms 12632 KB Output is correct
29 Correct 9 ms 12636 KB Output is correct
30 Correct 10 ms 12852 KB Output is correct
31 Correct 13 ms 12636 KB Output is correct
32 Correct 11 ms 12636 KB Output is correct
33 Correct 8 ms 12848 KB Output is correct
34 Correct 10 ms 12636 KB Output is correct
35 Correct 9 ms 12840 KB Output is correct
36 Correct 10 ms 12632 KB Output is correct
37 Correct 10 ms 12636 KB Output is correct
38 Correct 9 ms 12636 KB Output is correct
39 Correct 179 ms 32596 KB Output is correct
40 Correct 171 ms 32848 KB Output is correct
41 Correct 185 ms 32616 KB Output is correct
42 Correct 178 ms 32488 KB Output is correct
43 Correct 173 ms 32596 KB Output is correct
44 Correct 183 ms 32596 KB Output is correct
45 Correct 87 ms 30796 KB Output is correct
46 Correct 100 ms 31160 KB Output is correct
47 Correct 192 ms 32520 KB Output is correct
48 Correct 168 ms 32852 KB Output is correct
49 Correct 178 ms 32596 KB Output is correct
50 Correct 168 ms 32756 KB Output is correct
51 Correct 151 ms 31828 KB Output is correct
52 Correct 166 ms 32596 KB Output is correct
53 Correct 160 ms 32848 KB Output is correct
54 Correct 219 ms 33148 KB Output is correct
55 Execution timed out 1064 ms 92756 KB Time limit exceeded
56 Halted 0 ms 0 KB -