Submission #422046

# Submission time Handle Problem Language Result Execution time Memory
422046 2021-06-09T16:02:38 Z kai824 Food Court (JOI21_foodcourt) C++17
68 / 100
1000 ms 79868 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

struct node{
  node *l,*r;
  int s,e,ad=0,rm=0,rmd=0;//rmd: removed...
  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 prop(){
    if(l){
      l->update(s,e,rm);
      l->update(s,e,ad);
      l->rmd+=rmd;
    }
    if(r){
      r->update(s,e,rm);
      r->update(s,e,ad);
      r->rmd+=rmd;
    }
    rm=ad=rmd=0;
  }
  void update(int a,int b,int c){
    if(a<=s && e<=b){
      if(c<0)rmd+=min(ad,-c);
      ad+=c;
      if(ad<0){
        rm+=ad;ad=0;
      }
      return;
    }
    prop();
    if(a<=(s+e)/2)l->update(a,b,c);
    if((s+e)/2<b)r->update(a,b,c);
  }
  int query(int p,int mn){//query for rmd...
    if(s==e){
      if(ad<mn)return -1;
      return rmd;
    }
    prop();
    if(p<=(s+e)/2)return l->query(p,mn);
    else return r->query(p,mn);
  }
} *root;

const int inf=LLONG_MAX;
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define pii pair<int,int>

int ans[250005],nex=0;
struct node2{
  node2 *l,*r;
  int s,e,mm=inf;//mm stores which query is the nearest to being answered...
  int val=0;//similar to previous segtree
  vector<pii> vv;//value, answer it
  node2(int ss,int ee){
    s=ss;e=ee;
    if(s==e){
      l=r=NULL;
    }else{
      l=new node2(s,(s+e)/2);
      r=new node2((s+e)/2+1,e);
    }
  }
  void rev(){
    if(l)l->rev();if(r)r->rev();
    if(vv.size()>0)sort(vv.begin(),vv.end(),greater<pii>() );//smallest cross value behind...
  }
  void add(int p,int v,int it){//shop p, cross value v, update answer it...
    if(s==e){
      vv.eb(v,it);
      mm=min(mm,v-val);
      return;
    }
    if(p<=(s+e)/2)l->add(p,v,it);
    else r->add(p,v,it);

    mm=min(l->mm,r->mm);
  }
  void join(int a,int b,int cnt,int typ){
    if(a<=s && e<=b && cnt<mm){
      val+=cnt;
      mm-=cnt;
      return;
    }else if(s==e){
      val+=cnt;
      while(vv.size()>0 && val>=vv.back().f){
        ans[vv.back().s]=typ;
        vv.pop_back();
      }
      mm=inf;
      if(vv.size()>0)mm=vv.back().f-val;
      return;
    }
    //prop: since it was left to lazy, nothing should happen...
    l->join(s,e,val,-1);
    r->join(s,e,val,-1);
    val=0;

    if(a<=(s+e)/2)l->join(a,b,cnt,typ);
    if((s+e)/2<b)r->join(a,b,cnt,typ);

    mm=min(l->mm,r->mm);
  }
} *r2;

vector<pair<pii,pii> > mm;
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);
  r2=new node2(1,n);

  int a,b,c,d,e;
  while(q--){
    cin>>a;
    if(a==1){//people join the queue...
      cin>>b>>c>>d>>e;
      mm.eb(mp(b,c),mp(e,d));//range b to c, e customers, type d

      root->update(b,c,e);
    }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...
      e=root->query(b,c);
      //cout<<"DEBUG"<<e<<'\n';
      if(e==-1)nex++;
      else{
        c+=e;
        r2->add(b,c,nex++);
      }
    }
  }
  r2->rev();
  for(auto x:mm){
    r2->join(x.f.f,x.f.s,x.s.f,x.s.s);
  }

  for(int i=0;i<nex;i++){
    cout<<ans[i]<<'\n';
  }
  return 0;
}
/*
3 5 7
1 2 3 5 2
1 1 2 2 4
3 2 3
2 1 3 3
3 1 2
1 2 3 4 2
3 3 2
*/

Compilation message

foodcourt.cpp: In member function 'void node2::rev()':
foodcourt.cpp:78:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   78 |     if(l)l->rev();if(r)r->rev();
      |     ^~
foodcourt.cpp:78:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   78 |     if(l)l->rev();if(r)r->rev();
      |                   ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 720 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 4 ms 972 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 4 ms 976 KB Output is correct
