URAL 1613 For Fans of Statistics

题意:就是给了你n个数字,他们的编号为1到n,然后接下来有q个询问,每次询问有 l,r,x, 就是问你 是否 在编号区间[l,r]内有数字X出现过,有就是1,无就是0,最后一起输出来

输入其实数字是有重复的,所以先用map离散化,然后再用map跟vector 的邻接表连接,讲编号放入邻接表里面,并升序排序,然后询问的时候直接二分查找编号,是否存在就可以了,手写的二分 一直WA,莫名其妙,,改用Lower_bound就过了

int n;map<string ,int>mark,mp;vector<int > G[70000 + 55];int tot;void init() {mp.clear();mark.clear();for(int i=0;i<70000 + 55;i++)G[i].clear();tot = 1;}bool input() {while(cin>>n) {string tmp;for(int i=0;i<n;i++) {cin>>tmp;if(!mark[tmp]) {mp[tmp] = tot;G[tot].push_back(i + 1);tot++;mark[tmp]++;}else G[mp[tmp]].push_back(i + 1);}return false;}return true;}void cal() {for(int i=1;i<=tot;i++)sort(G[i].begin(),G[i].end());int q;cin>>q;int le,ri;string now;string ans = "";while(q–) {cin>>le>>ri>>now;int pos = mp[now];if(pos == 0) {ans += "0";continue;}int len = G[pos].size();int Head = lower_bound(G[pos].begin(),G[pos].end(),le) – G[pos].begin();if(Head < len && G[pos][Head] <= ri)ans += "1";else ans += "0";}cout<<ans<<endl;}void output() {}int main() {while(true) {init();if(input())return 0;cal();output();}return 0;}/*51234567 666666 3141593 666666 434343451 5 31415931 5 5782022 4 6666664 4 6666661 1 1234567*/

仿佛松树就是一位威风的将军,守护着国家的国民。

URAL 1613 For Fans of Statistics

相关文章:

你感兴趣的文章:

标签云: