답안 #1065395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065395 2024-08-19T07:01:37 Z 정희우(#11119) 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 427876 KB
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;
using pli = pair<lint,int>;

const int MAX_N=250010;

struct Seg
{
    lint minus_,plus_;
    int oi;
    void addv(lint v)
    {
        if(plus_+v<0)
        {
            minus_+=plus_+v;
            plus_=0;
        }
        else
            plus_+=v;
    }
};

int n,m,q;
int idx=0;
vector<vector<pair<lint,int>>> obj;
Seg seg[MAX_N<<2];

int findo(int oi,lint v)
{
    int p=lower_bound(obj[oi].begin(),obj[oi].end(),(pli){v,-MAX_N})-obj[oi].begin();
    if(p==obj[oi].size())return 0;
    if(obj[oi][p].second<0)return obj[oi][p].second+MAX_N;
    if(p)v-=obj[oi][p-1].first;
    return findo(obj[oi][p].second,v);
}

void pushobj(int oi,lint v,int j)
{
    if(!obj[oi].empty())v+=obj[oi].back().first;
    obj[oi].push_back({v,j});
}

void update_down(const Seg &p,Seg &c)
{
    c.addv(p.minus_);
    c.addv(p.plus_);
    if(!obj[p.oi].empty())pushobj(c.oi,obj[p.oi].back().first,p.oi);
}

void update_lazy(int i)
{
    update_down(seg[i],seg[i<<1]);
    update_down(seg[i],seg[i<<1|1]);
    seg[i].minus_=seg[i].plus_=0;
    if(obj[seg[i].oi].empty())return;
    seg[i].oi=idx++;
    obj.push_back({});
}

void init_(int i,int s,int e)
{
    seg[i].minus_=seg[i].plus_=0;
    seg[i].oi=idx++;
    obj.push_back({});
    if(s+1==e)return;
    init_(i<<1,s,(s+e)>>1);
    init_(i<<1|1,(s+e)>>1,e);
}

void update_(int i,int s,int e,int l,int r,lint v,int c)
{
    if(s>=r || e<=l)return;
    if(l<=s && e<=r)
    {
        seg[i].addv(v);
        if(v>0)pushobj(seg[i].oi,v,c-MAX_N);
        return;
    }
    update_lazy(i);
    update_(i<<1,s,(s+e)>>1,l,r,v,c);
    update_(i<<1|1,(s+e)>>1,e,l,r,v,c);
}

int find_(int i,int s,int e,int x,lint v)
{
    if(s>x || e<=x)return 0;
    if(s==x && x+1==e)
    {
        v-=seg[i].plus_;
        if(!obj[seg[i].oi].empty())v+=obj[seg[i].oi].back().first;
        return findo(seg[i].oi,v);
    }
    update_lazy(i);
    return find_(i<<1,s,(s+e)>>1,x,v)+find_(i<<1|1,(s+e)>>1,e,x,v);
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> m >> q;
    init_(1,0,n);
    while(q--)
    {
        int t,l,r,c;
        lint v;
        cin >> t;
        if(t==1)
        {
            cin >> l >> r >> c >> v;l--;
            update_(1,0,n,l,r,v,c);
        }
        if(t==2)
        {
            cin >> l >> r >> v;l--;
            update_(1,0,n,l,r,-v,0);
        }
        if(t==3)
        {
            cin >> l >> v;l--;
            cout << find_(1,0,n,l,v) << '\n';
        }
    }
    return 0;
}

Compilation message

foodcourt.cpp: In function 'int findo(int, lint)':
foodcourt.cpp:37:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     if(p==obj[oi].size())return 0;
      |        ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1428 KB Output is correct
