結果

問題 No.2338 Range AtCoder Query
ユーザー kotatsugamekotatsugame
提出日時 2023-06-02 22:16:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,813 ms / 4,000 ms
コード長 1,960 bytes
コンパイル時間 1,054 ms
コンパイル使用メモリ 89,880 KB
実行使用メモリ 143,736 KB
最終ジャッジ日時 2023-08-28 03:59:12
合計ジャッジ時間 37,929 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
138,592 KB
testcase_01 AC 107 ms
138,664 KB
testcase_02 AC 107 ms
138,476 KB
testcase_03 AC 107 ms
138,664 KB
testcase_04 AC 106 ms
138,516 KB
testcase_05 AC 107 ms
138,512 KB
testcase_06 AC 108 ms
138,540 KB
testcase_07 AC 111 ms
138,700 KB
testcase_08 AC 109 ms
138,516 KB
testcase_09 AC 109 ms
138,796 KB
testcase_10 AC 108 ms
138,700 KB
testcase_11 AC 1,262 ms
141,868 KB
testcase_12 AC 1,215 ms
141,868 KB
testcase_13 AC 1,283 ms
142,124 KB
testcase_14 AC 1,256 ms
141,312 KB
testcase_15 AC 1,513 ms
142,828 KB
testcase_16 AC 1,783 ms
143,628 KB
testcase_17 AC 1,792 ms
143,736 KB
testcase_18 AC 1,767 ms
143,424 KB
testcase_19 AC 1,766 ms
143,396 KB
testcase_20 AC 1,744 ms
143,564 KB
testcase_21 AC 1,751 ms
143,552 KB
testcase_22 AC 1,776 ms
143,444 KB
testcase_23 AC 1,749 ms
143,412 KB
testcase_24 AC 1,785 ms
143,428 KB
testcase_25 AC 1,813 ms
143,568 KB
testcase_26 AC 157 ms
138,996 KB
testcase_27 AC 141 ms
138,808 KB
testcase_28 AC 145 ms
138,884 KB
testcase_29 AC 1,405 ms
143,544 KB
testcase_30 AC 1,724 ms
143,416 KB
testcase_31 AC 1,127 ms
143,544 KB
testcase_32 AC 929 ms
143,384 KB
testcase_33 AC 258 ms
142,360 KB
testcase_34 AC 259 ms
142,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<deque>
#include<cassert>
using namespace std;
int ALL,CNT;
struct deq{
	deque<int>WA;
	deq()
	{
		WA.push_back(0);
	}
	void push_front(bool s)
	{
		if(s)
		{
			if(WA.size()>=2)ALL-=WA.front();
			else CNT++;
			WA.push_front(0);
		}
		else
		{
			if(WA.size()>=2)ALL++;
			WA.front()++;
		}
	}
	void push_back(bool s)
	{
		if(s)
		{
			if(WA.size()==1)CNT++,ALL+=WA.front();
			WA.push_back(0);
		}
		else WA.back()++;
	}
	void pop_front()
	{
		if(WA.front()>0)
		{
			if(WA.size()>=2)ALL--;
			WA.front()--;
		}
		else
		{
			WA.pop_front();
			if(WA.size()>=2)ALL+=WA.front();
			else CNT--;
		}
	}
	void pop_back()
	{
		if(WA.back()>0)WA.back()--;
		else
		{
			WA.pop_back();
			if(WA.size()==1)
			{
				CNT--;
				ALL-=WA.front();
			}
		}
	}
};
int N,M,Q;
int P[2<<17];
bool S[2<<17];
deq A[200000];
const int B=1500;
const int MN=200000;
vector<pair<int,pair<int,int> > >qR[(MN+B-1)/B];
int cnt[2<<17],ans[2<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M>>Q;
	for(int i=0;i<N;i++)
	{
		string s;
		cin>>P[i]>>s;
		P[i]--;
		S[i]=s=="AC";
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;cin>>l>>r;
		l--;
		qR[l/B].push_back(make_pair(r,make_pair(l,i)));
	}
	int nL=0,nR=0;
	for(int li=0;li*B<N;li++)
	{
		sort(qR[li].begin(),qR[li].end(),[&li](const pair<int,pair<int,int> >&l,const pair<int,pair<int,int> >&r)
		{
			if(li&1)return l.first>r.first;
			else return l.first<r.first;
		});
		for(pair<int,pair<int,int> >p:qR[li])
		{
			int l=p.second.first;
			int r=p.first;
			while(nL>l)
			{
				nL--;
				A[P[nL]].push_front(S[nL]);
			}
			while(nR<r)
			{
				A[P[nR]].push_back(S[nR]);
				nR++;
			}
			while(nL<l)
			{
				A[P[nL]].pop_front();
				nL++;
			}
			while(nR>r)
			{
				nR--;
				A[P[nR]].pop_back();
			}
			cnt[p.second.second]=CNT;
			ans[p.second.second]=ALL;
		}
	}
	for(int i=0;i<Q;i++)cout<<cnt[i]<<" "<<ans[i]<<"\n";
}
0