結果

問題 No.2338 Range AtCoder Query
ユーザー 沙耶花沙耶花
提出日時 2023-06-02 21:56:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,334 bytes
コンパイル時間 5,152 ms
コンパイル使用メモリ 270,040 KB
実行使用メモリ 156,352 KB
最終ジャッジ日時 2023-08-28 03:22:44
合計ジャッジ時間 23,910 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 719 ms
156,096 KB
testcase_32 AC 700 ms
156,100 KB
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
using P = pair<int,int>;
P op(P a,P b){
	a.first += b.first;
	a.second += b.second;
	return a;
}

P e(){
	return make_pair(0,0);
}

int main(){
	
	int n,m,q;
	cin>>n>>m>>q;
	
	vector<int> p(n),s(n);
	rep(i,n){
		cin>>p[i];
		p[i]--;
		string ss;
		cin>>ss;
		if(ss[0]=='A')s[i] = 1;
		else s[i] = 0;
	}
	vector<vector<int>> qs(n);
	vector<int> l(q),r(q);
	rep(i,q){
		cin>>l[i]>>r[i];
		l[i]--,r[i]--;
		qs[r[i]].push_back(i);
	}
	vector<int> ac(q),wa(q);
	vector<deque<int>> D(m,deque<int>(1,-1));
	segtree<P,op,e> seg(n+1);
	rep(i,n){
		if(s[i]==0){
			D[p[i]].push_back(i);
		}
		else{
			int cnt = D[p[i]].size() - 1;
			int cur = 1;
			while(D[p[i]].size()>1){
				int u = D[p[i]].back();
				D[p[i]].pop_back();
				seg.set(u,make_pair(cur,0));
				cur++;
			}
			if(D[p[i]].back()!=-1)seg.set(D[p[i]].back(),make_pair(-cur,-1));
			seg.set(i,make_pair(0,1));
			D[p[i]].front() = i;
		}
		rep(j,qs[i].size()){
			int ii = qs[i][j];
			ac[ii] = seg.prod(l[ii],n).second;
			wa[ii]  =seg.prod(l[ii],n).first;
		}
	}
	
	rep(i,q){
		cout<<ac[i]<<' '<<wa[i]<<endl;
	}
	
	return 0;
}
0