結果

問題 No.2338 Range AtCoder Query
ユーザー 👑 kmjpkmjp
提出日時 2023-06-02 23:30:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,246 bytes
コンパイル時間 2,343 ms
コンパイル使用メモリ 210,052 KB
実行使用メモリ 46,020 KB
最終ジャッジ日時 2023-08-28 06:08:59
合計ジャッジ時間 51,598 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
46,020 KB
testcase_01 AC 7 ms
17,676 KB
testcase_02 AC 7 ms
17,748 KB
testcase_03 AC 6 ms
17,840 KB
testcase_04 AC 6 ms
17,848 KB
testcase_05 AC 7 ms
17,700 KB
testcase_06 AC 9 ms
17,736 KB
testcase_07 AC 10 ms
17,744 KB
testcase_08 AC 9 ms
17,756 KB
testcase_09 AC 10 ms
17,808 KB
testcase_10 AC 10 ms
17,752 KB
testcase_11 AC 1,481 ms
25,092 KB
testcase_12 AC 1,489 ms
25,056 KB
testcase_13 AC 1,556 ms
25,264 KB
testcase_14 AC 1,329 ms
25,348 KB
testcase_15 AC 1,849 ms
25,788 KB
testcase_16 AC 3,350 ms
28,460 KB
testcase_17 AC 3,453 ms
28,636 KB
testcase_18 AC 3,319 ms
28,356 KB
testcase_19 AC 3,289 ms
28,400 KB
testcase_20 AC 3,298 ms
28,532 KB
testcase_21 AC 3,329 ms
28,568 KB
testcase_22 AC 3,217 ms
28,456 KB
testcase_23 AC 3,217 ms
28,536 KB
testcase_24 AC 3,302 ms
28,452 KB
testcase_25 AC 3,314 ms
28,460 KB
testcase_26 AC 92 ms
26,328 KB
testcase_27 AC 90 ms
26,324 KB
testcase_28 AC 91 ms
26,312 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
vector<int> AC[202020];
vector<pair<int,int>> ev[202020];
const int DI=2500;
int nac=0,nwa=0;

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

void del(int pos) {
	int p=P[pos];
	if(S[pos]==0) {
		AC[p][PL[p]]--;
		if(PL[p]<PR[p]) nwa--;
	}
	else {
		PL[p]++;
		if(PL[p]==PR[p]) {
			nac--;
		}
		else {
			nwa+=AC[p][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";
		AC[P[i]].push_back(0);
		AC[P[i]].push_back(0);
	}
	
	FOR(i,Q) {
		cin>>L[i]>>R[i];
		L[i]--;
		ev[L[i]/DI].push_back({R[i],i});
	}
	FOR(i,M+1) {
		AC[i].push_back(0);
		AC[i].push_back(0);
		PL[i]=PR[i]=AC[i].size()/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]=AC[j].size()/2;

	}
	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