답안 #421990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421990 2021-06-09T14:29:19 Z kai824 푸드 코트 (JOI21_foodcourt) C++17
14 / 100
1000 ms 254692 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define pii pair<int,int>

struct node{
  node *l,*r;
  int s,e,v=0;
  node(int ss,int ee){
    s=ss;e=ee;
    if(s==e){
      l=r=NULL;
    }else{
      l=new node(s,(s+e)/2);
      r=new node((s+e)/2+1,e);
    }
  }
  void update(int a,int b,int c){
    if(a<=s && e<=b){
      v+=c;
      return;
    }
    if(a<=(s+e)/2)l->update(a,b,c);
    if((s+e)/2<b)r->update(a,b,c);
  }
  int query(int p,bool clear=false){
    if(s==e){
      if(clear){
        int ans=v;
        v=0;
        return ans;
      }
      return v;
    }
    l->v+=v;r->v+=v;v=0;
    if(p<=(s+e)/2)return l->query(p,clear);
    else return r->query(p,clear);
  }
} *root;

deque<pair<int,pii> > dq[65005];//size, type, prefix sum...
int os[65005];//offset

int32_t main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int n,m,q;
  cin>>n>>m>>q;
  root=new node(1,n);

  int a,b,c,d,e;
  while(q--){
    cin>>a;
    if(a==1){//people join the queue... small number...
      cin>>b>>c>>d>>e;
      for(int i=b;i<=c;i++){
        a=root->query(i,true);
        while(dq[i].size()>0 && a>0){
          if(dq[i][0].f<=a){
            os[i]+=dq[i][0].f;
            a-=dq[i][0].f;
            dq[i].pop_front();
          }else{
            dq[i][0].f-=a;
            os[i]+=a;
            a=0;
          }
        }
        if(dq[i].size()==0){
          os[i]=0;
          dq[i].eb(e,mp(d,e));
        }else{
          dq[i].eb(e,mp(d,e+dq[i].back().s.s));
        }
      }
    }else if(a==2){//people leave the queue...
      cin>>b>>c>>d;
      root->update(b,c,d);
    }else{
      cin>>b>>c;//query shop b, cth customer...
      int i=b;
      a=root->query(i,true);
      while(dq[i].size()>0 && a>0){
        if(dq[i][0].f<=a){
          os[i]+=dq[i][0].f;
          a-=dq[i][0].f;
          dq[i].pop_front();
        }else{
          dq[i][0].f-=a;
          os[i]+=a;
          a=0;
        }
      }
      if(dq[i].size()==0 || dq[i].back().s.s-os[i]<c){
        cout<<"0\n";
        continue;
      }
      int lo=0,hi=dq[i].size()-1,mid;
      while(lo<hi){
        mid=lo+((hi-lo)/2);
        if(dq[i][mid].s.s-os[i]<c)lo=mid+1;
        else hi=mid;
      }
      cout<<dq[i][lo].s.f<<'\n';
    }
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 43852 KB Output is correct
2 Correct 75 ms 44376 KB Output is correct
3 Correct 92 ms 54076 KB Output is correct
4 Correct 128 ms 59692 KB Output is correct
5 Correct 30 ms 43016 KB Output is correct
6 Correct 30 ms 42956 KB Output is correct
7 Correct 99 ms 61760 KB Output is correct
8 Correct 110 ms 55376 KB Output is correct
9 Correct 100 ms 44472 KB Output is correct
10 Correct 102 ms 54580 KB Output is correct
11 Correct 106 ms 50376 KB Output is correct
12 Correct 99 ms 44624 KB Output is correct
13 Correct 116 ms 45032 KB Output is correct
14 Correct 141 ms 46588 KB Output is correct
15 Correct 109 ms 47152 KB Output is correct
16 Correct 156 ms 45204 KB Output is correct
17 Correct 77 ms 43632 KB Output is correct
18 Correct 90 ms 44040 KB Output is correct
19 Correct 31 ms 43232 KB Output is correct
20 Correct 31 ms 43300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 43852 KB Output is correct
2 Correct 75 ms 44376 KB Output is correct
3 Correct 92 ms 54076 KB Output is correct
4 Correct 128 ms 59692 KB Output is correct
5 Correct 30 ms 43016 KB Output is correct
6 Correct 30 ms 42956 KB Output is correct
7 Correct 99 ms 61760 KB Output is correct
8 Correct 110 ms 55376 KB Output is correct
9 Correct 100 ms 44472 KB Output is correct
10 Correct 102 ms 54580 KB Output is correct
11 Correct 106 ms 50376 KB Output is correct
12 Correct 99 ms 44624 KB Output is correct
13 Correct 116 ms 45032 KB Output is correct
14 Correct 141 ms 46588 KB Output is correct
15 Correct 109 ms 47152 KB Output is correct
16 Correct 156 ms 45204 KB Output is correct
17 Correct 77 ms 43632 KB Output is correct
18 Correct 90 ms 44040 KB Output is correct
19 Correct 31 ms 43232 KB Output is correct
20 Correct 31 ms 43300 KB Output is correct
21 Correct 75 ms 44272 KB Output is correct
22 Correct 81 ms 44620 KB Output is correct
23 Correct 118 ms 54156 KB Output is correct
24 Correct 134 ms 59956 KB Output is correct
25 Correct 33 ms 43092 KB Output is correct
26 Correct 33 ms 43000 KB Output is correct
27 Correct 99 ms 61124 KB Output is correct
28 Correct 112 ms 56388 KB Output is correct
29 Correct 104 ms 47256 KB Output is correct
30 Correct 108 ms 54212 KB Output is correct
31 Correct 106 ms 50220 KB Output is correct
32 Correct 98 ms 44420 KB Output is correct
33 Correct 109 ms 44852 KB Output is correct
34 Correct 155 ms 47512 KB Output is correct
35 Correct 138 ms 45672 KB Output is correct
36 Correct 146 ms 45176 KB Output is correct
37 Correct 32 ms 43228 KB Output is correct
38 Correct 31 ms 43280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 50340 KB Output is correct
2 Correct 164 ms 50168 KB Output is correct
3 Correct 160 ms 50212 KB Output is correct
4 Correct 139 ms 50116 KB Output is correct
5 Correct 182 ms 50320 KB Output is correct
6 Correct 175 ms 50304 KB Output is correct
7 Correct 53 ms 43552 KB Output is correct
8 Correct 54 ms 43588 KB Output is correct
9 Correct 135 ms 50120 KB Output is correct
10 Correct 136 ms 50188 KB Output is correct
11 Correct 128 ms 50244 KB Output is correct
12 Correct 125 ms 50156 KB Output is correct
13 Correct 116 ms 48104 KB Output is correct
14 Correct 138 ms 50228 KB Output is correct
15 Correct 158 ms 48104 KB Output is correct
16 Correct 158 ms 50132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 108 ms 129744 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 43852 KB Output is correct
2 Correct 75 ms 44376 KB Output is correct
3 Correct 92 ms 54076 KB Output is correct
4 Correct 128 ms 59692 KB Output is correct
5 Correct 30 ms 43016 KB Output is correct
6 Correct 30 ms 42956 KB Output is correct
7 Correct 99 ms 61760 KB Output is correct
8 Correct 110 ms 55376 KB Output is correct
9 Correct 100 ms 44472 KB Output is correct
10 Correct 102 ms 54580 KB Output is correct
11 Correct 106 ms 50376 KB Output is correct
12 Correct 99 ms 44624 KB Output is correct
13 Correct 116 ms 45032 KB Output is correct
14 Correct 141 ms 46588 KB Output is correct
15 Correct 109 ms 47152 KB Output is correct
16 Correct 156 ms 45204 KB Output is correct
17 Correct 77 ms 43632 KB Output is correct
18 Correct 90 ms 44040 KB Output is correct
19 Correct 31 ms 43232 KB Output is correct
20 Correct 31 ms 43300 KB Output is correct
21 Correct 126 ms 50340 KB Output is correct
22 Correct 164 ms 50168 KB Output is correct
23 Correct 160 ms 50212 KB Output is correct
24 Correct 139 ms 50116 KB Output is correct
25 Correct 182 ms 50320 KB Output is correct
26 Correct 175 ms 50304 KB Output is correct
27 Correct 53 ms 43552 KB Output is correct
28 Correct 54 ms 43588 KB Output is correct
29 Correct 135 ms 50120 KB Output is correct
30 Correct 136 ms 50188 KB Output is correct
31 Correct 128 ms 50244 KB Output is correct
32 Correct 125 ms 50156 KB Output is correct
33 Correct 116 ms 48104 KB Output is correct
34 Correct 138 ms 50228 KB Output is correct
35 Correct 158 ms 48104 KB Output is correct
36 Correct 158 ms 50132 KB Output is correct
37 Execution timed out 1091 ms 76456 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1101 ms 254692 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 43852 KB Output is correct
2 Correct 75 ms 44376 KB Output is correct
3 Correct 92 ms 54076 KB Output is correct
4 Correct 128 ms 59692 KB Output is correct
5 Correct 30 ms 43016 KB Output is correct
6 Correct 30 ms 42956 KB Output is correct
7 Correct 99 ms 61760 KB Output is correct
8 Correct 110 ms 55376 KB Output is correct
9 Correct 100 ms 44472 KB Output is correct
10 Correct 102 ms 54580 KB Output is correct
11 Correct 106 ms 50376 KB Output is correct
12 Correct 99 ms 44624 KB Output is correct
13 Correct 116 ms 45032 KB Output is correct
14 Correct 141 ms 46588 KB Output is correct
15 Correct 109 ms 47152 KB Output is correct
16 Correct 156 ms 45204 KB Output is correct
17 Correct 77 ms 43632 KB Output is correct
18 Correct 90 ms 44040 KB Output is correct
19 Correct 31 ms 43232 KB Output is correct
20 Correct 31 ms 43300 KB Output is correct
21 Correct 75 ms 44272 KB Output is correct
22 Correct 81 ms 44620 KB Output is correct
23 Correct 118 ms 54156 KB Output is correct
24 Correct 134 ms 59956 KB Output is correct
25 Correct 33 ms 43092 KB Output is correct
26 Correct 33 ms 43000 KB Output is correct
27 Correct 99 ms 61124 KB Output is correct
28 Correct 112 ms 56388 KB Output is correct
29 Correct 104 ms 47256 KB Output is correct
30 Correct 108 ms 54212 KB Output is correct
31 Correct 106 ms 50220 KB Output is correct
32 Correct 98 ms 44420 KB Output is correct
33 Correct 109 ms 44852 KB Output is correct
34 Correct 155 ms 47512 KB Output is correct
35 Correct 138 ms 45672 KB Output is correct
36 Correct 146 ms 45176 KB Output is correct
37 Correct 32 ms 43228 KB Output is correct
38 Correct 31 ms 43280 KB Output is correct
39 Correct 126 ms 50340 KB Output is correct
40 Correct 164 ms 50168 KB Output is correct
41 Correct 160 ms 50212 KB Output is correct
42 Correct 139 ms 50116 KB Output is correct
43 Correct 182 ms 50320 KB Output is correct
44 Correct 175 ms 50304 KB Output is correct
45 Correct 53 ms 43552 KB Output is correct
46 Correct 54 ms 43588 KB Output is correct
47 Correct 135 ms 50120 KB Output is correct
48 Correct 136 ms 50188 KB Output is correct
49 Correct 128 ms 50244 KB Output is correct
50 Correct 125 ms 50156 KB Output is correct
51 Correct 116 ms 48104 KB Output is correct
52 Correct 138 ms 50228 KB Output is correct
53 Correct 158 ms 48104 KB Output is correct
54 Correct 158 ms 50132 KB Output is correct
55 Execution timed out 1091 ms 76456 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 43852 KB Output is correct
2 Correct 75 ms 44376 KB Output is correct
3 Correct 92 ms 54076 KB Output is correct
4 Correct 128 ms 59692 KB Output is correct
5 Correct 30 ms 43016 KB Output is correct
6 Correct 30 ms 42956 KB Output is correct
7 Correct 99 ms 61760 KB Output is correct
8 Correct 110 ms 55376 KB Output is correct
9 Correct 100 ms 44472 KB Output is correct
10 Correct 102 ms 54580 KB Output is correct
11 Correct 106 ms 50376 KB Output is correct
12 Correct 99 ms 44624 KB Output is correct
13 Correct 116 ms 45032 KB Output is correct
14 Correct 141 ms 46588 KB Output is correct
15 Correct 109 ms 47152 KB Output is correct
16 Correct 156 ms 45204 KB Output is correct
17 Correct 77 ms 43632 KB Output is correct
18 Correct 90 ms 44040 KB Output is correct
19 Correct 31 ms 43232 KB Output is correct
20 Correct 31 ms 43300 KB Output is correct
21 Correct 75 ms 44272 KB Output is correct
22 Correct 81 ms 44620 KB Output is correct
23 Correct 118 ms 54156 KB Output is correct
24 Correct 134 ms 59956 KB Output is correct
25 Correct 33 ms 43092 KB Output is correct
26 Correct 33 ms 43000 KB Output is correct
27 Correct 99 ms 61124 KB Output is correct
28 Correct 112 ms 56388 KB Output is correct
29 Correct 104 ms 47256 KB Output is correct
30 Correct 108 ms 54212 KB Output is correct
31 Correct 106 ms 50220 KB Output is correct
32 Correct 98 ms 44420 KB Output is correct
33 Correct 109 ms 44852 KB Output is correct
34 Correct 155 ms 47512 KB Output is correct
35 Correct 138 ms 45672 KB Output is correct
36 Correct 146 ms 45176 KB Output is correct
37 Correct 32 ms 43228 KB Output is correct
38 Correct 31 ms 43280 KB Output is correct
39 Correct 126 ms 50340 KB Output is correct
40 Correct 164 ms 50168 KB Output is correct
41 Correct 160 ms 50212 KB Output is correct
42 Correct 139 ms 50116 KB Output is correct
43 Correct 182 ms 50320 KB Output is correct
44 Correct 175 ms 50304 KB Output is correct
45 Correct 53 ms 43552 KB Output is correct
46 Correct 54 ms 43588 KB Output is correct
47 Correct 135 ms 50120 KB Output is correct
48 Correct 136 ms 50188 KB Output is correct
49 Correct 128 ms 50244 KB Output is correct
50 Correct 125 ms 50156 KB Output is correct
51 Correct 116 ms 48104 KB Output is correct
52 Correct 138 ms 50228 KB Output is correct
53 Correct 158 ms 48104 KB Output is correct
54 Correct 158 ms 50132 KB Output is correct
55 Runtime error 108 ms 129744 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -