結果

問題 No.618 labo-index
ユーザー kotatsugamekotatsugame
提出日時 2020-04-22 19:48:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 255 ms / 6,000 ms
コード長 1,317 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 80,788 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 05:47:10
合計ジャッジ時間 7,246 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 4 ms
6,940 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 6 ms
6,940 KB
testcase_19 AC 229 ms
6,944 KB
testcase_20 AC 223 ms
6,940 KB
testcase_21 AC 220 ms
6,944 KB
testcase_22 AC 219 ms
6,944 KB
testcase_23 AC 219 ms
6,940 KB
testcase_24 AC 218 ms
6,944 KB
testcase_25 AC 226 ms
6,940 KB
testcase_26 AC 218 ms
6,940 KB
testcase_27 AC 234 ms
6,944 KB
testcase_28 AC 222 ms
6,944 KB
testcase_29 AC 255 ms
6,940 KB
testcase_30 AC 222 ms
6,940 KB
testcase_31 AC 220 ms
6,940 KB
testcase_32 AC 223 ms
6,940 KB
testcase_33 AC 220 ms
6,940 KB
testcase_34 AC 247 ms
6,940 KB
testcase_35 AC 239 ms
6,944 KB
testcase_36 AC 177 ms
6,944 KB
testcase_37 AC 217 ms
6,940 KB
testcase_38 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0):n(n_),bit(n_+1){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
	int lower_bound(T k)//k<=sum(ret)
	{
		if(k<=0)return 0;
		int ret=0,i=1;
		while((i<<1)<=n)i<<=1;
		for(;i;i>>=1)
			if(ret+i<=n&&bit[ret+i]<k)k-=bit[ret+=i];
		return ret+1;
	}
};
int Q;
int t[1<<17];
long x[1<<17];
main()
{
	cin>>Q;
	long cumsum=0;
	vector<long>X;
	for(int i=0;i<Q;i++)
	{
		cin>>t[i]>>x[i];
		if(t[i]==1)
		{
			x[i]-=cumsum;
			X.push_back(x[i]);
		}
		else if(t[i]==3)
		{
			cumsum+=x[i];
		}
	}
	sort(X.begin(),X.end());
	X.erase(unique(X.begin(),X.end()),X.end());
	BIT<int>P(X.size());
	vector<int>ind;
	cumsum=0;
	for(int i=0;i<Q;i++)
	{
		if(t[i]==1)
		{
			int id=lower_bound(X.begin(),X.end(),x[i])-X.begin()+1;
			P.add(id,1);
			ind.push_back(id);
		}
		else if(t[i]==2)
		{
			P.add(ind[x[i]-1],-1);
		}
		else
		{
			cumsum+=x[i];
		}
		long L=0,R=2e5;
		while(R-L>1)
		{
			long M=L+R>>1;
			long tst=M-cumsum;
			if(P.sum(X.size())-P.sum(lower_bound(X.begin(),X.end(),tst)-X.begin())>=M)L=M;
			else R=M;
		}
		cout<<L<<endl;
	}
}
0