Submission #955358

# Submission time Handle Problem Language Result Execution time Memory
955358 2024-03-30T08:21:17 Z vjudge1 Food Court (JOI21_foodcourt) C++17
20 / 100
1000 ms 145588 KB
#include <bits/stdc++.h>

#pragma optimize("Ofast")
#pragma target("avx2")

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
#define int ll

const int MAX=3e5+15;
const int B=300;
const int N=104;
const int block=400;
const int maxB=MAX/B+10;
const ll inf=1e18;  
const int mod=998244353;
const int mod1=1e9+9;
const ld eps=1e-9;

int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

int binpow(int a,int n){
  if(!n)return 1;
  if(n%2==1)return a*binpow(a,n-1)%mod;
  int k=binpow(a,n/2);
  return k*k%mod;
}

int n,m,q;

struct node{
  int t,l,r;
  node(){
    t=0,l=0,r=0;
  }

  node(int tl,int tr,int s){
    t=s;
    l=tl;
    r=tr;
  }
};

struct segtree{
  vector<pii> roots;

  node t[20*MAX];
  int cur;

  void build(int v,int tl,int tr){
    if(tl==tr){
      return;
    }
    int tm=(tl+tr)/2;
    t[v].l=++cur;
    t[v].r=++cur;
    build(t[v].l,tl,tm);
    build(t[v].r,tm+1,tr);
  }

  void update(int v,int tl,int tr,int pos,int x){
    if(tl==tr){
      t[v].t+=x;
      // cout<<v<<" "<<tl<<" "<<tr<<" "<<t[v].t<<"\n";
      return;
    }
    int tm=(tl+tr)/2;
    if(pos<=tm){
      cur++;
      t[cur]=node(t[t[v].l].l,t[t[v].l].r,t[t[v].l].t);
      t[v].l=cur;
      update(t[v].l,tl,tm,pos,x);
    }
    else{
      cur++;
      // cout<<v<<" "<<cur<<" "<<t[v].r<<"\n";
      t[cur]=node(t[t[v].r].l,t[t[v].r].r,t[t[v].r].t);
      t[v].r=cur;
      update(t[v].r,tm+1,tr,pos,x);
    }
    // cout<<v<<" "<<tl<<" "<<tr<<" "<<t[v].t<<" "<<t[v].l<<" "<<t[v].r<<"\n";
    t[v].t=t[t[v].l].t+t[t[v].r].t;
    // cout<<v<<" "<<tl<<" "<<tr<<" "<<t[v].t<<" "<<t[v].l<<" "<<t[v].r<<"\n";
  }

  int get(int v,int tl,int tr,int l,int r){
    if(l>r||tl>r||l>tr)return 0;
    if(l<=tl&&tr<=r){
      return t[v].t;
    }
    int tm=(tl+tr)/2;
    return get(t[v].l,tl,tm,l,r)+get(t[v].r,tm+1,tr,l,r);
  }
}t;

int z[MAX];
int f[MAX];

void solve(){
  cin>>n>>m>>q;
  t.roots.pb({1,0});
  t.cur=1;
  t.build(1,1,n);

  for(int i=1;i<=q;i++){
    // cout<<"!!! "<<i<<"\n";
    // for(int i=1;i<=n;i++){
    //   cout<<t.get(t.roots.back().F,1,n,i,i)<<" ";
    // }
    // cout<<"\n";
    int type;
    cin>>type;
    if(type==1){
      int l,r,x;
      cin>>l>>r>>z[i]>>x;
      int nroot=++t.cur;
      int lroot=t.roots.back().F;
      t.t[nroot]=node(t.t[lroot].l,t.t[lroot].r,t.t[lroot].t);
      // cout<<x<<"\n";
      t.update(nroot,1,n,l,x);
      if(r+1<=n)t.update(nroot,1,n,r+1,-x);
      t.roots.pb({nroot,i});
    }
    else if(type==2){
      int l,r,x;
      cin>>l>>r>>x;
      for(int i=l;i<=r;i++){
        f[i]=min(f[i]+x,t.get(t.roots.back().F,1,n,1,i));
      }
    }
    else{
      int v,pos;
      cin>>v>>pos;
      pos+=f[v];
      int l=0,r=sz(t.roots)-1,res=sz(t.roots)-1;
      // cout<<f[v]<<" "<<t.get(t.roots.back().F,1,n,1,v)<<" "<<pos<<"\n";
      if(t.get(t.roots.back().F,1,n,1,v)<pos){
        cout<<0<<"\n";
        continue;
      }
      while(l<=r){
        int m=(l+r)/2;
        if(t.get(t.roots[m].F,1,n,1,v)<pos){
          l=m+1;
        }
        else{
          r=m-1;
          res=m;
        }
      }
      cout<<z[t.roots[res].S]<<"\n";
    }
  }
}

