답안 #421845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421845 2021-06-09T12:56:21 Z tqbfjotld 푸드 코트 (JOI21_foodcourt) C++14
68 / 100
1000 ms 100348 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define getchar getchar_unlocked


struct node{
    int s,e;
    int lazymin,lazych;
    int v;
    node *l,*r;
    node (int _s, int _e){
        s = _s; e = _e;
        lazymin = 0; lazych = 0;
        v = 0;
        if (s!=e){
            l = new node(s,(s+e)/2);
            r = new node((s+e)/2+1,e);
        }
    }
    void proc(){
        if (lazymin==0 && lazych==0) return;
        if (s!=e){
            l->lazymin = min(l->lazymin,l->lazych+lazymin);
            l->lazych += lazych;
            r->lazymin = min(r->lazymin,r->lazych+lazymin);
            r->lazych += lazych;
        }
        if (s==e){
            v += lazymin;
            v = max(v,0LL);
            v -= lazymin;
            v += lazych;
        }
        lazymin = 0;
        lazych = 0;
    }
    void inc(int a, int b, int val){
        proc();
        if (a<=s && e<=b){
            lazych += val;
            proc();
            return;
        }
        else if (b<=(s+e)/2){
            l->inc(a,b,val);
        }
        else if (a>(s+e)/2){
            r->inc(a,b,val);
        }
        else{
            l->inc(a,b,val);
            r->inc(a,b,val);
        }
        l->proc();
        r->proc();
    }
    void dec(int a, int b, int val){
        proc();
        if (a<=s && e<=b){
            lazych -= val;
            lazymin = min(lazymin,lazych);
            proc();
            return;
        }
        else if (b<=(s+e)/2){
            l->dec(a,b,val);
        }
        else if (a>(s+e)/2){
            r->dec(a,b,val);
        }
        else{
            l->dec(a,b,val);
            r->dec(a,b,val);
        }
        l->proc(); r->proc();
    }
    int qu(int pos){
        proc();
        if (s==e) return v;
        if (pos>(s+e)/2)return r->qu(pos);
        else return l->qu(pos);
    }
}*root;

struct q_dat{
    int l,r;
    int t,k;
    q_dat(){
        l = 0; r = 0; t = 0; k = 0;
    }
    q_dat(int _l, int _r, int _t, int _k){
        l = _l; r = _r; t = _t; k = _k;
    }
};
//vector<q_dat> query1;
int groupnum[250005];
//vector<q_dat> query2;
vector<pair<pair<int,int>,int> > query3;

int fw[250005];

void upd(int32_t pos, int val){
    while (pos<250005){
        fw[pos] += val;
        pos+=pos&-pos;
    }
}
int qu(int32_t pos){
    int ans = 0;
    while (pos>0){
        ans += fw[pos];
        pos -= pos&-pos;
    }
    return ans;
}

int numt[250005];
int ans[250005];
vector<pair<pair<int32_t,int32_t>,int32_t> > bsvals[250005];
vector<pair<pair<int32_t,int32_t>,int32_t> > bsvals2[250005];

struct node2{
    int s, e;
    int lazyval;
    node2 *l,*r;
    node2 (int _s, int _e){
        s = _s; e = _e;
        lazyval = -1;
        if (s!=e){
            l = new node2(s,(s+e)/2);
            r = new node2((s+e)/2+1,e);
        }
    }
    void proc(){
        if (lazyval==-1) return;
        if (s!=e){
            l->lazyval = lazyval;
            r->lazyval = lazyval;
            lazyval = -1;
        }
    }
    int qu(int pos){
        proc();
        if (s==e) return lazyval;
        if (pos<=(s+e)/2) return l->qu(pos);
        return r->qu(pos);
    }
    void upd(int a, int b, int val){
        proc();
        if (a<=s && e<=b) {
            lazyval = val;
            proc();
            return;
        }
        if (b<=(s+e)/2){
            l->upd(a,b,val);
        }
        else if (a>(s+e)/2){
            r->upd(a,b,val);
        }
        else{
            l->upd(a,b,val);
            r->upd(a,b,val);
        }
    }
}*root2;

