Content

有 \(n\) 个字符串,每次出现这个单词就把这个单词放到队列的队首(若已经出现就把原队列里面的那个单词提到队首),求最后的队列由队首到队尾的元素依次是多少。

数据范围:\(1\leqslant n\leqslant 2\times 10^5\)。

Solution

直接用结构体存储一下每个字符串最后出现的位置(可以用 \(\texttt{map}\) 直接映射),然后我们按出现的位置从大到小排序即可。

Code

#include <cstdio>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std; struct node {
string name;
int last;
bool operator < (const node& cjy) const {return last > cjy.last;}
}a[200007];
map<string, int> vis;
int n, cnt; int main() {
//This program is written in Ubuntu 16.04 by Eason_AC
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
string s;
cin >> s;
if(!vis[s]) {
a[++cnt].name = s;
vis[s] = cnt;
}
a[vis[s]].last = i;
}
sort(a + 1, a + cnt + 1);
for(int i = 1; i <= cnt; ++i)
cout << a[i].name << endl;
return 0;
}

CF637B Chat Order 题解的更多相关文章

  1. VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) B. Chat Order 水题

    B. Chat Order 题目连接: http://www.codeforces.com/contest/637/problem/B Description Polycarp is a big lo ...

  2. Chat Order (map映射)

     Chat Order Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit ...

  3. codeforces 637B B. Chat Order(map,水题)

    题目链接: B. Chat Order time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  4. VK Cup 2016 - Qualification Round 1——B. Chat Order(试手stack+map)

    B. Chat Order time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  5. LeetCode Intersection of Two Arrays

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays/ 题目: Given two arrays, write a func ...

  6. LeetCode Reconstruct Itinerary

    原题链接在这里:https://leetcode.com/problems/reconstruct-itinerary/ 题目: Given a list of airline tickets rep ...

  7. Group Shifted Strings

    Given a string, we can "shift" each of its letter to its successive letter, for example: & ...

  8. PHP_D4_“简易聊天室 ”的具体技术实现

    上面已经介绍了系统的关键技术,下面对具体实现进行详解: 1.开发时,经常需要利用一个配置文件来存储系统的参数,例如:数据库连接信息等.这样可以提高系统的可移植性,当系统的配置发生变化时,例如:更改服务 ...

  9. 第15届浙江省赛 D Sequence Swapping(dp)

    Sequence Swapping Time Limit: 1 Second      Memory Limit: 65536 KB BaoBao has just found a strange s ...

随机推荐

  1. 类的访问权限和Object

    1.访问控制权限 1.1.访问控制权限都有哪些? 4个. private 私有 public 公开 protected 受保护 默认 1.2.以上的4个访问控制权限:控制的范围是什么? private ...

  2. P2066 机器分配 解析

    小日记: 1.今天新学的字体颜色,尽管不熟悉,但玩的666,卡星(开心) ╰( ̄▽ ̄)╮╰( ̄▽ ̄)╮╰( ̄▽ ̄)╮╰( ̄▽ ̄)╮╰( ̄▽ ̄)╮╰( ̄▽ ̄)╮ 2.今天油腔滑调,谅解亿下 P2066 ...

  3. [FJOI2021]游记

    高一这条命早在\(NOIP\)就没了,现在不过是强行续命罢了,希望死的不要很难看. 高二重开一档,最后一条命了,希望能高二进队\(Orz\). \(Day -2\) 开始敲板子. 先写了个交互的题,猜 ...

  4. Codeforces 1406E - Deleting Numbers(根分+数论)

    Codeforces 题面传送门 & 洛谷题面传送门 一道个人感觉挺有意思的交互题,本人一开始想了个奇奇怪怪的做法,还以为卡不进去,结果发现竟然过了,而且还是正解( 首先看到这类题目可以考虑每 ...

  5. 洛谷 P4663 - [BalticOI 2008]魔法石(dp)

    题面传送门 A:我该是有多无聊来写这种题的题解啊 B:大概是因为这题题解区里没有题解所以我来写一篇了,说明我有高尚的济世情怀(大雾 跑题了跑题了 首先看到字典序第 \(i\) 小小可以自然地想到按位决 ...

  6. Redis键空间通知(keyspace notification),事件订阅

      Redis键空间通知(keyspace notification),事件订阅   应用场景:有效期优惠券.24小时内支付.下单有效事件等等. 功能概览 键空间通知使得客户端可以通过订阅频道或模式, ...

  7. Java 堆、栈、队列(遇见再更新)

    目录 Java 栈.队列 栈 常用方法 案例 队列 Java 栈.队列 栈 常用方法 boolean empty() 测试堆栈是否为空 Object peek() 查看堆栈顶部的对象 Object p ...

  8. accelerate

    accelerate accelerare, accumulare和accurate共享一个含义为to的词根,后半截分别是:fast, pile up, care (关心则精确). 近/反义词: ex ...

  9. 实时数仓(二):DWD层-数据处理

    目录 实时数仓(二):DWD层-数据处理 1.数据源 2.用户行为日志 2.1开发环境搭建 1)包结构 2)pom.xml 3)MykafkaUtil.java 4)log4j.properties ...

  10. css通配样式初始化(多款,供君自选)

    腾讯官网 body,ol,ul,h1,h2,h3,h4,h5,h6,p,th,td,dl,dd,form,fieldset,legend,input,textarea,select{margin:0; ...