結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
17,660 KB
testcase_01 AC 6 ms
17,644 KB
testcase_02 AC 6 ms
17,704 KB
testcase_03 AC 6 ms
17,868 KB
testcase_04 AC 6 ms
17,664 KB
testcase_05 AC 6 ms
17,860 KB
testcase_06 AC 8 ms
17,764 KB
testcase_07 AC 8 ms
17,732 KB
testcase_08 AC 9 ms
17,712 KB
testcase_09 AC 9 ms
17,764 KB
testcase_10 AC 8 ms
17,696 KB
testcase_11 AC 1,532 ms
25,188 KB
testcase_12 AC 1,609 ms
25,344 KB
testcase_13 AC 1,642 ms
25,516 KB
testcase_14 AC 1,823 ms
25,328 KB
testcase_15 AC 1,925 ms
26,052 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 AC 91 ms
26,404 KB
testcase_27 AC 89 ms
26,348 KB
testcase_28 AC 94 ms
26,616 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=500;
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