結果

問題 No.2338 Range AtCoder Query
ユーザー 👑 kmjpkmjp
提出日時 2023-06-02 23:34:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,275 bytes
コンパイル時間 2,365 ms
コンパイル使用メモリ 209,272 KB
実行使用メモリ 25,916 KB
最終ジャッジ日時 2023-08-28 06:14:15
合計ジャッジ時間 22,953 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
17,732 KB
testcase_01 AC 7 ms
17,692 KB
testcase_02 AC 8 ms
17,752 KB
testcase_03 AC 8 ms
17,748 KB
testcase_04 AC 7 ms
17,724 KB
testcase_05 AC 7 ms
17,696 KB
testcase_06 AC 10 ms
17,808 KB
testcase_07 AC 10 ms
17,760 KB
testcase_08 AC 10 ms
17,868 KB
testcase_09 AC 10 ms
17,812 KB
testcase_10 AC 11 ms
17,756 KB
testcase_11 AC 2,502 ms
25,108 KB
testcase_12 AC 2,539 ms
25,116 KB
testcase_13 AC 2,619 ms
25,416 KB
testcase_14 AC 2,250 ms
25,324 KB
testcase_15 AC 3,085 ms
25,916 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
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 <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=3200;
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]];
		}
	}
	if(PL[p]==PR[p]&&AC[p][PL[p]]==0) {
		PL[p]=PR[p]=AC[p].size()/2;
	}
}

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(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