結果

問題 No.618 labo-index
ユーザー ふっぴーふっぴー
提出日時 2017-12-18 11:08:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,971 ms / 6,000 ms
コード長 2,943 bytes
コンパイル時間 2,957 ms
コンパイル使用メモリ 178,496 KB
実行使用メモリ 5,756 KB
最終ジャッジ日時 2023-08-22 05:22:15
合計ジャッジ時間 16,162 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 487 ms
4,376 KB
testcase_20 AC 578 ms
4,384 KB
testcase_21 AC 492 ms
4,376 KB
testcase_22 AC 511 ms
4,380 KB
testcase_23 AC 515 ms
4,380 KB
testcase_24 AC 478 ms
4,380 KB
testcase_25 AC 552 ms
4,380 KB
testcase_26 AC 521 ms
4,380 KB
testcase_27 AC 508 ms
4,380 KB
testcase_28 AC 476 ms
4,380 KB
testcase_29 AC 521 ms
4,380 KB
testcase_30 AC 485 ms
4,380 KB
testcase_31 AC 505 ms
4,376 KB
testcase_32 AC 558 ms
4,380 KB
testcase_33 AC 528 ms
4,380 KB
testcase_34 AC 718 ms
5,756 KB
testcase_35 AC 753 ms
5,756 KB
testcase_36 AC 1,971 ms
4,496 KB
testcase_37 AC 686 ms
4,428 KB
testcase_38 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

const ll none = -200000000000000;

int main() {
  int q, i, j;
  scanf("%d", &q);
  int block = sqrt(q);
  vector<vector<pll> > lab;
  lab.push_back(vector<pll>());
  vl add;
  int num = 0;
  //DEBUG(block)
  ll pre = 0;
  for (int unko = 0; unko < q; unko++) {
    int t, x;
    scanf("%d%d", &t, &x);
    if (t == 1) {
      lab[num / block].push_back(pll(x, num));
      if (lab[num / block].size() == block) {
	lab.push_back(vector<pll>());
	add.push_back(0);
      }
      sort(lab[num / block].begin(), lab[num / block].end());
      num++;
    }
    else if (t == 2) {
      x--;
      i = x / block;
      for (j = 0; j < lab[i].size(); j++) {
	if (lab[i][j].second == x) {
	  lab[i][j].first += none;
	  break;
	}
      }
      sort(lab[i].begin(), lab[i].end());
    }
    else {
      for (i = 0; i < add.size(); i++) {
	add[i] += x;
      }
      for (j = 0; j < lab[lab.size() - 1].size(); j++) {
	lab[lab.size() - 1][j].first += x;
      }
    }
    ll left, right;
    if (t == 1) {
      left = pre; right = pre + 2;
    }
    else if (t == 2) {
      left = pre - 1; right = pre + 2;
    }
    else {
      if (x >= 0) {
	left = pre; right = num + 2;
      }
      else {
	left = 0; right = pre + 2;
      }
    }
    while (left + 1 < right) {
      ll mid = (left + right) / 2; 
      int cnt = 0;
      for (i = 0; i < add.size(); i++) {
	int idx = lower_bound(lab[i].begin(), lab[i].end(), pll(mid - add[i], -1)) - lab[i].begin();
	cnt += block - idx;
      }
      int idx = lower_bound(lab[lab.size() - 1].begin(), lab[lab.size() - 1].end(), pll(mid, -1)) - lab[lab.size() - 1].begin();
      cnt += lab[lab.size() - 1].size() - idx;
      if (cnt >= mid) {
	left = mid;
      }
      else {
	right = mid;
      }
    }
    printf("%lld\n", left);
    pre = left;
    /*
    for (i = 0; i < lab.size(); i++) {
      for (j = 0; j < lab[i].size(); j++) {
	printf("(%lld, %lld) ", lab[i][j].first, lab[i][j].second);
      }
      cout << endl;
    }
    */
  }
}
											      
/*
5
1 1
1 2
1 3
1 4
1 5

4
1 1
1 2
1 3
2 2

5
1 1
1 2
1 3
3 2
3 -10

10
1 396579765
1 798135558
1 901129114
3 -929424919
2 3
1 -643609488
3 697031258
3 -245746533
1 -804449362
2 2
*/
0