2 Correct 4 ms 2012 KB Output is correct
3 Correct 3 ms 2160 KB Output is correct
4 Correct 4 ms 2280 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 516 KB Output is correct
7 Correct 4 ms 1632 KB Output is correct
8 Correct 4 ms 2140 KB Output is correct
9 Correct 4 ms 2012 KB Output is correct
10 Correct 4 ms 2144 KB Output is correct
11 Correct 4 ms 2036 KB Output is correct
12 Correct 5 ms 2012 KB Output is correct
13 Correct 2 ms 1084 KB Output is correct
14 Correct 2 ms 1120 KB Output is correct
15 Correct 2 ms 1328 KB Output is correct
16 Correct 3 ms 1380 KB Output is correct
17 Correct 4 ms 1944 KB Output is correct
18 Correct 4 ms 1976 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1428 KB Output is correct
2 Correct 4 ms 2012 KB Output is correct
3 Correct 3 ms 2160 KB Output is correct
4 Correct 4 ms 2280 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 516 KB Output is correct
7 Correct 4 ms 1632 KB Output is correct
8 Correct 4 ms 2140 KB Output is correct
9 Correct 4 ms 2012 KB Output is correct
10 Correct 4 ms 2144 KB Output is correct
11 Correct 4 ms 2036 KB Output is correct
12 Correct 5 ms 2012 KB Output is correct
13 Correct 2 ms 1084 KB Output is correct
14 Correct 2 ms 1120 KB Output is correct
15 Correct 2 ms 1328 KB Output is correct
16 Correct 3 ms 1380 KB Output is correct
17 Correct 4 ms 1944 KB Output is correct
18 Correct 4 ms 1976 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 6 ms 1908 KB Output is correct
22 Correct 4 ms 2012 KB Output is correct
23 Correct 4 ms 2200 KB Output is correct
24 Correct 4 ms 2248 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 3 ms 1628 KB Output is correct
28 Correct 4 ms 2144 KB Output is correct
29 Correct 4 ms 2008 KB Output is correct
30 Correct 4 ms 2144 KB Output is correct
31 Correct 5 ms 2144 KB Output is correct
32 Correct 5 ms 2076 KB Output is correct
33 Correct 2 ms 1100 KB Output is correct
34 Correct 3 ms 1120 KB Output is correct
35 Correct 3 ms 1432 KB Output is correct
36 Correct 4 ms 1380 KB Output is correct
37 Correct 1 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 14004 KB Output is correct
2 Correct 52 ms 15532 KB Output is correct
3 Correct 51 ms 16572 KB Output is correct
4 Correct 54 ms 14796 KB Output is correct
5 Correct 62 ms 17336 KB Output is correct
6 Correct 61 ms 17840 KB Output is correct
7 Correct 12 ms 992 KB Output is correct
8 Correct 14 ms 1560 KB Output is correct
9 Correct 52 ms 14520 KB Output is correct
10 Correct 60 ms 14216 KB Output is correct
11 Correct 50 ms 14180 KB Output is correct
12 Correct 52 ms 13172 KB Output is correct
13 Correct 46 ms 16316 KB Output is correct
14 Correct 53 ms 15540 KB Output is correct
15 Correct 56 ms 17456 KB Output is correct
16 Correct 63 ms 17080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1038 ms 427876 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1428 KB Output is correct
2 Correct 4 ms 2012 KB Output is correct
3 Correct 3 ms 2160 KB Output is correct
4 Correct 4 ms 2280 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 516 KB Output is correct
7 Correct 4 ms 1632 KB Output is correct
8 Correct 4 ms 2140 KB Output is correct
9 Correct 4 ms 2012 KB Output is correct
10 Correct 4 ms 2144 KB Output is correct
11 Correct 4 ms 2036 KB Output is correct
12 Correct 5 ms 2012 KB Output is correct
13 Correct 2 ms 1084 KB Output is correct
14 Correct 2 ms 1120 KB Output is correct
15 Correct 2 ms 1328 KB Output is correct
16 Correct 3 ms 1380 KB Output is correct
17 Correct 4 ms 1944 KB Output is correct
18 Correct 4 ms 1976 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 52 ms 14004 KB Output is correct
22 Correct 52 ms 15532 KB Output is correct
23 Correct 51 ms 16572 KB Output is correct
24 Correct 54 ms 14796 KB Output is correct
25 Correct 62 ms 17336 KB Output is correct
26 Correct 61 ms 17840 KB Output is correct
27 Correct 12 ms 992 KB Output is correct
28 Correct 14 ms 1560 KB Output is correct
29 Correct 52 ms 14520 KB Output is correct
30 Correct 60 ms 14216 KB Output is correct
31 Correct 50 ms 14180 KB Output is correct
32 Correct 52 ms 13172 KB Output is correct
33 Correct 46 ms 16316 KB Output is correct
34 Correct 53 ms 15540 KB Output is correct
35 Correct 56 ms 17456 KB Output is correct
36 Correct 63 ms 17080 KB Output is correct
37 Correct 233 ms 109032 KB Output is correct
38 Correct 237 ms 86696 KB Output is correct
39 Correct 11 ms 988 KB Output is correct
40 Correct 14 ms 1520 KB Output is correct
41 Correct 201 ms 67216 KB Output is correct
42 Correct 275 ms 110400 KB Output is correct
43 Correct 279 ms 110240 KB Output is correct
44 Correct 248 ms 84964 KB Output is correct
45 Correct 297 ms 110252 KB Output is correct
46 Correct 291 ms 109220 KB Output is correct
47 Correct 76 ms 34388 KB Output is correct
48 Correct 186 ms 71080 KB Output is correct
49 Correct 198 ms 71040 KB Output is correct
50 Correct 254 ms 108692 KB Output is correct
51 Correct 295 ms 108700 KB Output is correct
52 Correct 303 ms 108724 KB Output is correct
53 Correct 44 ms 16052 KB Output is correct
54 Correct 72 ms 17584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 85976 KB Output is correct
2 Correct 297 ms 113316 KB Output is correct
3 Correct 324 ms 112820 KB Output is correct
4 Correct 229 ms 71804 KB Output is correct
5 Correct 293 ms 85224 KB Output is correct
6 Correct 309 ms 112352 KB Output is correct
7 Correct 17 ms 992 KB Output is correct
8 Correct 21 ms 1812 KB Output is correct
9 Correct 152 ms 51852 KB Output is correct
10 Correct 171 ms 59712 KB Output is correct
11 Correct 251 ms 82384 KB Output is correct
12 Correct 256 ms 82592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1428 KB Output is correct
2 Correct 4 ms 2012 KB Output is correct
3 Correct 3 ms 2160 KB Output is correct
4 Correct 4 ms 2280 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 516 KB Output is correct
7 Correct 4 ms 1632 KB Output is correct
8 Correct 4 ms 2140 KB Output is correct
9 Correct 4 ms 2012 KB Output is correct
10 Correct 4 ms 2144 KB Output is correct
11 Correct 4 ms 2036 KB Output is correct
12 Correct 5 ms 2012 KB Output is correct
13 Correct 2 ms 1084 KB Output is correct
14 Correct 2 ms 1120 KB Output is correct
15 Correct 2 ms 1328 KB Output is correct
16 Correct 3 ms 1380 KB Output is correct
17 Correct 4 ms 1944 KB Output is correct
18 Correct 4 ms 1976 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 6 ms 1908 KB Output is correct
22 Correct 4 ms 2012 KB Output is correct
23 Correct 4 ms 2200 KB Output is correct
24 Correct 4 ms 2248 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 3 ms 1628 KB Output is correct
28 Correct 4 ms 2144 KB Output is correct
29 Correct 4 ms 2008 KB Output is correct
30 Correct 4 ms 2144 KB Output is correct
31 Correct 5 ms 2144 KB Output is correct
32 Correct 5 ms 2076 KB Output is correct
33 Correct 2 ms 1100 KB Output is correct
34 Correct 3 ms 1120 KB Output is correct
35 Correct 3 ms 1432 KB Output is correct
36 Correct 4 ms 1380 KB Output is correct
37 Correct 1 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 52 ms 14004 KB Output is correct
40 Correct 52 ms 15532 KB Output is correct
41 Correct 51 ms 16572 KB Output is correct
42 Correct 54 ms 14796 KB Output is correct
43 Correct 62 ms 17336 KB Output is correct
44 Correct 61 ms 17840 KB Output is correct
45 Correct 12 ms 992 KB Output is correct
46 Correct 14 ms 1560 KB Output is correct
47 Correct 52 ms 14520 KB Output is correct
48 Correct 60 ms 14216 KB Output is correct
49 Correct 50 ms 14180 KB Output is correct
50 Correct 52 ms 13172 KB Output is correct
51 Correct 46 ms 16316 KB Output is correct
52 Correct 53 ms 15540 KB Output is correct
53 Correct 56 ms 17456 KB Output is correct
54 Correct 63 ms 17080 KB Output is correct
55 Correct 233 ms 109032 KB Output is correct
56 Correct 237 ms 86696 KB Output is correct
57 Correct 11 ms 988 KB Output is correct
58 Correct 14 ms 1520 KB Output is correct
59 Correct 201 ms 67216 KB Output is correct
60 Correct 275 ms 110400 KB Output is correct
61 Correct 279 ms 110240 KB Output is correct
62 Correct 248 ms 84964 KB Output is correct
63 Correct 297 ms 110252 KB Output is correct
64 Correct 291 ms 109220 KB Output is correct
65 Correct 76 ms 34388 KB Output is correct
66 Correct 186 ms 71080 KB Output is correct
67 Correct 198 ms 71040 KB Output is correct
68 Correct 254 ms 108692 KB Output is correct
69 Correct 295 ms 108700 KB Output is correct
70 Correct 303 ms 108724 KB Output is correct
71 Correct 44 ms 16052 KB Output is correct
72 Correct 72 ms 17584 KB Output is correct
73 Correct 292 ms 85976 KB Output is correct
74 Correct 297 ms 113316 KB Output is correct
75 Correct 324 ms 112820 KB Output is correct
76 Correct 229 ms 71804 KB Output is correct
77 Correct 293 ms 85224 KB Output is correct
78 Correct 309 ms 112352 KB Output is correct
79 Correct 17 ms 992 KB Output is correct
80 Correct 21 ms 1812 KB Output is correct
81 Correct 152 ms 51852 KB Output is correct
82 Correct 171 ms 59712 KB Output is correct
83 Correct 251 ms 82384 KB Output is correct
84 Correct 256 ms 82592 KB Output is correct
85 Correct 314 ms 110092 KB Output is correct
86 Correct 300 ms 107820 KB Output is correct
87 Correct 325 ms 111160 KB Output is correct
88 Correct 331 ms 111936 KB Output is correct
89 Correct 158 ms 57408 KB Output is correct
90 Correct 351 ms 109844 KB Output is correct
91 Correct 230 ms 79432 KB Output is correct
92 Correct 248 ms 74568 KB Output is correct
93 Correct 312 ms 108960 KB Output is correct
94 Correct 276 ms 85148 KB Output is correct
95 Correct 328 ms 109956 KB Output is correct
96 Correct 339 ms 108892 KB Output is correct
97 Correct 323 ms 108680 KB Output is correct
98 Correct 257 ms 84384 KB Output is correct
99 Correct 100 ms 33708 KB Output is correct
100 Correct 192 ms 62616 KB Output is correct
101 Correct 203 ms 70948 KB Output is correct
102 Correct 166 ms 54700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1428 KB Output is correct
2 Correct 4 ms 2012 KB Output is correct
3 Correct 3 ms 2160 KB Output is correct
4 Correct 4 ms 2280 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 516 KB Output is correct
7 Correct 4 ms 1632 KB Output is correct
8 Correct 4 ms 2140 KB Output is correct
9 Correct 4 ms 2012 KB Output is correct
10 Correct 4 ms 2144 KB Output is correct
11 Correct 4 ms 2036 KB Output is correct
12 Correct 5 ms 2012 KB Output is correct
13 Correct 2 ms 1084 KB Output is correct
14 Correct 2 ms 1120 KB Output is correct
15 Correct 2 ms 1328 KB Output is correct
16 Correct 3 ms 1380 KB Output is correct
17 Correct 4 ms 1944 KB Output is correct
18 Correct 4 ms 1976 KB Output is correct
19 Correct 2 ms 860 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 6 ms 1908 KB Output is correct
22 Correct 4 ms 2012 KB Output is correct
23 Correct 4 ms 2200 KB Output is correct
24 Correct 4 ms 2248 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 3 ms 1628 KB Output is correct
28 Correct 4 ms 2144 KB Output is correct
29 Correct 4 ms 2008 KB Output is correct
30 Correct 4 ms 2144 KB Output is correct
31 Correct 5 ms 2144 KB Output is correct
32 Correct 5 ms 2076 KB Output is correct
33 Correct 2 ms 1100 KB Output is correct
34 Correct 3 ms 1120 KB Output is correct
35 Correct 3 ms 1432 KB Output is correct
36 Correct 4 ms 1380 KB Output is correct
37 Correct 1 ms 860 KB Output is correct
38 Correct 2 ms 860 KB Output is correct
39 Correct 52 ms 14004 KB Output is correct
40 Correct 52 ms 15532 KB Output is correct
41 Correct 51 ms 16572 KB Output is correct
42 Correct 54 ms 14796 KB Output is correct
43 Correct 62 ms 17336 KB Output is correct
44 Correct 61 ms 17840 KB Output is correct
45 Correct 12 ms 992 KB Output is correct
46 Correct 14 ms 1560 KB Output is correct
47 Correct 52 ms 14520 KB Output is correct
48 Correct 60 ms 14216 KB Output is correct
49 Correct 50 ms 14180 KB Output is correct
50 Correct 52 ms 13172 KB Output is correct
51 Correct 46 ms 16316 KB Output is correct
52 Correct 53 ms 15540 KB Output is correct
53 Correct 56 ms 17456 KB Output is correct
54 Correct 63 ms 17080 KB Output is correct
55 Execution timed out 1038 ms 427876 KB Time limit exceeded
56 Halted 0 ms 0 KB -