답안 #955350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955350 2024-03-30T08:00:51 Z vjudge1 푸드 코트 (JOI21_foodcourt) C++17
0 / 100
333 ms 53804 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=1e5+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;
      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++;
      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);
    }
    t[v].t=t[t[v].l].t+t[t[v].r].t;
  }

  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];

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++){
    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);
      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{
      int v,pos;
      cin>>v>>pos;
      int l=0,r=sz(t.roots)-1,res=sz(t.roots)-1;
      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")
      |
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 47964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 47964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 82 ms 49744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 333 ms 53804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 47964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 92 ms 50312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 47964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 47964 KB Output isn't correct
2 Halted 0 ms 0 KB -