結果

問題 No.2338 Range AtCoder Query
ユーザー shobonvipshobonvip
提出日時 2023-06-03 00:47:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,193 ms / 4,000 ms
コード長 2,657 bytes
コンパイル時間 4,136 ms
コンパイル使用メモリ 234,928 KB
実行使用メモリ 24,620 KB
最終ジャッジ日時 2023-08-28 07:10:05
合計ジャッジ時間 26,340 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 905 ms
15,064 KB
testcase_12 AC 828 ms
15,200 KB
testcase_13 AC 939 ms
15,188 KB
testcase_14 AC 965 ms
14,684 KB
testcase_15 AC 1,052 ms
16,264 KB
testcase_16 AC 1,060 ms
20,852 KB
testcase_17 AC 1,056 ms
20,920 KB
testcase_18 AC 1,060 ms
21,128 KB
testcase_19 AC 1,060 ms
20,824 KB
testcase_20 AC 1,068 ms
20,828 KB
testcase_21 AC 1,071 ms
21,012 KB
testcase_22 AC 1,066 ms
21,176 KB
testcase_23 AC 1,070 ms
20,980 KB
testcase_24 AC 1,067 ms
21,144 KB
testcase_25 AC 1,066 ms
20,876 KB
testcase_26 AC 65 ms
15,736 KB
testcase_27 AC 63 ms
15,668 KB
testcase_28 AC 62 ms
15,608 KB
testcase_29 AC 279 ms
18,600 KB
testcase_30 AC 1,193 ms
22,460 KB
testcase_31 AC 386 ms
24,620 KB
testcase_32 AC 213 ms
18,624 KB
testcase_33 AC 162 ms
19,732 KB
testcase_34 AC 165 ms
19,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

struct t3{int left, right, index;};
bool sec_sort(t3 a, t3 b){return a.right < b.right;}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n, m, q;
	cin >> n >> m >> q;
	
	vector<int> prob(n);
	vector<int> dat(n);
	vector<int> lftwa(n);
	vector<int> nowcnt(m);
	vector<vector<int>> ayaya(m);

	for (int i=0; i<n; i++){
		int p; string s; cin >> p >> s;
		p--;
		prob[i] = p;
		if (s == "AC"){
			dat[i] = 1;
			lftwa[i] = nowcnt[p];
			ayaya[p].push_back(nowcnt[p]);
		}else{
			dat[i] = 0;
			nowcnt[p]++;
		}
	}

	int sep = ceil(sqrt(n));
	vector<vector<t3>> mo(sep+1, vector<t3>(0));
	t3 f;

	for(int i=0; i<q; i++){
		int l, r;
		cin >> l >> r;
		l--;
		f.left = l;
		f.right = r;
		f.index = i;
		mo[l/sep].push_back(f);
	}

	vector<int> ans1(q); // AC
	vector<int> ans2(q); // WA

	vector<int> lpiv(m);
	vector<int> rpiv(m);
	vector<int> lftsum(m);

	int l = 0, r = 0;
	int tl, tr, daime;
	int nowans1 = 0;
	int nowans2 = 0;

	for(int i=0; i<sep+1; i++){
		sort(mo[i].begin(), mo[i].end(), sec_sort);
		//if (i%2 == 1){
	//		reverse(mo[i].begin(), mo[i].end());
	//	}
		for(int j=0; j<mo[i].size(); j++){
			tl = mo[i][j].left;
			tr = mo[i][j].right;
			//右を伸ばす
			for(int k=r; k<tr; k++){
				daime = prob[k];
				if (dat[k] == 1){
					if (lpiv[daime] == rpiv[daime]){
						nowans1++;
						nowans2 += lftwa[k] - lftsum[daime];
					}
					rpiv[daime]++;
				}
			}
			//右を縮ませる
			for(int k=r-1; k>=tr; k--){
				daime = prob[k];
				if (dat[k] == 1){
					rpiv[daime]--;
					if (lpiv[daime] == rpiv[daime]){
						nowans1--;
						nowans2 -= lftwa[k] - lftsum[daime];
					}
				}
			}
			//左を縮ませる
			for(int k=l; k<tl; k++){
				daime = prob[k];
				if (dat[k] == 1){
					lpiv[daime]++;
					if (lpiv[daime] < rpiv[daime]){
						nowans2 += ayaya[daime][lpiv[daime]] - lftsum[daime];
					}else{
						nowans1--;
					}
				}else{
					lftsum[daime]++;
					if (lpiv[daime] < rpiv[daime]) nowans2--;
				}
			}
			//左を伸ばす
			for(int k=l-1; k>=tl; k--){
				daime = prob[k];
				if (dat[k] == 1){
					if (lpiv[daime] < rpiv[daime]){
						nowans2 -= ayaya[daime][lpiv[daime]] - lftsum[daime];
					}else{
						nowans1++;
					}
					lpiv[daime]--;
				}else{
					lftsum[daime]--;
					if (lpiv[daime] != rpiv[daime]) nowans2++;
				}
			}
			l = tl; r = tr;
			ans1[mo[i][j].index] = nowans1;
			ans2[mo[i][j].index] = nowans2;
		}
	}
	
	for(int i=0; i<q; i++){
		cout << ans1[i] << " " << ans2[i] << "\n";
	}
}


0