int incl[250005];
int incr[250005];
int incamt[250005];
int finans[250005];

inline void scan(int &a){
    a = 0;
    char ch = ' ';
    while (ch<'0' || ch>'9') ch = getchar();
    while (ch>='0' && ch<='9'){
        a = (a<<3)+(a<<1)+ch-'0';
        ch = getchar();
    }
}

main(){
    int n,m,q;
    scan(n); scan(m); scan(q);
    root = new node(1,n);
    for (int x = 0; x<q; x++){
        int a;
        scan(a);
        if (a==1){
            int b,c,d,e;
            scan(b); scan(c); scan(d); scan(e);
            groupnum[x] = d;
           // query1.push_back(q_dat(b,c,x,e));
            root->inc(b,c,e);
            upd(b,e);
            upd(c+1,-e);
            incl[x] = b;
            incr[x] = c;
            incamt[x] = e;
        }
        else if (a==2){
            int b,c,d;
            scan(b); scan(c); scan(d);
           // query2.push_back(q_dat(b,c,x,d));
            root->dec(b,c,d);
        }
        else if (a==3){
            int b,c;
            scan(b); scan(c);
            query3.push_back({{b,c},x});
            int num = root->qu(b);
            numt[x] = qu(b)-num+c;
            incl[x] = b;
            if (num<c){
                ans[x] = -1;
            }
            //printf("%lld has %lld\n",b,numpopped[x]);
        }
    }
    for (auto x : query3){
        if (ans[x.second]==-1) continue;
        int a = -1;
        int b = x.second;
        int mid = (a+b)/2;
        bsvals[mid].push_back({{a,b},x.second});
    }
    bool found = true;
    while (found){
        found = false;
        for (int32_t k = 0; k<250005; k++){
            fw[k] = 0;
        }
        for (int32_t t = 0; t<q; t++){
            if (incamt[t]!=0){
                upd(incl[t],incamt[t]);
                upd(incr[t]+1,-incamt[t]);
            }
            for (auto x : bsvals[t]){
                if (x.first.first+1==x.first.second) {
                    ans[x.second] = x.first.second;
                    assert(ans[x.second]<x.second);
                    continue;
                }
                if (qu(incl[x.second])>=numt[x.second]){
                    bsvals2[(x.first.first+t)/2].push_back({{x.first.first,t},x.second});
                }
                else{
                    bsvals2[(x.first.second+t)/2].push_back({{t,x.first.second},x.second});
                }
                found = true;
            }
            bsvals[t].clear();
        }
        swap(bsvals2,bsvals);
    }
    root2 = new node2(1,n);
    vector<pair<pair<int,int>,int> > stuff;
    for (auto x : query3){
        if (ans[x.second]==-1) {
            continue;
        }
        stuff.push_back({{ans[x.second],incl[x.second]},x.second});
    }
    sort(stuff.begin(),stuff.end());
    int curt = 0;
    for (auto x : stuff){
        while (curt<=x.first.first){
            if (incamt[curt]!=0){
                root2->upd(incl[curt],incr[curt],curt);
                //printf("set %lld to %lld with %lld\n",incl[curt],incr[curt],curt);
            }
            curt++;
        }
        finans[x.second] = root2->qu(x.first.second);
        //printf("query %lld = %lld\n",x.first.second,finans[x.second]);
    }
    for (auto x : query3){
       // printf("ans = %lld\n",ans[x.second]);
        if (ans[x.second]==-1){
            printf("0\n");
        }
        else{
            assert(finans[x.second]!=-1);
            printf("%lld\n",groupnum[finans[x.second]]);
        }

    }
}

Compilation message

