結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー guestguest
提出日時 2016-11-21 12:34:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 228 ms / 5,000 ms
コード長 1,483 bytes
コンパイル時間 1,729 ms
コンパイル使用メモリ 182,948 KB
実行使用メモリ 19,708 KB
最終ジャッジ日時 2023-10-23 15:58:28
合計ジャッジ時間 9,658 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 4 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 148 ms
4,400 KB
testcase_13 AC 147 ms
8,568 KB
testcase_14 AC 176 ms
8,560 KB
testcase_15 AC 139 ms
8,572 KB
testcase_16 AC 165 ms
8,572 KB
testcase_17 AC 161 ms
8,580 KB
testcase_18 AC 150 ms
4,400 KB
testcase_19 AC 168 ms
8,568 KB
testcase_20 AC 171 ms
8,564 KB
testcase_21 AC 146 ms
8,576 KB
testcase_22 AC 167 ms
8,564 KB
testcase_23 AC 149 ms
4,400 KB
testcase_24 AC 161 ms
8,564 KB
testcase_25 AC 165 ms
4,400 KB
testcase_26 AC 181 ms
4,400 KB
testcase_27 AC 149 ms
8,572 KB
testcase_28 AC 149 ms
8,568 KB
testcase_29 AC 170 ms
8,564 KB
testcase_30 AC 136 ms
8,576 KB
testcase_31 AC 146 ms
8,580 KB
testcase_32 AC 168 ms
8,560 KB
testcase_33 AC 160 ms
8,568 KB
testcase_34 AC 164 ms
4,400 KB
testcase_35 AC 139 ms
8,580 KB
testcase_36 AC 168 ms
4,400 KB
testcase_37 AC 136 ms
19,708 KB
testcase_38 AC 183 ms
11,728 KB
testcase_39 AC 167 ms
11,728 KB
testcase_40 AC 165 ms
11,728 KB
testcase_41 AC 228 ms
12,256 KB
testcase_42 AC 123 ms
12,256 KB
testcase_43 AC 161 ms
4,348 KB
testcase_44 AC 114 ms
4,400 KB
testcase_45 AC 137 ms
19,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>


#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define dnmin(a,b) (a)=min((a),(b))

using namespace std;
typedef vector<int> VI;
typedef pair<int, int> pii;

struct Bitree {
	typedef int btT;
	vector<btT> bv;
	Bitree() :bv(100005){}
	Bitree(int n) : bv(n + 3) {}
	btT sum(int i) {
		btT res=0; for(i++; i>0; i -= i & -i) res += bv[i]; return res;
	}
	btT sum(int a, int b) {return sum(b) - (a? sum(a-1): 0);}
	void add(int i, btT x){for(i++; i<(int)bv.size(); i += i & -i) bv[i] += x; }
};


int main(){
 
	int n, t, mno=0;
	cin >>n;
	VI hs(n);
	unordered_map<string, VI> mp;
	Bitree bta(600*27);
	vector<VI> va(600*27);
	rep(i,n) cin >>hs[i];
	cin >> t;
	VI nos(n);
	rep(i, t){
		string s; char a;
		cin >> s >> a;
		if(!mp.count(s)){
			mp[s] = VI{ 0,0, ++mno};
			//rcv[mp[s][2]] = s;
		}
		if(a != '?'){
			if(mp[s][0] !=0){
				bta.add(mp[s][0], -1);
				auto it = lower_bound(all(va[mp[s][0]]), mp[s][1]);
				assert(*it == mp[s][1]);
				if(it != va[mp[s][0]].end() && *it == mp[s][1]) va[mp[s][0]].erase(it);
			}
			mp[s][1] = i+1;
			int mz= a-'A';
			mp[s][0] += 50 * hs[mz] + (500 * hs[mz]) / (8 + 2* (++nos[mz]));
			bta.add(mp[s][0], 1);
			va[mp[s][0]].push_back(mp[s][1]);
		}else{
			int ans = bta.sum( mp[s][0] + 1, 600*27);
			auto& wv = va[mp[s][0]];
			int ans2 = lower_bound(all(wv), mp[s][1]) - wv.begin();
			cout << ans + ans2 + 1 <<"\n";
		}
	}
	
	return 0;
}
 
0