結果

問題 No.2338 Range AtCoder Query
ユーザー 👑 kmjpkmjp
提出日時 2023-06-02 23:41:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,308 ms / 4,000 ms
コード長 2,207 bytes
コンパイル時間 2,205 ms
コンパイル使用メモリ 207,276 KB
実行使用メモリ 21,668 KB
最終ジャッジ日時 2023-08-28 06:25:21
合計ジャッジ時間 29,838 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
17,696 KB
testcase_01 AC 6 ms
17,616 KB
testcase_02 AC 7 ms
17,684 KB
testcase_03 AC 6 ms
17,896 KB
testcase_04 AC 6 ms
17,744 KB
testcase_05 AC 6 ms
17,728 KB
testcase_06 AC 9 ms
17,636 KB
testcase_07 AC 9 ms
17,636 KB
testcase_08 AC 9 ms
17,744 KB
testcase_09 AC 9 ms
17,788 KB
testcase_10 AC 9 ms
17,752 KB
testcase_11 AC 962 ms
20,368 KB
testcase_12 AC 905 ms
20,448 KB
testcase_13 AC 1,006 ms
20,544 KB
testcase_14 AC 973 ms
20,260 KB
testcase_15 AC 1,155 ms
20,860 KB
testcase_16 AC 1,290 ms
21,316 KB
testcase_17 AC 1,289 ms
21,336 KB
testcase_18 AC 1,271 ms
21,588 KB
testcase_19 AC 1,282 ms
21,312 KB
testcase_20 AC 1,277 ms
21,312 KB
testcase_21 AC 1,289 ms
21,480 KB
testcase_22 AC 1,276 ms
21,356 KB
testcase_23 AC 1,308 ms
21,384 KB
testcase_24 AC 1,281 ms
21,328 KB
testcase_25 AC 1,290 ms
21,324 KB
testcase_26 AC 44 ms
19,096 KB
testcase_27 AC 42 ms
19,348 KB
testcase_28 AC 43 ms
19,180 KB
testcase_29 AC 960 ms
21,332 KB
testcase_30 AC 1,212 ms
21,420 KB
testcase_31 AC 729 ms
21,668 KB
testcase_32 AC 672 ms
21,444 KB
testcase_33 AC 403 ms
20,600 KB
testcase_34 AC 403 ms
20,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M,Q;
int P[202020],S[202020];
int L[202020],R[202020],ac[202020],wa[202020];
int PL[202020],PR[202020];
int num[202020];
int start[202020];
int AC[808080];

vector<pair<int,int>> ev[202020];
const int DI=800;
int nac=0,nwa=0;

void add1(int pos) {
	int p=P[pos];
	if(S[pos]==0) {
		AC[PR[p]]++;
	}
	else {
		if(PL[p]==PR[p]) {
			nac++;
			nwa+=AC[PL[p]];
		}
		PR[p]++;
	}
}
void add2(int pos) {
	int p=P[pos];
	if(S[pos]==0) {
		AC[PL[p]]++;
		if(PL[p]<PR[p]) nwa++;
	}
	else {
		if(PL[p]==PR[p]) {
			nac++;
		}
		else {
			nwa-=AC[PL[p]];
		}
		PL[p]--;
	}
}

void del(int pos) {
	int p=P[pos];
	if(S[pos]==0) {
		AC[PL[p]]--;
		if(PL[p]<PR[p]) nwa--;
	}
	else {
		PL[p]++;
		if(PL[p]==PR[p]) {
			nac--;
		}
		else {
			nwa+=AC[PL[p]];
		}
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>Q;
	FOR(i,N) {
		cin>>P[i]>>s;
		S[i]=s=="AC";
		num[P[i]]++;
	}
	
	FOR(i,Q) {
		cin>>L[i]>>R[i];
		L[i]--;
		ev[L[i]/DI].push_back({R[i],i});
	}
	int sum=0;
	FOR(i,M+1) {
		PL[i]=PR[i]=start[i]=sum+num[i];
		sum+=num[i]*2;
		
	}
	
	FOR(i,201000) if(ev[i].size()) {
		sort(ALL(ev[i]));
		int CL=i*DI,CR=i*DI;
		FORR2(r,cur,ev[i]) {
			int TL=L[cur],TR=r;
			while(CR<TR) add1(CR++);
			while(TL<CL) add2(--CL);
			while(CL<TL) del(CL++);
			ac[cur]=nac;
			wa[cur]=nwa;
		}
		while(CL<CR) del(CL++);
		FOR(j,M+1) PL[j]=PR[j]=start[j];

	}
	FOR(i,Q) {
		cout<<ac[i]<<" "<<wa[i]<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0