結果
| 問題 |
No.449 ゆきこーだーの雨と雪 (4)
|
| ユーザー |
nola_suz
|
| 提出日時 | 2016-11-19 00:18:07 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 952 ms / 5,000 ms |
| コード長 | 4,479 bytes |
| コンパイル時間 | 1,956 ms |
| コンパイル使用メモリ | 126,908 KB |
| 実行使用メモリ | 47,004 KB |
| 最終ジャッジ日時 | 2024-09-22 10:17:09 |
| 合計ジャッジ時間 | 22,839 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
//#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define VV(T) vector<vector< T > >
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
v.assign(a, vector<T>(b, t));
}
template <class F, class T>
void convert(const F &f, T &t){
stringstream ss;
ss << f;
ss >> t;
}
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
template <class Tp>
class fenwick_tree{
std::vector<Tp> bit;
public:
fenwick_tree(){}
explicit fenwick_tree(std::size_t n) : bit(n + 1) {}
Tp sum(std::size_t i) const{
Tp s = 0;
while(i){
s += bit[i];
i -= i & -i;
}
return s;
}
void add(std::size_t i, Tp x){
while(i < bit.size()){
bit[i] += x;
i += i & -i;
}
}
void clear(){
bit.clear();
}
void assign(std::size_t n){
bit.assign(n + 1, Tp());
}
void swap(fenwick_tree &f){
bit.swap(f.bit);
}
};
void mainmain(){
int n;
cin>>n;
vint v(n);
rep(i,n) cin>>v[i];
int T;
cin>>T;
typedef pair<pii,vint> P;
map<string,P> ma;
vint cnt(n,1);
vector<pair<string,string>> input(T);
set<pii> score;
vector<pii> w;
rep(i,T){
string s;
cin>>s;
string t;
cin>>t;
input[i]=mkp(s,t);
if(t[0]=='?'){
// set<pii>::iterator it = score.upper_bound(pii(-ma[s].F.F, -ma[s].F.S));
// int ans = distance(score.begin(), it);
// ans = score.size()-ans;
// cout<<ans+1<<endl;
w.PB(pii(-ma[s].F.F,-ma[s].F.S));
continue;
}
if(ma.count(s)==0){
ma[s]=mkp(pii(0,i),vint(n));
score.insert(pii(0,i));
}
int tt = t[0]-'A';
ma[s].S[tt]=(50*v[tt] + (50*v[tt]/(0.8+0.2*cnt[tt])));
score.erase(pii(-ma[s].F.F, -ma[s].F.S));
ma[s].F.F-=ma[s].S[tt];
ma[s].F.S=i;
score.insert(pii(-ma[s].F.F, -ma[s].F.S));
cnt[tt]++;
}
sort(ALL(w));
ma=map<string,P>();
cnt=vint(n,1);
score.clear();
fenwick_tree<int> bit(w.size()+100);
rep(i,T){
// cout<<i<<endl;
string s=input[i].F;
string t=input[i].S;
if(t[0]=='?'){
// set<pii>::iterator it = score.upper_bound(pii(-ma[s].F.F, -ma[s].F.S));
// int ans = distance(score.begin(), it);
// ans = score.size()-ans;
// cout<<ans+1<<endl;
int idx = lower_bound(ALL(w), pii(-ma[s].F.F, -ma[s].F.S))-w.begin();
int ans = bit.sum(w.size()+11) - bit.sum(idx+1);
cout<<ans+1<<endl;
continue;
}
if(ma.count(s)==0){
ma[s]=mkp(pii(0,i),vint(n));
score.insert(pii(0,i));
}
int tt = t[0]-'A';
ma[s].S[tt]=(50*v[tt] + (50*v[tt]/(0.8+0.2*cnt[tt])));
score.erase(pii(-ma[s].F.F, -ma[s].F.S));
int idx = lower_bound(ALL(w), pii(-ma[s].F.F, -ma[s].F.S))-w.begin();
bit.add(idx+1, -1);
ma[s].F.F-=ma[s].S[tt];
ma[s].F.S=i;
score.insert(pii(-ma[s].F.F, -ma[s].F.S));
idx = lower_bound(ALL(w), pii(-ma[s].F.F, -ma[s].F.S))-w.begin();
bit.add(idx+1, 1);
cnt[tt]++;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(20);
mainmain();
}
nola_suz