結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー latte0119
提出日時 2016-11-19 00:19:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 360 ms / 5,000 ms
コード長 3,071 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 172,336 KB
実行使用メモリ 20,736 KB
最終ジャッジ日時 2024-09-22 10:16:35
合計ジャッジ時間 13,229 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:104:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  104 |     scanf("%lld",&N);
      |     ~~~~~^~~~~~~~~~~
main.cpp:105:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  105 |     rep(i,N)scanf("%lld",&L[i]);
      |             ~~~~~^~~~~~~~~~~~~~
main.cpp:107:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  107 |     int T;scanf("%lld",&T);
      |           ~~~~~^~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
unsigned long r() {
static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
unsigned long t=(x^(x<<11));
x=y; y=z; z=w;
return ( w=(w^(w>>19))^(t^(t>>8)) );
}
struct node{
int p,t;
node *lch,*rch;
int cnt;
node(int p,int t):p(p),t(t),lch(NULL),rch(NULL),cnt(1){}
};
inline int cnt(node *t){return t?t->cnt:0;}
inline node *update(node *t){
if(!t)return NULL;
t->cnt=cnt(t->lch)+1+cnt(t->rch);
return t;
}
node *merge(node *a,node *b){
if(!a)return b;
if(!b)return a;
if(r()%(cnt(a)+cnt(b))<cnt(a)){
a->rch=merge(a->rch,b);
return update(a);
}
else{
b->lch=merge(a,b->lch);
return update(b);
}
}
pair<node *,node *>split(node *t,int k){
if(!t)return make_pair((node *)NULL,(node *)NULL);
if(k<=cnt(t->lch)){
pair<node *,node *>s=split(t->lch,k);
t->lch=s.second;
return make_pair(s.first,update(t));
}
else{
pair<node *,node *>s=split(t->rch,k-cnt(t->lch)-1);
t->rch=s.first;
return make_pair(update(t),s.second);
}
}
int f(int a,int b){
return a*50+(500*a)/(8+2*b);
}
node *root;
int find(node *t,pint v){
if(!t)return 0;
if(t->p<v.fi||(t->p==v.fi&&t->t>v.se))return find(t->lch,v);
return cnt(t->lch)+1+find(t->rch,v);
}
void insert(pint v){
int t=find(root,v);
pair<node *,node *>s=split(root,t);
root=merge(s.first,merge(new node(v.fi,v.se),s.second));
}
void erase(pint v){
int t=find(root,v);
pair<node *,node *>s1=split(root,t-1);
pair<node *,node *>s2=split(s1.second,1);
root=merge(s1.first,s2.second);
}
void debug(node *t){
if(t==NULL)return;
debug(t->lch);
cout<<"("<<t->p<<","<<t->t<<") ";
debug(t->rch);
}
void debug(){
cout<<"[ ";debug(root);
cout<<" ]"<<endl;
}
int N;
int L[26];
signed main(){
scanf("%lld",&N);
rep(i,N)scanf("%lld",&L[i]);
int T;scanf("%lld",&T);
root=NULL;
int cnt[26]={};
map<string,pint>scr;
rep(i,T){
string s;
char c;
cin>>s>>c;
if(c=='?'){
printf("%lld\n",find(root,scr[s]));
}
else{
int tmp=f(L[c-'A'],++cnt[c-'A']);
if(scr.find(s)==scr.end()){
scr[s]={tmp,i};
insert({tmp,i});
}
else{
erase(scr[s]);
scr[s].fi+=tmp;
scr[s].se=i;
insert(scr[s]);
}
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0