码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5233 Gunner II

时间:2015-05-25 10:16:44      阅读:98      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!