結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー latte0119latte0119
提出日時 2016-11-19 00:19:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 359 ms / 5,000 ms
コード長 3,071 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 173,600 KB
実行使用メモリ 21,012 KB
最終ジャッジ日時 2023-10-23 15:01:35
合計ジャッジ時間 13,092 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 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 4 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 278 ms
6,984 KB
testcase_13 AC 336 ms
10,892 KB
testcase_14 AC 291 ms
9,708 KB
testcase_15 AC 359 ms
11,452 KB
testcase_16 AC 308 ms
10,272 KB
testcase_17 AC 334 ms
10,288 KB
testcase_18 AC 276 ms
6,972 KB
testcase_19 AC 286 ms
9,704 KB
testcase_20 AC 280 ms
9,680 KB
testcase_21 AC 335 ms
10,864 KB
testcase_22 AC 335 ms
10,904 KB
testcase_23 AC 278 ms
6,972 KB
testcase_24 AC 312 ms
10,280 KB
testcase_25 AC 265 ms
6,064 KB
testcase_26 AC 249 ms
5,144 KB
testcase_27 AC 329 ms
10,864 KB
testcase_28 AC 331 ms
10,876 KB
testcase_29 AC 283 ms
9,664 KB
testcase_30 AC 358 ms
11,472 KB
testcase_31 AC 344 ms
10,900 KB
testcase_32 AC 288 ms
9,696 KB
testcase_33 AC 320 ms
10,300 KB
testcase_34 AC 264 ms
6,076 KB
testcase_35 AC 357 ms
11,488 KB
testcase_36 AC 264 ms
6,068 KB
testcase_37 AC 217 ms
21,012 KB
testcase_38 AC 248 ms
12,420 KB
testcase_39 AC 209 ms
12,420 KB
testcase_40 AC 228 ms
12,420 KB
testcase_41 AC 313 ms
14,764 KB
testcase_42 AC 260 ms
14,764 KB
testcase_43 AC 179 ms
6,408 KB
testcase_44 AC 137 ms
8,476 KB
testcase_45 AC 154 ms
21,012 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
}
0