結果

問題 No.2338 Range AtCoder Query
ユーザー kotatsugamekotatsugame
提出日時 2023-06-02 22:11:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,959 bytes
コンパイル時間 1,165 ms
コンパイル使用メモリ 90,888 KB
実行使用メモリ 143,744 KB
最終ジャッジ日時 2023-08-28 03:48:26
合計ジャッジ時間 27,354 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
138,560 KB
testcase_01 AC 110 ms
138,620 KB
testcase_02 AC 107 ms
138,508 KB
testcase_03 AC 109 ms
138,624 KB
testcase_04 AC 109 ms
138,704 KB
testcase_05 AC 110 ms
138,500 KB
testcase_06 AC 110 ms
138,612 KB
testcase_07 AC 109 ms
138,540 KB
testcase_08 AC 110 ms
138,548 KB
testcase_09 AC 111 ms
138,768 KB
testcase_10 AC 110 ms
138,552 KB
testcase_11 AC 2,242 ms
142,416 KB
testcase_12 AC 1,990 ms
142,252 KB
testcase_13 AC 3,667 ms
142,236 KB
testcase_14 AC 2,699 ms
141,668 KB
testcase_15 AC 2,158 ms
143,088 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 3,114 ms
143,480 KB
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 2,960 ms
143,744 KB
testcase_24 AC 3,525 ms
143,704 KB
testcase_25 TLE -
testcase_26 AC 170 ms
138,868 KB
testcase_27 AC 149 ms
138,880 KB
testcase_28 AC 149 ms
138,808 KB
testcase_29 TLE -
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)
	{
		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=500;
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