signed main(){
  //  freopen("help.in","r",stdin);
  //  freopen("help.out","w",stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // prec();
  int t=1;
  // cin>>t;  
  while(t--)solve();
}

Compilation message

foodcourt.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize("Ofast")
      | 
foodcourt.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    4 | #pragma target("avx2")
      |
# Verdict Execution time Memory Grader output
1 Correct 80 ms 143728 KB Output is correct
2 Correct 44 ms 143700 KB Output is correct
3 Correct 32 ms 143868 KB Output is correct
4 Correct 45 ms 143708 KB Output is correct
5 Correct 22 ms 143704 KB Output is correct
6 Correct 23 ms 143700 KB Output is correct
7 Correct 60 ms 143792 KB Output is correct
8 Correct 61 ms 143960 KB Output is correct
9 Correct 62 ms 143708 KB Output is correct
10 Correct 57 ms 143868 KB Output is correct
11 Correct 58 ms 143704 KB Output is correct
12 Correct 69 ms 143708 KB Output is correct
13 Correct 83 ms 143836 KB Output is correct
14 Correct 97 ms 143848 KB Output is correct
15 Correct 67 ms 143696 KB Output is correct
16 Correct 93 ms 143704 KB Output is correct
17 Correct 40 ms 143700 KB Output is correct
18 Correct 59 ms 143844 KB Output is correct
19 Correct 24 ms 143708 KB Output is correct
20 Correct 26 ms 143836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 143728 KB Output is correct
2 Correct 44 ms 143700 KB Output is correct
3 Correct 32 ms 143868 KB Output is correct
4 Correct 45 ms 143708 KB Output is correct
5 Correct 22 ms 143704 KB Output is correct
6 Correct 23 ms 143700 KB Output is correct
7 Correct 60 ms 143792 KB Output is correct
8 Correct 61 ms 143960 KB Output is correct
9 Correct 62 ms 143708 KB Output is correct
10 Correct 57 ms 143868 KB Output is correct
11 Correct 58 ms 143704 KB Output is correct
12 Correct 69 ms 143708 KB Output is correct
13 Correct 83 ms 143836 KB Output is correct
14 Correct 97 ms 143848 KB Output is correct
15 Correct 67 ms 143696 KB Output is correct
16 Correct 93 ms 143704 KB Output is correct
17 Correct 40 ms 143700 KB Output is correct
18 Correct 59 ms 143844 KB Output is correct
19 Correct 24 ms 143708 KB Output is correct
20 Correct 26 ms 143836 KB Output is correct
21 Correct 43 ms 143700 KB Output is correct
22 Correct 45 ms 143848 KB Output is correct
23 Correct 35 ms 143712 KB Output is correct
24 Correct 40 ms 143696 KB Output is correct
25 Correct 22 ms 143704 KB Output is correct
26 Correct 24 ms 143696 KB Output is correct
27 Correct 57 ms 143708 KB Output is correct
28 Correct 61 ms 143708 KB Output is correct
29 Correct 59 ms 143856 KB Output is correct
30 Correct 65 ms 143696 KB Output is correct
31 Correct 61 ms 143864 KB Output is correct
32 Correct 62 ms 143852 KB Output is correct
33 Correct 78 ms 143860 KB Output is correct
34 Correct 95 ms 143708 KB Output is correct
35 Correct 69 ms 143704 KB Output is correct
36 Correct 98 ms 143832 KB Output is correct
37 Correct 22 ms 143708 KB Output is correct
38 Correct 24 ms 143864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1033 ms 144336 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1016 ms 145588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 80 ms 143728 KB Output is correct
2 Correct 44 ms 143700 KB Output is correct
3 Correct 32 ms 143868 KB Output is correct
4 Correct 45 ms 143708 KB Output is correct
5 Correct 22 ms 143704 KB Output is correct
6 Correct 23 ms 143700 KB Output is correct
7 Correct 60 ms 143792 KB Output is correct
8 Correct 61 ms 143960 KB Output is correct
9 Correct 62 ms 143708 KB Output is correct
10 Correct 57 ms 143868 KB Output is correct
11 Correct 58 ms 143704 KB Output is correct
12 Correct 69 ms 143708 KB Output is correct
13 Correct 83 ms 143836 KB Output is correct
14 Correct 97 ms 143848 KB Output is correct
15 Correct 67 ms 143696 KB Output is correct
16 Correct 93 ms 143704 KB Output is correct
17 Correct 40 ms 143700 KB Output is correct
18 Correct 59 ms 143844 KB Output is correct
19 Correct 24 ms 143708 KB Output is correct
20 Correct 26 ms 143836 KB Output is correct
21 Execution timed out 1033 ms 144336 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 124 ms 144376 KB Output is correct
2 Correct 125 ms 144592 KB Output is correct
3 Correct 147 ms 144592 KB Output is correct
4 Correct 109 ms 144512 KB Output is correct
5 Correct 112 ms 144336 KB Output is correct
6 Correct 158 ms 144568 KB Output is correct
7 Correct 51 ms 144424 KB Output is correct
8 Correct 40 ms 144340 KB Output is correct
9 Correct 90 ms 144480 KB Output is correct
10 Correct 91 ms 144404 KB Output is correct
11 Correct 102 ms 144520 KB Output is correct
12 Correct 104 ms 144584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 143728 KB Output is correct
2 Correct 44 ms 143700 KB Output is correct
3 Correct 32 ms 143868 KB Output is correct
4 Correct 45 ms 143708 KB Output is correct
5 Correct 22 ms 143704 KB Output is correct
6 Correct 23 ms 143700 KB Output is correct
7 Correct 60 ms 143792 KB Output is correct
8 Correct 61 ms 143960 KB Output is correct
9 Correct 62 ms 143708 KB Output is correct
10 Correct 57 ms 143868 KB Output is correct
11 Correct 58 ms 143704 KB Output is correct
12 Correct 69 ms 143708 KB Output is correct
13 Correct 83 ms 143836 KB Output is correct
14 Correct 97 ms 143848 KB Output is correct
15 Correct 67 ms 143696 KB Output is correct
16 Correct 93 ms 143704 KB Output is correct
17 Correct 40 ms 143700 KB Output is correct
18 Correct 59 ms 143844 KB Output is correct
19 Correct 24 ms 143708 KB Output is correct
20 Correct 26 ms 143836 KB Output is correct
21 Correct 43 ms 143700 KB Output is correct
22 Correct 45 ms 143848 KB Output is correct
23 Correct 35 ms 143712 KB Output is correct
24 Correct 40 ms 143696 KB Output is correct
25 Correct 22 ms 143704 KB Output is correct
26 Correct 24 ms 143696 KB Output is correct
27 Correct 57 ms 143708 KB Output is correct
28 Correct 61 ms 143708 KB Output is correct
29 Correct 59 ms 143856 KB Output is correct
30 Correct 65 ms 143696 KB Output is correct
31 Correct 61 ms 143864 KB Output is correct
32 Correct 62 ms 143852 KB Output is correct
33 Correct 78 ms 143860 KB Output is correct
34 Correct 95 ms 143708 KB Output is correct
35 Correct 69 ms 143704 KB Output is correct
36 Correct 98 ms 143832 KB Output is correct
37 Correct 22 ms 143708 KB Output is correct
38 Correct 24 ms 143864 KB Output is correct
39 Execution timed out 1033 ms 144336 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 80 ms 143728 KB Output is correct
2 Correct 44 ms 143700 KB Output is correct
3 Correct 32 ms 143868 KB Output is correct
4 Correct 45 ms 143708 KB Output is correct
5 Correct 22 ms 143704 KB Output is correct
6 Correct 23 ms 143700 KB Output is correct
7 Correct 60 ms 143792 KB Output is correct
8 Correct 61 ms 143960 KB Output is correct
9 Correct 62 ms 143708 KB Output is correct
10 Correct 57 ms 143868 KB Output is correct
11 Correct 58 ms 143704 KB Output is correct
12 Correct 69 ms 143708 KB Output is correct
13 Correct 83 ms 143836 KB Output is correct
14 Correct 97 ms 143848 KB Output is correct
15 Correct 67 ms 143696 KB Output is correct
16 Correct 93 ms 143704 KB Output is correct
17 Correct 40 ms 143700 KB Output is correct
18 Correct 59 ms 143844 KB Output is correct
19 Correct 24 ms 143708 KB Output is correct
20 Correct 26 ms 143836 KB Output is correct
21 Correct 43 ms 143700 KB Output is correct
22 Correct 45 ms 143848 KB Output is correct
23 Correct 35 ms 143712 KB Output is correct
24 Correct 40 ms 143696 KB Output is correct
25 Correct 22 ms 143704 KB Output is correct
26 Correct 24 ms 143696 KB Output is correct
27 Correct 57 ms 143708 KB Output is correct
28 Correct 61 ms 143708 KB Output is correct
29 Correct 59 ms 143856 KB Output is correct
30 Correct 65 ms 143696 KB Output is correct
31 Correct 61 ms 143864 KB Output is correct
32 Correct 62 ms 143852 KB Output is correct
33 Correct 78 ms 143860 KB Output is correct
34 Correct 95 ms 143708 KB Output is correct
35 Correct 69 ms 143704 KB Output is correct
36 Correct 98 ms 143832 KB Output is correct
37 Correct 22 ms 143708 KB Output is correct
38 Correct 24 ms 143864 KB Output is correct
39 Execution timed out 1033 ms 144336 KB Time limit exceeded
40 Halted 0 ms 0 KB -