답안 #1065410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065410 2024-08-19T07:13:44 Z 정희우(#11119) 푸드 코트 (JOI21_foodcourt) C++17
68 / 100
1000 ms 319060 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;
const int BN=20;

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<pair<lint,int>> obj[MAX_N*BN];
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++;
}

void init_(int i,int s,int e)
{
    seg[i].minus_=seg[i].plus_=0;
    seg[i].oi=idx++;
    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:38: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]
   38 |     if(p==obj[oi].size())return 0;
      |        ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 119120 KB Output is correct
2 Correct 42 ms 119384 KB Output is correct
3 Correct 39 ms 119124 KB Output is correct
4 Correct 42 ms 119376 KB Output is correct
5 Correct 37 ms 118484 KB Output is correct
6 Correct 46 ms 118604 KB Output is correct
7 Correct 39 ms 119120 KB Output is correct
8 Correct 40 ms 119412 KB Output is correct
9 Correct 49 ms 119376 KB Output is correct
10 Correct 39 ms 119380 KB Output is correct
11 Correct 41 ms 119388 KB Output is correct
12 Correct 39 ms 119456 KB Output is correct
13 Correct 40 ms 118872 KB Output is correct
14 Correct 37 ms 118876 KB Output is correct
15 Correct 38 ms 118868 KB Output is correct
16 Correct 47 ms 119256 KB Output is correct
17 Correct 48 ms 119120 KB Output is correct
18 Correct 40 ms 119376 KB Output is correct
19 Correct 37 ms 118864 KB Output is correct
20 Correct 38 ms 118876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 119120 KB Output is correct
2 Correct 42 ms 119384 KB Output is correct
3 Correct 39 ms 119124 KB Output is correct
4 Correct 42 ms 119376 KB Output is correct
5 Correct 37 ms 118484 KB Output is correct
6 Correct 46 ms 118604 KB Output is correct
7 Correct 39 ms 119120 KB Output is correct
8 Correct 40 ms 119412 KB Output is correct
9 Correct 49 ms 119376 KB Output is correct
10 Correct 39 ms 119380 KB Output is correct
11 Correct 41 ms 119388 KB Output is correct
12 Correct 39 ms 119456 KB Output is correct
13 Correct 40 ms 118872 KB Output is correct
14 Correct 37 ms 118876 KB Output is correct
15 Correct 38 ms 118868 KB Output is correct
16 Correct 47 ms 119256 KB Output is correct
17 Correct 48 ms 119120 KB Output is correct
18 Correct 40 ms 119376 KB Output is correct
19 Correct 37 ms 118864 KB Output is correct
20 Correct 38 ms 118876 KB Output is correct
21 Correct 39 ms 119388 KB Output is correct
22 Correct 40 ms 119384 KB Output is correct
23 Correct 39 ms 119388 KB Output is correct
24 Correct 41 ms 119376 KB Output is correct
25 Correct 37 ms 118608 KB Output is correct
26 Correct 43 ms 118540 KB Output is correct
27 Correct 39 ms 119132 KB Output is correct
28 Correct 40 ms 119520 KB Output is correct
29 Correct 41 ms 119380 KB Output is correct
30 Correct 41 ms 119376 KB Output is correct
31 Correct 39 ms 119300 KB Output is correct
32 Correct 40 ms 119380 KB Output is correct
33 Correct 38 ms 118872 KB Output is correct
34 Correct 38 ms 118876 KB Output is correct
35 Correct 38 ms 119056 KB Output is correct
36 Correct 39 ms 119016 KB Output is correct
37 Correct 37 ms 118612 KB Output is correct
38 Correct 37 ms 118868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 124756 KB Output is correct
2 Correct 89 ms 126032 KB Output is correct
3 Correct 87 ms 126464 KB Output is correct
4 Correct 90 ms 126288 KB Output is correct
5 Correct 92 ms 128084 KB Output is correct
6 Correct 94 ms 127924 KB Output is correct
7 Correct 47 ms 119264 KB Output is correct
8 Correct 49 ms 119292 KB Output is correct
9 Correct 86 ms 125052 KB Output is correct
10 Correct 86 ms 125012 KB Output is correct
11 Correct 84 ms 125012 KB Output is correct
12 Correct 84 ms 125016 KB Output is correct
13 Correct 101 ms 126236 KB Output is correct
14 Correct 95 ms 126716 KB Output is correct
15 Correct 92 ms 128116 KB Output is correct
16 Correct 104 ms 128088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1066 ms 319060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 119120 KB Output is correct
2 Correct 42 ms 119384 KB Output is correct
3 Correct 39 ms 119124 KB Output is correct
4 Correct 42 ms 119376 KB Output is correct
5 Correct 37 ms 118484 KB Output is correct
6 Correct 46 ms 118604 KB Output is correct
7 Correct 39 ms 119120 KB Output is correct
8 Correct 40 ms 119412 KB Output is correct
9 Correct 49 ms 119376 KB Output is correct
10 Correct 39 ms 119380 KB Output is correct
11 Correct 41 ms 119388 KB Output is correct
12 Correct 39 ms 119456 KB Output is correct
13 Correct 40 ms 118872 KB Output is correct
14 Correct 37 ms 118876 KB Output is correct
15 Correct 38 ms 118868 KB Output is correct
16 Correct 47 ms 119256 KB Output is correct
17 Correct 48 ms 119120 KB Output is correct
18 Correct 40 ms 119376 KB Output is correct
19 Correct 37 ms 118864 KB Output is correct
20 Correct 38 ms 118876 KB Output is correct
21 Correct 82 ms 124756 KB Output is correct
22 Correct 89 ms 126032 KB Output is correct
23 Correct 87 ms 126464 KB Output is correct
24 Correct 90 ms 126288 KB Output is correct
25 Correct 92 ms 128084 KB Output is correct
26 Correct 94 ms 127924 KB Output is correct
27 Correct 47 ms 119264 KB Output is correct
28 Correct 49 ms 119292 KB Output is correct
29 Correct 86 ms 125052 KB Output is correct
30 Correct 86 ms 125012 KB Output is correct
31 Correct 84 ms 125012 KB Output is correct
32 Correct 84 ms 125016 KB Output is correct
33 Correct 101 ms 126236 KB Output is correct
34 Correct 95 ms 126716 KB Output is correct
35 Correct 92 ms 128116 KB Output is correct
36 Correct 104 ms 128088 KB Output is correct
37 Correct 240 ms 161564 KB Output is correct
38 Correct 228 ms 164452 KB Output is correct
39 Correct 48 ms 119252 KB Output is correct
40 Correct 49 ms 119320 KB Output is correct
41 Correct 206 ms 154704 KB Output is correct
42 Correct 245 ms 169808 KB Output is correct
43 Correct 256 ms 170548 KB Output is correct
44 Correct 241 ms 163412 KB Output is correct
45 Correct 254 ms 170512 KB Output is correct
46 Correct 310 ms 170840 KB Output is correct
47 Correct 94 ms 133900 KB Output is correct
48 Correct 180 ms 157320 KB Output is correct
49 Correct 177 ms 155220 KB Output is correct
50 Correct 230 ms 163920 KB Output is correct
51 Correct 248 ms 171508 KB Output is correct
52 Correct 280 ms 171600 KB Output is correct
53 Correct 76 ms 126804 KB Output is correct
54 Correct 89 ms 128188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 234 ms 164056 KB Output is correct
2 Correct 239 ms 167760 KB Output is correct
3 Correct 248 ms 169552 KB Output is correct
4 Correct 193 ms 156500 KB Output is correct
5 Correct 241 ms 164180 KB Output is correct
6 Correct 291 ms 171092 KB Output is correct
7 Correct 53 ms 119252 KB Output is correct
8 Correct 51 ms 119624 KB Output is correct
9 Correct 124 ms 139812 KB Output is correct
10 Correct 150 ms 152304 KB Output is correct
11 Correct 208 ms 165708 KB Output is correct
12 Correct 205 ms 165680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 119120 KB Output is correct
2 Correct 42 ms 119384 KB Output is correct
3 Correct 39 ms 119124 KB Output is correct
4 Correct 42 ms 119376 KB Output is correct
5 Correct 37 ms 118484 KB Output is correct
6 Correct 46 ms 118604 KB Output is correct
7 Correct 39 ms 119120 KB Output is correct
8 Correct 40 ms 119412 KB Output is correct
9 Correct 49 ms 119376 KB Output is correct
10 Correct 39 ms 119380 KB Output is correct
11 Correct 41 ms 119388 KB Output is correct
12 Correct 39 ms 119456 KB Output is correct
13 Correct 40 ms 118872 KB Output is correct
14 Correct 37 ms 118876 KB Output is correct
15 Correct 38 ms 118868 KB Output is correct
16 Correct 47 ms 119256 KB Output is correct
17 Correct 48 ms 119120 KB Output is correct
18 Correct 40 ms 119376 KB Output is correct
19 Correct 37 ms 118864 KB Output is correct
20 Correct 38 ms 118876 KB Output is correct
21 Correct 39 ms 119388 KB Output is correct
22 Correct 40 ms 119384 KB Output is correct
23 Correct 39 ms 119388 KB Output is correct
24 Correct 41 ms 119376 KB Output is correct
25 Correct 37 ms 118608 KB Output is correct
26 Correct 43 ms 118540 KB Output is correct
27 Correct 39 ms 119132 KB Output is correct
28 Correct 40 ms 119520 KB Output is correct
29 Correct 41 ms 119380 KB Output is correct
30 Correct 41 ms 119376 KB Output is correct
31 Correct 39 ms 119300 KB Output is correct
32 Correct 40 ms 119380 KB Output is correct
33 Correct 38 ms 118872 KB Output is correct
34 Correct 38 ms 118876 KB Output is correct
35 Correct 38 ms 119056 KB Output is correct
36 Correct 39 ms 119016 KB Output is correct
37 Correct 37 ms 118612 KB Output is correct
38 Correct 37 ms 118868 KB Output is correct
39 Correct 82 ms 124756 KB Output is correct
40 Correct 89 ms 126032 KB Output is correct
41 Correct 87 ms 126464 KB Output is correct
42 Correct 90 ms 126288 KB Output is correct
43 Correct 92 ms 128084 KB Output is correct
44 Correct 94 ms 127924 KB Output is correct
45 Correct 47 ms 119264 KB Output is correct
46 Correct 49 ms 119292 KB Output is correct
47 Correct 86 ms 125052 KB Output is correct
48 Correct 86 ms 125012 KB Output is correct
49 Correct 84 ms 125012 KB Output is correct
50 Correct 84 ms 125016 KB Output is correct
51 Correct 101 ms 126236 KB Output is correct
52 Correct 95 ms 126716 KB Output is correct
53 Correct 92 ms 128116 KB Output is correct
54 Correct 104 ms 128088 KB Output is correct
55 Correct 240 ms 161564 KB Output is correct
56 Correct 228 ms 164452 KB Output is correct
57 Correct 48 ms 119252 KB Output is correct
58 Correct 49 ms 119320 KB Output is correct
59 Correct 206 ms 154704 KB Output is correct
60 Correct 245 ms 169808 KB Output is correct
61 Correct 256 ms 170548 KB Output is correct
62 Correct 241 ms 163412 KB Output is correct
63 Correct 254 ms 170512 KB Output is correct
64 Correct 310 ms 170840 KB Output is correct
65 Correct 94 ms 133900 KB Output is correct
66 Correct 180 ms 157320 KB Output is correct
67 Correct 177 ms 155220 KB Output is correct
68 Correct 230 ms 163920 KB Output is correct
69 Correct 248 ms 171508 KB Output is correct
70 Correct 280 ms 171600 KB Output is correct
71 Correct 76 ms 126804 KB Output is correct
72 Correct 89 ms 128188 KB Output is correct
73 Correct 234 ms 164056 KB Output is correct
74 Correct 239 ms 167760 KB Output is correct
75 Correct 248 ms 169552 KB Output is correct
76 Correct 193 ms 156500 KB Output is correct
77 Correct 241 ms 164180 KB Output is correct
78 Correct 291 ms 171092 KB Output is correct
79 Correct 53 ms 119252 KB Output is correct
80 Correct 51 ms 119624 KB Output is correct
81 Correct 124 ms 139812 KB Output is correct
82 Correct 150 ms 152304 KB Output is correct
83 Correct 208 ms 165708 KB Output is correct
84 Correct 205 ms 165680 KB Output is correct
85 Correct 232 ms 161620 KB Output is correct
86 Correct 283 ms 167252 KB Output is correct
87 Correct 258 ms 169040 KB Output is correct
88 Correct 302 ms 175900 KB Output is correct
89 Correct 138 ms 143700 KB Output is correct
90 Correct 275 ms 169672 KB Output is correct
91 Correct 208 ms 159316 KB Output is correct
92 Correct 322 ms 157856 KB Output is correct
93 Correct 303 ms 171088 KB Output is correct
94 Correct 252 ms 163424 KB Output is correct
95 Correct 253 ms 168788 KB Output is correct
96 Correct 266 ms 170576 KB Output is correct
97 Correct 298 ms 170816 KB Output is correct
98 Correct 235 ms 162128 KB Output is correct
99 Correct 97 ms 133972 KB Output is correct
100 Correct 157 ms 151640 KB Output is correct
101 Correct 180 ms 157316 KB Output is correct
102 Correct 158 ms 146768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 119120 KB Output is correct
2 Correct 42 ms 119384 KB Output is correct
3 Correct 39 ms 119124 KB Output is correct
4 Correct 42 ms 119376 KB Output is correct
5 Correct 37 ms 118484 KB Output is correct
6 Correct 46 ms 118604 KB Output is correct
7 Correct 39 ms 119120 KB Output is correct
8 Correct 40 ms 119412 KB Output is correct
9 Correct 49 ms 119376 KB Output is correct
10 Correct 39 ms 119380 KB Output is correct
11 Correct 41 ms 119388 KB Output is correct
12 Correct 39 ms 119456 KB Output is correct
13 Correct 40 ms 118872 KB Output is correct
14 Correct 37 ms 118876 KB Output is correct
15 Correct 38 ms 118868 KB Output is correct
16 Correct 47 ms 119256 KB Output is correct
17 Correct 48 ms 119120 KB Output is correct
18 Correct 40 ms 119376 KB Output is correct
19 Correct 37 ms 118864 KB Output is correct
20 Correct 38 ms 118876 KB Output is correct
21 Correct 39 ms 119388 KB Output is correct
22 Correct 40 ms 119384 KB Output is correct
23 Correct 39 ms 119388 KB Output is correct
24 Correct 41 ms 119376 KB Output is correct
25 Correct 37 ms 118608 KB Output is correct
26 Correct 43 ms 118540 KB Output is correct
27 Correct 39 ms 119132 KB Output is correct
28 Correct 40 ms 119520 KB Output is correct
29 Correct 41 ms 119380 KB Output is correct
30 Correct 41 ms 119376 KB Output is correct
31 Correct 39 ms 119300 KB Output is correct
32 Correct 40 ms 119380 KB Output is correct
33 Correct 38 ms 118872 KB Output is correct
34 Correct 38 ms 118876 KB Output is correct
35 Correct 38 ms 119056 KB Output is correct
36 Correct 39 ms 119016 KB Output is correct
37 Correct 37 ms 118612 KB Output is correct
38 Correct 37 ms 118868 KB Output is correct
39 Correct 82 ms 124756 KB Output is correct
40 Correct 89 ms 126032 KB Output is correct
41 Correct 87 ms 126464 KB Output is correct
42 Correct 90 ms 126288 KB Output is correct
43 Correct 92 ms 128084 KB Output is correct
44 Correct 94 ms 127924 KB Output is correct
45 Correct 47 ms 119264 KB Output is correct
46 Correct 49 ms 119292 KB Output is correct
47 Correct 86 ms 125052 KB Output is correct
48 Correct 86 ms 125012 KB Output is correct
49 Correct 84 ms 125012 KB Output is correct
50 Correct 84 ms 125016 KB Output is correct
51 Correct 101 ms 126236 KB Output is correct
52 Correct 95 ms 126716 KB Output is correct
53 Correct 92 ms 128116 KB Output is correct
54 Correct 104 ms 128088 KB Output is correct
55 Execution timed out 1066 ms 319060 KB Time limit exceeded
56 Halted 0 ms 0 KB -