結果

問題 No.618 labo-index
ユーザー ふっぴーふっぴー
提出日時 2017-12-18 10:53:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,657 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 180,744 KB
実行使用メモリ 12,448 KB
最終ジャッジ日時 2024-05-09 11:12:11
合計ジャッジ時間 38,317 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 5 ms
6,940 KB
testcase_05 AC 5 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 6 ms
6,944 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 4 ms
6,940 KB
testcase_14 AC 4 ms
6,940 KB
testcase_15 AC 5 ms
6,940 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 9 ms
6,940 KB
testcase_19 AC 1,502 ms
6,940 KB
testcase_20 AC 1,586 ms
6,940 KB
testcase_21 AC 1,524 ms
6,944 KB
testcase_22 AC 1,528 ms
6,940 KB
testcase_23 AC 1,530 ms
6,944 KB
testcase_24 AC 1,497 ms
6,944 KB
testcase_25 AC 1,564 ms
6,940 KB
testcase_26 AC 1,537 ms
6,944 KB
testcase_27 AC 1,527 ms
6,940 KB
testcase_28 AC 1,496 ms
6,944 KB
testcase_29 AC 1,539 ms
6,944 KB
testcase_30 AC 1,520 ms
6,944 KB
testcase_31 AC 1,527 ms
6,940 KB
testcase_32 AC 1,573 ms
6,944 KB
testcase_33 AC 1,534 ms
6,944 KB
testcase_34 AC 4,828 ms
6,944 KB
testcase_35 TLE -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
  cin >> q;
  int block = sqrt(q);
  vector<vector<pll> > lab;
  lab.push_back(vector<pll>());
  vl add;
  int num = 0;
  //DEBUG(block)
  for (int unko = 0; unko < q; unko++) {
    int t, x;
    cin >> 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 = 0, right = 100001;
    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;
      }
    }
    cout << left << endl;
    /*
    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