8 Correct 5 ms 972 KB Output is correct
9 Correct 4 ms 928 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 4 ms 980 KB Output is correct
12 Correct 4 ms 972 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 2 ms 972 KB Output is correct
15 Correct 3 ms 908 KB Output is correct
16 Correct 4 ms 972 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 4 ms 972 KB Output is correct
19 Correct 3 ms 836 KB Output is correct
20 Correct 5 ms 976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 720 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 4 ms 972 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 4 ms 976 KB Output is correct
8 Correct 5 ms 972 KB Output is correct
9 Correct 4 ms 928 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 4 ms 980 KB Output is correct
12 Correct 4 ms 972 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 2 ms 972 KB Output is correct
15 Correct 3 ms 908 KB Output is correct
16 Correct 4 ms 972 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 4 ms 972 KB Output is correct
19 Correct 3 ms 836 KB Output is correct
20 Correct 5 ms 976 KB Output is correct
21 Correct 4 ms 844 KB Output is correct
22 Correct 4 ms 972 KB Output is correct
23 Correct 4 ms 716 KB Output is correct
24 Correct 6 ms 1100 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 4 ms 972 KB Output is correct
28 Correct 5 ms 980 KB Output is correct
29 Correct 4 ms 972 KB Output is correct
30 Correct 4 ms 972 KB Output is correct
31 Correct 4 ms 972 KB Output is correct
32 Correct 4 ms 976 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 2 ms 972 KB Output is correct
35 Correct 3 ms 844 KB Output is correct
36 Correct 4 ms 972 KB Output is correct
37 Correct 3 ms 844 KB Output is correct
38 Correct 4 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 20868 KB Output is correct
2 Correct 142 ms 21040 KB Output is correct
3 Correct 146 ms 20900 KB Output is correct
4 Correct 145 ms 20896 KB Output is correct
5 Correct 143 ms 21056 KB Output is correct
6 Correct 138 ms 21044 KB Output is correct
7 Correct 24 ms 2184 KB Output is correct
8 Correct 25 ms 2272 KB Output is correct
9 Correct 130 ms 20820 KB Output is correct
10 Correct 133 ms 20764 KB Output is correct
11 Correct 159 ms 20844 KB Output is correct
12 Correct 149 ms 20796 KB Output is correct
13 Correct 118 ms 15008 KB Output is correct
14 Correct 142 ms 21912 KB Output is correct
15 Correct 136 ms 15932 KB Output is correct
16 Correct 165 ms 21816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 854 ms 71928 KB Output is correct
2 Correct 725 ms 62636 KB Output is correct
3 Execution timed out 1032 ms 79868 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 720 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 4 ms 972 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 4 ms 976 KB Output is correct
8 Correct 5 ms 972 KB Output is correct
9 Correct 4 ms 928 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 4 ms 980 KB Output is correct
12 Correct 4 ms 972 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 2 ms 972 KB Output is correct
15 Correct 3 ms 908 KB Output is correct
16 Correct 4 ms 972 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 4 ms 972 KB Output is correct
19 Correct 3 ms 836 KB Output is correct
20 Correct 5 ms 976 KB Output is correct
21 Correct 154 ms 20868 KB Output is correct
22 Correct 142 ms 21040 KB Output is correct
23 Correct 146 ms 20900 KB Output is correct
24 Correct 145 ms 20896 KB Output is correct
25 Correct 143 ms 21056 KB Output is correct
26 Correct 138 ms 21044 KB Output is correct
27 Correct 24 ms 2184 KB Output is correct
28 Correct 25 ms 2272 KB Output is correct
29 Correct 130 ms 20820 KB Output is correct
30 Correct 133 ms 20764 KB Output is correct
31 Correct 159 ms 20844 KB Output is correct
32 Correct 149 ms 20796 KB Output is correct
33 Correct 118 ms 15008 KB Output is correct
34 Correct 142 ms 21912 KB Output is correct
35 Correct 136 ms 15932 KB Output is correct
36 Correct 165 ms 21816 KB Output is correct
37 Correct 167 ms 19152 KB Output is correct
38 Correct 156 ms 18980 KB Output is correct
39 Correct 20 ms 2060 KB Output is correct
40 Correct 25 ms 2128 KB Output is correct
41 Correct 170 ms 21032 KB Output is correct
42 Correct 188 ms 21068 KB Output is correct
43 Correct 190 ms 20964 KB Output is correct
44 Correct 180 ms 20920 KB Output is correct
45 Correct 227 ms 20964 KB Output is correct
46 Correct 184 ms 20940 KB Output is correct
47 Correct 82 ms 20876 KB Output is correct
48 Correct 176 ms 20884 KB Output is correct
49 Correct 127 ms 14960 KB Output is correct
50 Correct 154 ms 20396 KB Output is correct
51 Correct 248 ms 20956 KB Output is correct
52 Correct 186 ms 20936 KB Output is correct
53 Correct 120 ms 19344 KB Output is correct
54 Correct 144 ms 21840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 21256 KB Output is correct
2 Correct 185 ms 19236 KB Output is correct
3 Correct 191 ms 22304 KB Output is correct
4 Correct 170 ms 20248 KB Output is correct
5 Correct 178 ms 21160 KB Output is correct
6 Correct 215 ms 22264 KB Output is correct
7 Correct 34 ms 3512 KB Output is correct
8 Correct 29 ms 3052 KB Output is correct
9 Correct 121 ms 22208 KB Output is correct
10 Correct 137 ms 19000 KB Output is correct
11 Correct 168 ms 22284 KB Output is correct
12 Correct 169 ms 22268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 720 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 4 ms 972 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 4 ms 976 KB Output is correct
8 Correct 5 ms 972 KB Output is correct
9 Correct 4 ms 928 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 4 ms 980 KB Output is correct
12 Correct 4 ms 972 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 2 ms 972 KB Output is correct
15 Correct 3 ms 908 KB Output is correct
16 Correct 4 ms 972 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 4 ms 972 KB Output is correct
19 Correct 3 ms 836 KB Output is correct
20 Correct 5 ms 976 KB Output is correct
21 Correct 4 ms 844 KB Output is correct
22 Correct 4 ms 972 KB Output is correct
23 Correct 4 ms 716 KB Output is correct
24 Correct 6 ms 1100 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 4 ms 972 KB Output is correct
28 Correct 5 ms 980 KB Output is correct
29 Correct 4 ms 972 KB Output is correct
30 Correct 4 ms 972 KB Output is correct
31 Correct 4 ms 972 KB Output is correct
32 Correct 4 ms 976 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 2 ms 972 KB Output is correct
35 Correct 3 ms 844 KB Output is correct
36 Correct 4 ms 972 KB Output is correct
37 Correct 3 ms 844 KB Output is correct
38 Correct 4 ms 972 KB Output is correct
39 Correct 154 ms 20868 KB Output is correct
40 Correct 142 ms 21040 KB Output is correct
41 Correct 146 ms 20900 KB Output is correct
42 Correct 145 ms 20896 KB Output is correct
43 Correct 143 ms 21056 KB Output is correct
44 Correct 138 ms 21044 KB Output is correct
45 Correct 24 ms 2184 KB Output is correct
46 Correct 25 ms 2272 KB Output is correct
47 Correct 130 ms 20820 KB Output is correct
48 Correct 133 ms 20764 KB Output is correct
49 Correct 159 ms 20844 KB Output is correct
50 Correct 149 ms 20796 KB Output is correct
51 Correct 118 ms 15008 KB Output is correct
52 Correct 142 ms 21912 KB Output is correct
53 Correct 136 ms 15932 KB Output is correct
54 Correct 165 ms 21816 KB Output is correct
55 Correct 167 ms 19152 KB Output is correct
56 Correct 156 ms 18980 KB Output is correct
57 Correct 20 ms 2060 KB Output is correct
58 Correct 25 ms 2128 KB Output is correct
59 Correct 170 ms 21032 KB Output is correct
60 Correct 188 ms 21068 KB Output is correct
61 Correct 190 ms 20964 KB Output is correct
62 Correct 180 ms 20920 KB Output is correct
63 Correct 227 ms 20964 KB Output is correct
64 Correct 184 ms 20940 KB Output is correct
65 Correct 82 ms 20876 KB Output is correct
66 Correct 176 ms 20884 KB Output is correct
67 Correct 127 ms 14960 KB Output is correct
68 Correct 154 ms 20396 KB Output is correct
69 Correct 248 ms 20956 KB Output is correct
70 Correct 186 ms 20936 KB Output is correct
71 Correct 120 ms 19344 KB Output is correct
72 Correct 144 ms 21840 KB Output is correct
73 Correct 174 ms 21256 KB Output is correct
74 Correct 185 ms 19236 KB Output is correct
75 Correct 191 ms 22304 KB Output is correct
76 Correct 170 ms 20248 KB Output is correct
77 Correct 178 ms 21160 KB Output is correct
78 Correct 215 ms 22264 KB Output is correct
79 Correct 34 ms 3512 KB Output is correct
80 Correct 29 ms 3052 KB Output is correct
81 Correct 121 ms 22208 KB Output is correct
82 Correct 137 ms 19000 KB Output is correct
83 Correct 168 ms 22284 KB Output is correct
84 Correct 169 ms 22268 KB Output is correct
85 Correct 166 ms 17388 KB Output is correct
86 Correct 191 ms 21588 KB Output is correct
87 Correct 164 ms 20196 KB Output is correct
88 Correct 192 ms 21800 KB Output is correct
89 Correct 124 ms 16736 KB Output is correct
90 Correct 201 ms 21508 KB Output is correct
91 Correct 133 ms 15032 KB Output is correct
92 Correct 133 ms 15228 KB Output is correct
93 Correct 192 ms 21424 KB Output is correct
94 Correct 179 ms 21436 KB Output is correct
95 Correct 172 ms 19636 KB Output is correct
96 Correct 185 ms 21492 KB Output is correct
97 Correct 189 ms 21416 KB Output is correct
98 Correct 140 ms 15716 KB Output is correct
99 Correct 89 ms 21432 KB Output is correct
100 Correct 133 ms 18620 KB Output is correct
101 Correct 165 ms 21556 KB Output is correct
102 Correct 143 ms 21904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 720 KB Output is correct
2 Correct 4 ms 972 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 4 ms 972 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 4 ms 976 KB Output is correct
8 Correct 5 ms 972 KB Output is correct
9 Correct 4 ms 928 KB Output is correct
10 Correct 4 ms 972 KB Output is correct
11 Correct 4 ms 980 KB Output is correct
12 Correct 4 ms 972 KB Output is correct
13 Correct 2 ms 844 KB Output is correct
14 Correct 2 ms 972 KB Output is correct
15 Correct 3 ms 908 KB Output is correct
16 Correct 4 ms 972 KB Output is correct
17 Correct 4 ms 716 KB Output is correct
18 Correct 4 ms 972 KB Output is correct
19 Correct 3 ms 836 KB Output is correct
20 Correct 5 ms 976 KB Output is correct
21 Correct 4 ms 844 KB Output is correct
22 Correct 4 ms 972 KB Output is correct
23 Correct 4 ms 716 KB Output is correct
24 Correct 6 ms 1100 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 4 ms 972 KB Output is correct
28 Correct 5 ms 980 KB Output is correct
29 Correct 4 ms 972 KB Output is correct
30 Correct 4 ms 972 KB Output is correct
31 Correct 4 ms 972 KB Output is correct
32 Correct 4 ms 976 KB Output is correct
33 Correct 3 ms 844 KB Output is correct
34 Correct 2 ms 972 KB Output is correct
35 Correct 3 ms 844 KB Output is correct
36 Correct 4 ms 972 KB Output is correct
37 Correct 3 ms 844 KB Output is correct
38 Correct 4 ms 972 KB Output is correct
39 Correct 154 ms 20868 KB Output is correct
40 Correct 142 ms 21040 KB Output is correct
41 Correct 146 ms 20900 KB Output is correct
42 Correct 145 ms 20896 KB Output is correct
43 Correct 143 ms 21056 KB Output is correct
44 Correct 138 ms 21044 KB Output is correct
45 Correct 24 ms 2184 KB Output is correct
46 Correct 25 ms 2272 KB Output is correct
47 Correct 130 ms 20820 KB Output is correct
48 Correct 133 ms 20764 KB Output is correct
49 Correct 159 ms 20844 KB Output is correct
50 Correct 149 ms 20796 KB Output is correct
51 Correct 118 ms 15008 KB Output is correct
52 Correct 142 ms 21912 KB Output is correct
53 Correct 136 ms 15932 KB Output is correct
54 Correct 165 ms 21816 KB Output is correct
55 Correct 854 ms 71928 KB Output is correct
56 Correct 725 ms 62636 KB Output is correct
57 Execution timed out 1032 ms 79868 KB Time limit exceeded
58 Halted 0 ms 0 KB -