結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
138,480 KB
testcase_01 AC 106 ms
138,496 KB
testcase_02 AC 107 ms
138,508 KB
testcase_03 AC 105 ms
138,536 KB
testcase_04 AC 105 ms
138,508 KB
testcase_05 AC 105 ms
138,532 KB
testcase_06 AC 108 ms
138,548 KB
testcase_07 AC 108 ms
138,712 KB
testcase_08 AC 108 ms
138,556 KB
testcase_09 AC 111 ms
138,520 KB
testcase_10 AC 108 ms
138,848 KB
testcase_11 AC 1,257 ms
141,900 KB
testcase_12 AC 1,269 ms
141,684 KB
testcase_13 AC 1,334 ms
142,120 KB
testcase_14 AC 1,304 ms
141,384 KB
testcase_15 AC 1,533 ms
142,444 KB
testcase_16 AC 1,798 ms
143,608 KB
testcase_17 AC 1,820 ms
143,504 KB
testcase_18 AC 1,794 ms
143,600 KB
testcase_19 AC 1,755 ms
143,472 KB
testcase_20 AC 1,847 ms
143,480 KB
testcase_21 AC 1,790 ms
143,564 KB
testcase_22 AC 1,763 ms
143,540 KB
testcase_23 AC 1,819 ms
143,556 KB
testcase_24 AC 1,854 ms
143,672 KB
testcase_25 AC 1,821 ms
143,544 KB
testcase_26 AC 159 ms
138,824 KB
testcase_27 AC 142 ms
138,788 KB
testcase_28 AC 145 ms
138,876 KB
testcase_29 AC 1,392 ms
143,652 KB
testcase_30 AC 1,796 ms
143,580 KB
testcase_31 AC 1,137 ms
143,500 KB
testcase_32 AC 876 ms
143,416 KB
testcase_33 AC 254 ms
142,768 KB
testcase_34 AC 253 ms
142,380 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=1200;
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++)
	{
		if(li&1)
		{
			sort(qR[li].begin(),qR[li].end(),[&li](const pair<int,pair<int,int> >&l,const pair<int,pair<int,int> >&r)
			{
				return l.first>r.first;
			});
		}
		else
		{
			sort(qR[li].begin(),qR[li].end(),[&li](const pair<int,pair<int,int> >&l,const pair<int,pair<int,int> >&r)
			{
				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