foodcourt.cpp:184:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  184 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 14540 KB Output is correct
2 Correct 32 ms 14704 KB Output is correct
3 Correct 31 ms 14512 KB Output is correct
4 Correct 45 ms 14580 KB Output is correct
5 Correct 28 ms 14184 KB Output is correct
6 Correct 30 ms 14156 KB Output is correct
7 Correct 28 ms 14528 KB Output is correct
8 Correct 32 ms 14688 KB Output is correct
9 Correct 32 ms 14676 KB Output is correct
10 Correct 28 ms 14664 KB Output is correct
11 Correct 32 ms 14668 KB Output is correct
12 Correct 28 ms 14588 KB Output is correct
13 Correct 30 ms 14528 KB Output is correct
14 Correct 29 ms 14704 KB Output is correct
15 Correct 29 ms 14516 KB Output is correct
16 Correct 30 ms 14660 KB Output is correct
17 Correct 29 ms 14480 KB Output is correct
18 Correct 31 ms 14572 KB Output is correct
19 Correct 30 ms 14472 KB Output is correct
20 Correct 32 ms 14548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 14540 KB Output is correct
2 Correct 32 ms 14704 KB Output is correct
3 Correct 31 ms 14512 KB Output is correct
4 Correct 45 ms 14580 KB Output is correct
5 Correct 28 ms 14184 KB Output is correct
6 Correct 30 ms 14156 KB Output is correct
7 Correct 28 ms 14528 KB Output is correct
8 Correct 32 ms 14688 KB Output is correct
9 Correct 32 ms 14676 KB Output is correct
10 Correct 28 ms 14664 KB Output is correct
11 Correct 32 ms 14668 KB Output is correct
12 Correct 28 ms 14588 KB Output is correct
13 Correct 30 ms 14528 KB Output is correct
14 Correct 29 ms 14704 KB Output is correct
15 Correct 29 ms 14516 KB Output is correct
16 Correct 30 ms 14660 KB Output is correct
17 Correct 29 ms 14480 KB Output is correct
18 Correct 31 ms 14572 KB Output is correct
19 Correct 30 ms 14472 KB Output is correct
20 Correct 32 ms 14548 KB Output is correct
21 Correct 29 ms 14668 KB Output is correct
22 Correct 29 ms 14700 KB Output is correct
23 Correct 30 ms 14508 KB Output is correct
24 Correct 30 ms 14684 KB Output is correct
25 Correct 28 ms 14164 KB Output is correct
26 Correct 31 ms 14188 KB Output is correct
27 Correct 29 ms 14532 KB Output is correct
28 Correct 32 ms 14588 KB Output is correct
29 Correct 29 ms 14600 KB Output is correct
30 Correct 30 ms 14560 KB Output is correct
31 Correct 32 ms 14588 KB Output is correct
32 Correct 30 ms 14668 KB Output is correct
33 Correct 28 ms 14540 KB Output is correct
34 Correct 29 ms 14632 KB Output is correct
35 Correct 29 ms 14536 KB Output is correct
36 Correct 33 ms 14592 KB Output is correct
37 Correct 29 ms 14364 KB Output is correct
38 Correct 31 ms 14552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 31820 KB Output is correct
2 Correct 173 ms 31684 KB Output is correct
3 Correct 170 ms 31852 KB Output is correct
4 Correct 169 ms 31964 KB Output is correct
5 Correct 175 ms 31760 KB Output is correct
6 Correct 167 ms 31760 KB Output is correct
7 Correct 92 ms 20272 KB Output is correct
8 Correct 91 ms 20592 KB Output is correct
9 Correct 156 ms 31552 KB Output is correct
10 Correct 146 ms 31800 KB Output is correct
11 Correct 157 ms 31612 KB Output is correct
12 Correct 182 ms 31712 KB Output is correct
13 Correct 140 ms 29192 KB Output is correct
14 Correct 167 ms 34464 KB Output is correct
15 Correct 160 ms 27588 KB Output is correct
16 Correct 180 ms 32136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 972 ms 93000 KB Output is correct
2 Correct 756 ms 79288 KB Output is correct
3 Execution timed out 1083 ms 100348 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 14540 KB Output is correct
2 Correct 32 ms 14704 KB Output is correct
3 Correct 31 ms 14512 KB Output is correct
4 Correct 45 ms 14580 KB Output is correct
5 Correct 28 ms 14184 KB Output is correct
6 Correct 30 ms 14156 KB Output is correct
7 Correct 28 ms 14528 KB Output is correct
8 Correct 32 ms 14688 KB Output is correct
9 Correct 32 ms 14676 KB Output is correct
10 Correct 28 ms 14664 KB Output is correct
11 Correct 32 ms 14668 KB Output is correct
12 Correct 28 ms 14588 KB Output is correct
13 Correct 30 ms 14528 KB Output is correct
14 Correct 29 ms 14704 KB Output is correct
15 Correct 29 ms 14516 KB Output is correct
16 Correct 30 ms 14660 KB Output is correct
17 Correct 29 ms 14480 KB Output is correct
18 Correct 31 ms 14572 KB Output is correct
19 Correct 30 ms 14472 KB Output is correct
20 Correct 32 ms 14548 KB Output is correct
21 Correct 150 ms 31820 KB Output is correct
22 Correct 173 ms 31684 KB Output is correct
23 Correct 170 ms 31852 KB Output is correct
24 Correct 169 ms 31964 KB Output is correct
25 Correct 175 ms 31760 KB Output is correct
26 Correct 167 ms 31760 KB Output is correct
27 Correct 92 ms 20272 KB Output is correct
28 Correct 91 ms 20592 KB Output is correct
29 Correct 156 ms 31552 KB Output is correct
30 Correct 146 ms 31800 KB Output is correct
31 Correct 157 ms 31612 KB Output is correct
32 Correct 182 ms 31712 KB Output is correct
33 Correct 140 ms 29192 KB Output is correct
34 Correct 167 ms 34464 KB Output is correct
35 Correct 160 ms 27588 KB Output is correct
36 Correct 180 ms 32136 KB Output is correct
37 Correct 218 ms 34388 KB Output is correct
38 Correct 210 ms 32536 KB Output is correct
39 Correct 97 ms 20016 KB Output is correct
40 Correct 100 ms 20788 KB Output is correct
41 Correct 237 ms 34040 KB Output is correct
42 Correct 228 ms 35436 KB Output is correct
43 Correct 232 ms 35612 KB Output is correct
44 Correct 231 ms 34792 KB Output is correct
45 Correct 215 ms 35472 KB Output is correct
46 Correct 278 ms 35628 KB Output is correct
47 Correct 144 ms 36584 KB Output is correct
48 Correct 199 ms 36464 KB Output is correct
49 Correct 159 ms 28832 KB Output is correct
50 Correct 222 ms 33980 KB Output is correct
51 Correct 226 ms 35104 KB Output is correct
52 Correct 255 ms 35216 KB Output is correct
53 Correct 173 ms 29560 KB Output is correct
54 Correct 225 ms 32180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 35476 KB Output is correct
2 Correct 257 ms 34640 KB Output is correct
3 Correct 290 ms 37088 KB Output is correct
4 Correct 194 ms 33964 KB Output is correct
5 Correct 247 ms 35336 KB Output is correct
6 Correct 256 ms 37060 KB Output is correct
7 Correct 136 ms 21796 KB Output is correct
8 Correct 136 ms 21328 KB Output is correct
9 Correct 187 ms 36928 KB Output is correct
10 Correct 200 ms 32892 KB Output is correct
11 Correct 237 ms 36972 KB Output is correct
12 Correct 240 ms 37048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 14540 KB Output is correct
2 Correct 32 ms 14704 KB Output is correct
3 Correct 31 ms 14512 KB Output is correct
4 Correct 45 ms 14580 KB Output is correct
5 Correct 28 ms 14184 KB Output is correct
6 Correct 30 ms 14156 KB Output is correct
7 Correct 28 ms 14528 KB Output is correct
8 Correct 32 ms 14688 KB Output is correct
9 Correct 32 ms 14676 KB Output is correct
10 Correct 28 ms 14664 KB Output is correct
11 Correct 32 ms 14668 KB Output is correct
12 Correct 28 ms 14588 KB Output is correct
13 Correct 30 ms 14528 KB Output is correct
14 Correct 29 ms 14704 KB Output is correct
15 Correct 29 ms 14516 KB Output is correct
16 Correct 30 ms 14660 KB Output is correct
17 Correct 29 ms 14480 KB Output is correct
18 Correct 31 ms 14572 KB Output is correct
19 Correct 30 ms 14472 KB Output is correct
20 Correct 32 ms 14548 KB Output is correct
21 Correct 29 ms 14668 KB Output is correct
22 Correct 29 ms 14700 KB Output is correct
23 Correct 30 ms 14508 KB Output is correct
24 Correct 30 ms 14684 KB Output is correct
25 Correct 28 ms 14164 KB Output is correct
26 Correct 31 ms 14188 KB Output is correct
27 Correct 29 ms 14532 KB Output is correct
28 Correct 32 ms 14588 KB Output is correct
29 Correct 29 ms 14600 KB Output is correct
30 Correct 30 ms 14560 KB Output is correct
31 Correct 32 ms 14588 KB Output is correct
32 Correct 30 ms 14668 KB Output is correct
33 Correct 28 ms 14540 KB Output is correct
34 Correct 29 ms 14632 KB Output is correct
35 Correct 29 ms 14536 KB Output is correct
36 Correct 33 ms 14592 KB Output is correct
37 Correct 29 ms 14364 KB Output is correct
38 Correct 31 ms 14552 KB Output is correct
39 Correct 150 ms 31820 KB Output is correct
40 Correct 173 ms 31684 KB Output is correct
41 Correct 170 ms 31852 KB Output is correct
42 Correct 169 ms 31964 KB Output is correct
43 Correct 175 ms 31760 KB Output is correct
44 Correct 167 ms 31760 KB Output is correct
45 Correct 92 ms 20272 KB Output is correct
46 Correct 91 ms 20592 KB Output is correct
47 Correct 156 ms 31552 KB Output is correct
48 Correct 146 ms 31800 KB Output is correct
49 Correct 157 ms 31612 KB Output is correct
50 Correct 182 ms 31712 KB Output is correct
51 Correct 140 ms 29192 KB Output is correct
52 Correct 167 ms 34464 KB Output is correct
53 Correct 160 ms 27588 KB Output is correct
54 Correct 180 ms 32136 KB Output is correct
55 Correct 218 ms 34388 KB Output is correct
56 Correct 210 ms 32536 KB Output is correct
57 Correct 97 ms 20016 KB Output is correct
58 Correct 100 ms 20788 KB Output is correct
59 Correct 237 ms 34040 KB Output is correct
60 Correct 228 ms 35436 KB Output is correct
61 Correct 232 ms 35612 KB Output is correct
62 Correct 231 ms 34792 KB Output is correct
63 Correct 215 ms 35472 KB Output is correct
64 Correct 278 ms 35628 KB Output is correct
65 Correct 144 ms 36584 KB Output is correct
66 Correct 199 ms 36464 KB Output is correct
67 Correct 159 ms 28832 KB Output is correct
68 Correct 222 ms 33980 KB Output is correct
69 Correct 226 ms 35104 KB Output is correct
70 Correct 255 ms 35216 KB Output is correct
71 Correct 173 ms 29560 KB Output is correct
72 Correct 225 ms 32180 KB Output is correct
73 Correct 239 ms 35476 KB Output is correct
74 Correct 257 ms 34640 KB Output is correct
75 Correct 290 ms 37088 KB Output is correct
76 Correct 194 ms 33964 KB Output is correct
77 Correct 247 ms 35336 KB Output is correct
78 Correct 256 ms 37060 KB Output is correct
79 Correct 136 ms 21796 KB Output is correct
80 Correct 136 ms 21328 KB Output is correct
81 Correct 187 ms 36928 KB Output is correct
82 Correct 200 ms 32892 KB Output is correct
83 Correct 237 ms 36972 KB Output is correct
84 Correct 240 ms 37048 KB Output is correct
85 Correct 196 ms 32680 KB Output is correct
86 Correct 221 ms 36544 KB Output is correct
87 Correct 233 ms 33568 KB Output is correct
88 Correct 254 ms 35392 KB Output is correct
89 Correct 196 ms 29240 KB Output is correct
90 Correct 242 ms 35432 KB Output is correct
91 Correct 168 ms 29512 KB Output is correct
92 Correct 185 ms 29400 KB Output is correct
93 Correct 250 ms 35572 KB Output is correct
94 Correct 274 ms 35088 KB Output is correct
95 Correct 292 ms 33980 KB Output is correct
96 Correct 217 ms 35624 KB Output is correct
97 Correct 214 ms 35616 KB Output is correct
98 Correct 195 ms 30416 KB Output is correct
99 Correct 134 ms 36492 KB Output is correct
100 Correct 190 ms 33296 KB Output is correct
101 Correct 214 ms 36536 KB Output is correct
102 Correct 188 ms 34196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 14540 KB Output is correct
2 Correct 32 ms 14704 KB Output is correct
3 Correct 31 ms 14512 KB Output is correct
4 Correct 45 ms 14580 KB Output is correct
5 Correct 28 ms 14184 KB Output is correct
6 Correct 30 ms 14156 KB Output is correct
7 Correct 28 ms 14528 KB Output is correct
8 Correct 32 ms 14688 KB Output is correct
9 Correct 32 ms 14676 KB Output is correct
10 Correct 28 ms 14664 KB Output is correct
11 Correct 32 ms 14668 KB Output is correct
12 Correct 28 ms 14588 KB Output is correct
13 Correct 30 ms 14528 KB Output is correct
14 Correct 29 ms 14704 KB Output is correct
15 Correct 29 ms 14516 KB Output is correct
16 Correct 30 ms 14660 KB Output is correct
17 Correct 29 ms 14480 KB Output is correct
18 Correct 31 ms 14572 KB Output is correct
19 Correct 30 ms 14472 KB Output is correct
20 Correct 32 ms 14548 KB Output is correct
21 Correct 29 ms 14668 KB Output is correct
22 Correct 29 ms 14700 KB Output is correct
23 Correct 30 ms 14508 KB Output is correct
24 Correct 30 ms 14684 KB Output is correct
25 Correct 28 ms 14164 KB Output is correct
26 Correct 31 ms 14188 KB Output is correct
27 Correct 29 ms 14532 KB Output is correct
28 Correct 32 ms 14588 KB Output is correct
29 Correct 29 ms 14600 KB Output is correct
30 Correct 30 ms 14560 KB Output is correct
31 Correct 32 ms 14588 KB Output is correct
32 Correct 30 ms 14668 KB Output is correct
33 Correct 28 ms 14540 KB Output is correct
34 Correct 29 ms 14632 KB Output is correct
35 Correct 29 ms 14536 KB Output is correct
36 Correct 33 ms 14592 KB Output is correct
37 Correct 29 ms 14364 KB Output is correct
38 Correct 31 ms 14552 KB Output is correct
39 Correct 150 ms 31820 KB Output is correct
40 Correct 173 ms 31684 KB Output is correct
41 Correct 170 ms 31852 KB Output is correct
42 Correct 169 ms 31964 KB Output is correct
43 Correct 175 ms 31760 KB Output is correct
44 Correct 167 ms 31760 KB Output is correct
45 Correct 92 ms 20272 KB Output is correct
46 Correct 91 ms 20592 KB Output is correct
47 Correct 156 ms 31552 KB Output is correct
48 Correct 146 ms 31800 KB Output is correct
49 Correct 157 ms 31612 KB Output is correct
50 Correct 182 ms 31712 KB Output is correct
51 Correct 140 ms 29192 KB Output is correct
52 Correct 167 ms 34464 KB Output is correct
53 Correct 160 ms 27588 KB Output is correct
54 Correct 180 ms 32136 KB Output is correct
55 Correct 972 ms 93000 KB Output is correct
56 Correct 756 ms 79288 KB Output is correct
57 Execution timed out 1083 ms 100348 KB Time limit exceeded
58 Halted 0 ms 0 KB -