結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
138,520 KB
testcase_01 AC 108 ms
138,560 KB
testcase_02 AC 107 ms
138,656 KB
testcase_03 AC 107 ms
138,504 KB
testcase_04 AC 107 ms
138,496 KB
testcase_05 AC 108 ms
138,512 KB
testcase_06 AC 110 ms
138,548 KB
testcase_07 AC 109 ms
138,628 KB
testcase_08 AC 111 ms
138,612 KB
testcase_09 AC 110 ms
138,508 KB
testcase_10 AC 109 ms
138,552 KB
testcase_11 AC 1,293 ms
141,920 KB
testcase_12 AC 1,234 ms
141,856 KB
testcase_13 AC 1,362 ms
142,328 KB
testcase_14 AC 1,364 ms
141,260 KB
testcase_15 AC 1,490 ms
142,816 KB
testcase_16 AC 1,760 ms
143,340 KB
testcase_17 AC 1,760 ms
143,504 KB
testcase_18 AC 1,765 ms
143,504 KB
testcase_19 AC 1,743 ms
143,216 KB
testcase_20 AC 1,755 ms
143,420 KB
testcase_21 AC 1,766 ms
143,208 KB
testcase_22 AC 1,763 ms
143,448 KB
testcase_23 AC 1,774 ms
143,348 KB
testcase_24 AC 1,751 ms
143,460 KB
testcase_25 AC 1,771 ms
143,552 KB
testcase_26 AC 159 ms
138,800 KB
testcase_27 AC 143 ms
138,888 KB
testcase_28 AC 147 ms
138,936 KB
testcase_29 AC 1,488 ms
143,480 KB
testcase_30 AC 1,863 ms
143,496 KB
testcase_31 AC 1,166 ms
143,344 KB
testcase_32 AC 908 ms
143,432 KB
testcase_33 AC 258 ms
142,716 KB
testcase_34 AC 257 ms
142,592 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=1000;
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