首页 > 其他 > 详细

hdu 5233 Gunner II

时间:2015-05-25 10:13:56      阅读:163      评论:0      收藏:0      [点我收藏+]

开始试了很多方法,不过由于删除的效率导致tle,总之无论什么方法,能ac就是好方法

#include<iostream>
#include<vector>
#include<map>
using namespace std;
vector<int>mapp[100000+5];
map<int,int>root;
int he[100000+5];
int main()
{
    int n,m;
    cin.sync_with_stdio(false);
    while(cin>>n>>m)
    {
        for(int i=1;i<=n;i++) mapp[i].clear();
        root.clear();
        for(int i=1;i<=n;i++) cin>>he[i];
        for(int i=n;i>=1;i--)
        {
            if(root.find(he[i])==root.end()) root[he[i]]=i,mapp[i].push_back(i);
            else mapp[root[he[i]]].push_back(i); 
        }
        for(int i=0;i<m;i++)
        {
            int x;
            cin>>x;
            x=root[x];
            if(mapp[x].size()) cout<<mapp[x][mapp[x].size()-1]<<endl,mapp[x].erase(mapp[x].end()-1);
            else cout<<"-1"<<endl;
        }
    }
    return 0;
}


 

hdu 5233 Gunner II

原文:http://blog.csdn.net/zafkiel_nightmare/article/details/45954217

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!