結果

問題 No.953 席
ユーザー kzyKTkzyKT
提出日時 2019-12-16 00:59:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 4,605 bytes
コンパイル時間 1,952 ms
コンパイル使用メモリ 175,860 KB
実行使用メモリ 11,336 KB
最終ジャッジ日時 2023-09-15 16:01:04
合計ジャッジ時間 7,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,564 KB
testcase_01 AC 3 ms
9,544 KB
testcase_02 AC 147 ms
9,768 KB
testcase_03 AC 141 ms
9,784 KB
testcase_04 AC 165 ms
9,772 KB
testcase_05 AC 123 ms
9,768 KB
testcase_06 AC 157 ms
9,844 KB
testcase_07 AC 89 ms
11,272 KB
testcase_08 AC 133 ms
11,060 KB
testcase_09 AC 77 ms
11,336 KB
testcase_10 AC 27 ms
10,036 KB
testcase_11 AC 95 ms
10,864 KB
testcase_12 AC 169 ms
10,400 KB
testcase_13 AC 150 ms
11,108 KB
testcase_14 AC 179 ms
10,372 KB
testcase_15 AC 151 ms
10,360 KB
testcase_16 AC 167 ms
10,244 KB
testcase_17 AC 141 ms
10,256 KB
testcase_18 AC 155 ms
10,248 KB
testcase_19 AC 139 ms
11,096 KB
testcase_20 AC 147 ms
10,312 KB
testcase_21 AC 160 ms
9,852 KB
testcase_22 AC 177 ms
10,928 KB
testcase_23 AC 170 ms
9,860 KB
testcase_24 AC 145 ms
9,872 KB
testcase_25 AC 133 ms
11,048 KB
testcase_26 AC 44 ms
9,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

class RMQ{
public:
  int n,dat[555555];
  void init(int _n){
    n=1;
    while(n<_n)n*=2;
    fill(dat,dat+2*n-1,MAX);
  }
  void update(int k,int a){
    k+=n-1;dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  int query(int a,int b){return query(a,b,0,0,n);}
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return MAX;
    if(a<=l&&r<=b) return dat[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
};


class RMQ2{
public:
  int n,dat[555555];
  void init(int _n){
    n=1;
    while(n<_n)n*=2;
    fill(dat,dat+2*n-1,-MAX);
  }
  void update(int k,int a){
    k+=n-1;dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=max(dat[k*2+1],dat[k*2+2]);
    }
  }
  int query(int a,int b){return query(a,b,0,0,n);}
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return -MAX;
    if(a<=l&&r<=b) return dat[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return max(vl,vr);
  }
};

RMQ t[2];
RMQ2 r[2];

void Main() {
  int n,k1,k2;
  cin >> n >> k1 >> k2;
  k1--,k2--;
  rep(i,2) {
    t[i].init(n);
    r[i].init(n);
  }
  rep(i,n) {
    rep(j,2) {
      t[j].update(i,i);
      r[j].update(i,i);
    }
  }
  int T;
  cin >> T;
  priority_queue<P,vector<P>,greater<P> > que;
  int c[n];
  mem(c);
  ll M=0;
  while(T--) {
    ll x,y;
    cin >> x >> y;
  next:;
    x=max(x,M);
    while(!que.empty()&&que.top().F<=x) {
      P p=que.top();que.pop();
      t[0].update(p.S,p.S);
      r[0].update(p.S,p.S);
      c[p.S]=0;
      REP(i,-2,1) {
        int f=1;
        rep(j,3) {
          if(p.S+i+j>=0&&p.S+i+j<n&&c[p.S+i+j]) f=0;
        }
        if(f) {
          if(p.S+i+1>=0&&p.S+i+1<n) {
            t[1].update(p.S+i+1,p.S+i+1);
            r[1].update(p.S+i+1,p.S+i+1);
          }
        }
      }
    }
    int ans=0;
    if(k1<k2) {
      int p1=r[1].query(0,k2);
      int p2=t[1].query(k2,n);
      if(p1==-MAX&&p2==MAX) {
        p1=r[0].query(0,k2);
        p2=t[0].query(k2,n);
      }
      if(p1==-MAX&&p2==MAX) {
        M=max(M,que.top().F);
        goto next;
      }
      int d1=abs(p1-k1),d2=abs(p2-k2);
      if(d1<=d2) {
        ans=p1;
        r[0].update(p1,-MAX);
        t[0].update(p1,MAX);
        REP(i,-1,2) {
          if(p1+i>=0&&p1+i<n) {
            r[1].update(p1+i,-MAX);
            t[1].update(p1+i,MAX);
          }
        }
      } else {
        ans=p2;
        t[0].update(p2,MAX);
        r[0].update(p2,-MAX);
        REP(i,-1,2) {
          if(p2+i>=0&&p2+i<n) {
            t[1].update(p2+i,MAX);
            r[1].update(p2+i,-MAX);
          }
        }
      }
    } else {
      int p1=r[1].query(0,k1);
      int p2=t[1].query(k1,n);
      if(p1==-MAX&&p2==MAX) {
        p1=r[0].query(0,k1);
        p2=t[0].query(k1,n);
      }
      if(p1==-MAX&&p2==MAX) {
        M=max(M,que.top().F);
        goto next;
      }
      int d1=abs(p1-k2),d2=abs(p2-k1);
      if(d1<d2) {
        ans=p1;
        r[0].update(p1,-MAX);
        t[0].update(p1,MAX);
        REP(i,-1,2) {
          if(p1+i>=0&&p1+i<n) {
            r[1].update(p1+i,-MAX);
            t[1].update(p1+i,MAX);
          }
        }
      } else {
        ans=p2;
        r[0].update(p2,-MAX);
        t[0].update(p2,MAX);
        REP(i,-1,2) {
          if(p2+i>=0&&p2+i<n) {
            t[1].update(p2+i,MAX);
            r[1].update(p2+i,-MAX);
          }
        }
      }
    }
    que.push(P(x+y,ans));
    c[ans]=1;
    pr(ans+1);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
0