Submission #1065406

# Submission time Handle Problem Language Result Execution time Memory
1065406 2024-08-19T07:09:56 Z 정희우(#11119) Food Court (JOI21_foodcourt) C++17
68 / 100
1000 ms 260656 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())return;
    if(obj[p.oi].size()==1)pushobj(c.oi,obj[p.oi][0].first,obj[p.oi][0].second);
    else 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;
    if(obj[seg[i].oi].size()==1)
    {
        obj[seg[i].oi].clear();
        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;
      |        ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1276 KB Output is correct
2 Correct 3 ms 1456 KB Output is correct
3 Correct 3 ms 1328 KB Output is correct
4 Correct 4 ms 1652 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 5 ms 1652 KB Output is correct
8 Correct 4 ms 1412 KB Output is correct
9 Correct 6 ms 1656 KB Output is correct
10 Correct 5 ms 1400 KB Output is correct
11 Correct 4 ms 1652 KB Output is correct
12 Correct 3 ms 1652 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
16 Correct 3 ms 1084 KB Output is correct
17 Correct 3 ms 1460 KB Output is correct
18 Correct 4 ms 1648 KB Output is correct
19 Correct 2 ms 772 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1276 KB Output is correct
2 Correct 3 ms 1456 KB Output is correct
3 Correct 3 ms 1328 KB Output is correct
4 Correct 4 ms 1652 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 5 ms 1652 KB Output is correct
8 Correct 4 ms 1412 KB Output is correct
9 Correct 6 ms 1656 KB Output is correct
10 Correct 5 ms 1400 KB Output is correct
11 Correct 4 ms 1652 KB Output is correct
12 Correct 3 ms 1652 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
16 Correct 3 ms 1084 KB Output is correct
17 Correct 3 ms 1460 KB Output is correct
18 Correct 4 ms 1648 KB Output is correct
19 Correct 2 ms 772 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 4 ms 1432 KB Output is correct
22 Correct 4 ms 1400 KB Output is correct
23 Correct 4 ms 1540 KB Output is correct
24 Correct 4 ms 1652 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 1396 KB Output is correct
28 Correct 4 ms 1652 KB Output is correct
29 Correct 5 ms 1648 KB Output is correct
30 Correct 4 ms 1396 KB Output is correct
31 Correct 4 ms 1440 KB Output is correct
32 Correct 5 ms 1404 KB Output is correct
33 Correct 1 ms 864 KB Output is correct
34 Correct 2 ms 872 KB Output is correct
35 Correct 2 ms 1120 KB Output is correct
36 Correct 3 ms 1088 KB Output is correct
37 Correct 1 ms 612 KB Output is correct
38 Correct 2 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 13456 KB Output is correct
2 Correct 63 ms 13796 KB Output is correct
3 Correct 60 ms 13624 KB Output is correct
4 Correct 53 ms 14008 KB Output is correct
5 Correct 70 ms 15004 KB Output is correct
6 Correct 67 ms 15272 KB Output is correct
7 Correct 12 ms 1004 KB Output is correct
8 Correct 14 ms 1244 KB Output is correct
9 Correct 55 ms 12388 KB Output is correct
10 Correct 52 ms 13260 KB Output is correct
11 Correct 52 ms 14024 KB Output is correct
12 Correct 53 ms 13164 KB Output is correct
13 Correct 47 ms 10424 KB Output is correct
14 Correct 76 ms 14428 KB Output is correct
15 Correct 69 ms 14008 KB Output is correct
16 Correct 69 ms 16728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 260656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1276 KB Output is correct
2 Correct 3 ms 1456 KB Output is correct
3 Correct 3 ms 1328 KB Output is correct
4 Correct 4 ms 1652 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 5 ms 1652 KB Output is correct
8 Correct 4 ms 1412 KB Output is correct
9 Correct 6 ms 1656 KB Output is correct
10 Correct 5 ms 1400 KB Output is correct
11 Correct 4 ms 1652 KB Output is correct
12 Correct 3 ms 1652 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
16 Correct 3 ms 1084 KB Output is correct
17 Correct 3 ms 1460 KB Output is correct
18 Correct 4 ms 1648 KB Output is correct
19 Correct 2 ms 772 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 62 ms 13456 KB Output is correct
22 Correct 63 ms 13796 KB Output is correct
23 Correct 60 ms 13624 KB Output is correct
24 Correct 53 ms 14008 KB Output is correct
25 Correct 70 ms 15004 KB Output is correct
26 Correct 67 ms 15272 KB Output is correct
27 Correct 12 ms 1004 KB Output is correct
28 Correct 14 ms 1244 KB Output is correct
29 Correct 55 ms 12388 KB Output is correct
30 Correct 52 ms 13260 KB Output is correct
31 Correct 52 ms 14024 KB Output is correct
32 Correct 53 ms 13164 KB Output is correct
33 Correct 47 ms 10424 KB Output is correct
34 Correct 76 ms 14428 KB Output is correct
35 Correct 69 ms 14008 KB Output is correct
36 Correct 69 ms 16728 KB Output is correct
37 Correct 214 ms 66532 KB Output is correct
38 Correct 207 ms 68244 KB Output is correct
39 Correct 13 ms 992 KB Output is correct
40 Correct 12 ms 1240 KB Output is correct
41 Correct 183 ms 47268 KB Output is correct
42 Correct 237 ms 70168 KB Output is correct
43 Correct 230 ms 70524 KB Output is correct
44 Correct 266 ms 67248 KB Output is correct
45 Correct 245 ms 69176 KB Output is correct
46 Correct 236 ms 70812 KB Output is correct
47 Correct 62 ms 28820 KB Output is correct
48 Correct 149 ms 51240 KB Output is correct
49 Correct 149 ms 49056 KB Output is correct
50 Correct 241 ms 66008 KB Output is correct
51 Correct 245 ms 70188 KB Output is correct
52 Correct 236 ms 70420 KB Output is correct
53 Correct 50 ms 17856 KB Output is correct
54 Correct 57 ms 15028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 67276 KB Output is correct
2 Correct 292 ms 69064 KB Output is correct
3 Correct 244 ms 67036 KB Output is correct
4 Correct 161 ms 49312 KB Output is correct
5 Correct 228 ms 67408 KB Output is correct
6 Correct 287 ms 67972 KB Output is correct
7 Correct 15 ms 992 KB Output is correct
8 Correct 16 ms 1748 KB Output is correct
9 Correct 123 ms 32776 KB Output is correct
10 Correct 122 ms 45992 KB Output is correct
11 Correct 177 ms 60780 KB Output is correct
12 Correct 165 ms 60844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1276 KB Output is correct
2 Correct 3 ms 1456 KB Output is correct
3 Correct 3 ms 1328 KB Output is correct
4 Correct 4 ms 1652 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 5 ms 1652 KB Output is correct
8 Correct 4 ms 1412 KB Output is correct
9 Correct 6 ms 1656 KB Output is correct
10 Correct 5 ms 1400 KB Output is correct
11 Correct 4 ms 1652 KB Output is correct
12 Correct 3 ms 1652 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
16 Correct 3 ms 1084 KB Output is correct
17 Correct 3 ms 1460 KB Output is correct
18 Correct 4 ms 1648 KB Output is correct
19 Correct 2 ms 772 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 4 ms 1432 KB Output is correct
22 Correct 4 ms 1400 KB Output is correct
23 Correct 4 ms 1540 KB Output is correct
24 Correct 4 ms 1652 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 1396 KB Output is correct
28 Correct 4 ms 1652 KB Output is correct
29 Correct 5 ms 1648 KB Output is correct
30 Correct 4 ms 1396 KB Output is correct
31 Correct 4 ms 1440 KB Output is correct
32 Correct 5 ms 1404 KB Output is correct
33 Correct 1 ms 864 KB Output is correct
34 Correct 2 ms 872 KB Output is correct
35 Correct 2 ms 1120 KB Output is correct
36 Correct 3 ms 1088 KB Output is correct
37 Correct 1 ms 612 KB Output is correct
38 Correct 2 ms 864 KB Output is correct
39 Correct 62 ms 13456 KB Output is correct
40 Correct 63 ms 13796 KB Output is correct
41 Correct 60 ms 13624 KB Output is correct
42 Correct 53 ms 14008 KB Output is correct
43 Correct 70 ms 15004 KB Output is correct
44 Correct 67 ms 15272 KB Output is correct
45 Correct 12 ms 1004 KB Output is correct
46 Correct 14 ms 1244 KB Output is correct
47 Correct 55 ms 12388 KB Output is correct
48 Correct 52 ms 13260 KB Output is correct
49 Correct 52 ms 14024 KB Output is correct
50 Correct 53 ms 13164 KB Output is correct
51 Correct 47 ms 10424 KB Output is correct
52 Correct 76 ms 14428 KB Output is correct
53 Correct 69 ms 14008 KB Output is correct
54 Correct 69 ms 16728 KB Output is correct
55 Correct 214 ms 66532 KB Output is correct
56 Correct 207 ms 68244 KB Output is correct
57 Correct 13 ms 992 KB Output is correct
58 Correct 12 ms 1240 KB Output is correct
59 Correct 183 ms 47268 KB Output is correct
60 Correct 237 ms 70168 KB Output is correct
61 Correct 230 ms 70524 KB Output is correct
62 Correct 266 ms 67248 KB Output is correct
63 Correct 245 ms 69176 KB Output is correct
64 Correct 236 ms 70812 KB Output is correct
65 Correct 62 ms 28820 KB Output is correct
66 Correct 149 ms 51240 KB Output is correct
67 Correct 149 ms 49056 KB Output is correct
68 Correct 241 ms 66008 KB Output is correct
69 Correct 245 ms 70188 KB Output is correct
70 Correct 236 ms 70420 KB Output is correct
71 Correct 50 ms 17856 KB Output is correct
72 Correct 57 ms 15028 KB Output is correct
73 Correct 227 ms 67276 KB Output is correct
74 Correct 292 ms 69064 KB Output is correct
75 Correct 244 ms 67036 KB Output is correct
76 Correct 161 ms 49312 KB Output is correct
77 Correct 228 ms 67408 KB Output is correct
78 Correct 287 ms 67972 KB Output is correct
79 Correct 15 ms 992 KB Output is correct
80 Correct 16 ms 1748 KB Output is correct
81 Correct 123 ms 32776 KB Output is correct
82 Correct 122 ms 45992 KB Output is correct
83 Correct 177 ms 60780 KB Output is correct
84 Correct 165 ms 60844 KB Output is correct
85 Correct 196 ms 68712 KB Output is correct
86 Correct 228 ms 66728 KB Output is correct
87 Correct 217 ms 69804 KB Output is correct
88 Correct 257 ms 76960 KB Output is correct
89 Correct 106 ms 35760 KB Output is correct
90 Correct 221 ms 69800 KB Output is correct
91 Correct 162 ms 54440 KB Output is correct
92 Correct 189 ms 52908 KB Output is correct
93 Correct 228 ms 70764 KB Output is correct
94 Correct 201 ms 67760 KB Output is correct
95 Correct 227 ms 69804 KB Output is correct
96 Correct 228 ms 69580 KB Output is correct
97 Correct 241 ms 71336 KB Output is correct
98 Correct 180 ms 70572 KB Output is correct
99 Correct 74 ms 29620 KB Output is correct
100 Correct 120 ms 45224 KB Output is correct
101 Correct 183 ms 52656 KB Output is correct
102 Correct 118 ms 39108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1276 KB Output is correct
2 Correct 3 ms 1456 KB Output is correct
3 Correct 3 ms 1328 KB Output is correct
4 Correct 4 ms 1652 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 5 ms 1652 KB Output is correct
8 Correct 4 ms 1412 KB Output is correct
9 Correct 6 ms 1656 KB Output is correct
10 Correct 5 ms 1400 KB Output is correct
11 Correct 4 ms 1652 KB Output is correct
12 Correct 3 ms 1652 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
16 Correct 3 ms 1084 KB Output is correct
17 Correct 3 ms 1460 KB Output is correct
18 Correct 4 ms 1648 KB Output is correct
19 Correct 2 ms 772 KB Output is correct
20 Correct 2 ms 856 KB Output is correct
21 Correct 4 ms 1432 KB Output is correct
22 Correct 4 ms 1400 KB Output is correct
23 Correct 4 ms 1540 KB Output is correct
24 Correct 4 ms 1652 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 1396 KB Output is correct
28 Correct 4 ms 1652 KB Output is correct
29 Correct 5 ms 1648 KB Output is correct
30 Correct 4 ms 1396 KB Output is correct
31 Correct 4 ms 1440 KB Output is correct
32 Correct 5 ms 1404 KB Output is correct
33 Correct 1 ms 864 KB Output is correct
34 Correct 2 ms 872 KB Output is correct
35 Correct 2 ms 1120 KB Output is correct
36 Correct 3 ms 1088 KB Output is correct
37 Correct 1 ms 612 KB Output is correct
38 Correct 2 ms 864 KB Output is correct
39 Correct 62 ms 13456 KB Output is correct
40 Correct 63 ms 13796 KB Output is correct
41 Correct 60 ms 13624 KB Output is correct
42 Correct 53 ms 14008 KB Output is correct
43 Correct 70 ms 15004 KB Output is correct
44 Correct 67 ms 15272 KB Output is correct
45 Correct 12 ms 1004 KB Output is correct
46 Correct 14 ms 1244 KB Output is correct
47 Correct 55 ms 12388 KB Output is correct
48 Correct 52 ms 13260 KB Output is correct
49 Correct 52 ms 14024 KB Output is correct
50 Correct 53 ms 13164 KB Output is correct
51 Correct 47 ms 10424 KB Output is correct
52 Correct 76 ms 14428 KB Output is correct
53 Correct 69 ms 14008 KB Output is correct
54 Correct 69 ms 16728 KB Output is correct
55 Execution timed out 1075 ms 260656 KB Time limit exceeded
56 Halted 0 ms 0 KB -