結果

問題 No.953 席
ユーザー chocoruskchocorusk
提出日時 2019-12-16 02:03:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 3,162 bytes
コンパイル時間 1,362 ms
コンパイル使用メモリ 130,968 KB
実行使用メモリ 15,584 KB
最終ジャッジ日時 2023-09-15 16:24:07
合計ジャッジ時間 10,327 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 267 ms
13,432 KB
testcase_03 AC 263 ms
12,352 KB
testcase_04 AC 266 ms
13,072 KB
testcase_05 AC 255 ms
12,508 KB
testcase_06 AC 265 ms
12,540 KB
testcase_07 AC 274 ms
15,340 KB
testcase_08 AC 337 ms
14,476 KB
testcase_09 AC 239 ms
15,296 KB
testcase_10 AC 81 ms
7,360 KB
testcase_11 AC 245 ms
12,508 KB
testcase_12 AC 307 ms
13,484 KB
testcase_13 AC 339 ms
14,696 KB
testcase_14 AC 296 ms
12,936 KB
testcase_15 AC 291 ms
13,060 KB
testcase_16 AC 294 ms
13,444 KB
testcase_17 AC 296 ms
13,400 KB
testcase_18 AC 287 ms
12,728 KB
testcase_19 AC 323 ms
14,644 KB
testcase_20 AC 292 ms
13,252 KB
testcase_21 AC 263 ms
12,608 KB
testcase_22 AC 309 ms
13,980 KB
testcase_23 AC 275 ms
12,520 KB
testcase_24 AC 278 ms
13,016 KB
testcase_25 AC 352 ms
15,584 KB
testcase_26 AC 246 ms
12,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
#define int long long
using namespace std;
//typedef long long int ll;
typedef pair<int, int> P;
signed main()
{
	int n, k1, k2;
  cin>>n>>k1>>k2;
  int q;
  cin>>q;
  int a[100010], b[100010];
  using Pi=pair<P, int>;
  priority_queue<Pi, vector<Pi>, greater<Pi>> v;
  vector<Pi> vec;
  for(int i=0; i<q; i++){
    cin>>a[i]>>b[i];
  }
  queue<int> que;
  int cnt=0;
  priority_queue<int, vector<int>, greater<int>> pque;
  for(int i=0; i<q; i++){
    while(!pque.empty()){
      int x=pque.top();
      if(x>a[i]) break;
      cnt--;
      pque.pop();
      if(!que.empty()){
        int j=que.front();
        que.pop();
        a[j]=x;
        cnt++;
        pque.push(a[j]+b[j]);
      }
    }
    if(cnt<n){
      cnt++;
      pque.push(a[i]+b[i]);
    }else{
      que.push(i);
    }
  }
  while(!pque.empty()){
      int x=pque.top();
      cnt--;
      pque.pop();
      if(!que.empty()){
        int j=que.front();
        que.pop();
        a[j]=x;
        cnt++;
        pque.push(a[j]+b[j]);
      }
  }
  for(int i=0; i<q; i++){
    //cout<<a[i]<<endl;
    v.push({{a[i], i+q}, 0});
    v.push({{a[i]+b[i], i}, 1});
  }
  set<int> st1, st2;
  bool used[100010]={};
  for(int i=0; i<=n+1; i++){
    st1.insert(i);
    st2.insert(i);
  }
  queue<int> myon;
  int ans[100010];
  while(!v.empty()){
    auto p=v.top(); v.pop();
    int t=p.second;
    int i=p.first.second;
    if(t==0){
      i-=q;
      auto itr=st1.lower_bound(max(k1, k2));
      int x=*itr;
      itr--;
      int y=*itr;
      if(x==n+1 && y==0){
        auto itr2=st2.lower_bound(max(k1, k2));
        int x2=*itr2;
        itr2--;
        int y2=*itr2;
        if(x2==n+1 && y2==0){
          //cout<<i<<" "<<p.first.first<<endl;
          assert(0);
        }else if(x2==n+1){
          x=y2;
        }else if(y2==0){
          x=x2;
        }else{
          if(x2-max(k1, k2)>min(k1, k2)-y2){
            x2=y2;
          }else if(k1<k2 && x2-k2==k1-y2){
            x2=y2;
          }
          x=x2;
        }
      }else if(x==n+1){
        x=y;
      }else if(y==0){
        
      }else{
        if(x-max(k1, k2)>min(k1, k2)-y){
          x=y;
        }else if(k1<k2 && x-k2==k1-y){
          x=y;
        }
      }
      ans[i]=x;
      st2.erase(x);
      st1.erase(x);
      if(x>1) st1.erase(x-1);
      if(x<n) st1.erase(x+1);
      used[x]=1;
    }else{
      int x=ans[i];
      used[x]=0;
      st2.insert(x);
      if(x-1>0){
        if(!used[x-1] && !used[x-2]) st1.insert(x-1);
      }
      if(x+1<=n){
        if(!used[x+1] && !used[x+2]) st1.insert(x+1);
      }
      if(!used[x-1] && !used[x+1]) st1.insert(x);
    }
  }
  for(int i=0; i<q; i++){
    cout<<ans[i]<<endl;
  }
	return 0;
}
0