結果

問題 No.2338 Range AtCoder Query
ユーザー kotatsugamekotatsugame
提出日時 2023-06-02 22:02:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,875 bytes
コンパイル時間 1,290 ms
コンパイル使用メモリ 90,924 KB
実行使用メモリ 148,276 KB
最終ジャッジ日時 2023-08-28 03:33:02
合計ジャッジ時間 23,242 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
143,124 KB
testcase_01 AC 107 ms
138,528 KB
testcase_02 AC 108 ms
138,480 KB
testcase_03 AC 107 ms
138,460 KB
testcase_04 AC 107 ms
138,524 KB
testcase_05 AC 110 ms
138,492 KB
testcase_06 AC 111 ms
138,576 KB
testcase_07 AC 111 ms
138,584 KB
testcase_08 AC 112 ms
138,608 KB
testcase_09 AC 113 ms
138,524 KB
testcase_10 AC 111 ms
138,608 KB
testcase_11 AC 2,780 ms
142,220 KB
testcase_12 AC 2,571 ms
142,384 KB
testcase_13 AC 2,898 ms
142,648 KB
testcase_14 AC 2,841 ms
141,480 KB
testcase_15 AC 3,328 ms
142,712 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

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)
	{
		answer_dec();
		if(s)WA.push_front(0);
		else WA.front()++;
		answer_inc();
	}
	void push_back(bool s)
	{
		answer_dec();
		if(s)WA.push_back(0);
		else WA.back()++;
		answer_inc();
	}
	void pop_front()
	{
		answer_dec();
		if(WA.front()>0)WA.front()--;
		else WA.pop_front();
		answer_inc();
	}
	void pop_back()
	{
		answer_dec();
		if(WA.back()>0)WA.back()--;
		else WA.pop_back();
		answer_inc();
	}
	void answer_dec()
	{
		if(WA.size()>=2)
		{
			ALL-=WA.front();
			CNT--;
		}
	}
	void answer_inc()
	{
		if(WA.size()>=2)
		{
			ALL+=WA.front();
			CNT++;
		}
	}
};
int N,M,Q;
int P[2<<17];
bool S[2<<17];
deq A[200000];
const int B=400;
const int MN=200000;
vector<pair<int,pair<int,int> > >qR[(MN+B-1)/B];
int cnt[2<<17],ans[2<<17];
int main()
{
	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