【STL】codeforces 818D Multicolored Cars
来源:互联网 发布:幽浮2知乎 编辑:程序博客网 时间:2024/05/29 19:30
Link:http://codeforces.com/problemset/problem/818/D
#include <bits/stdc++.h>using namespace std;typedef long long LL;/*题意:在 1 到 n 时刻,有 n 量有颜色的车通过,用数字表示颜色,Alice 选择一个颜色A,要求 Bob 选择一个颜色B,使得对于任意时刻 cnt(B) >= cnt(A),即通过的颜色为 B 的车始终不小于颜色为 A 的车。求任意满足条件的解,否则输出 -1 。题解:将出现A颜色之前的颜色以及出现的次数在集合里存起来,到A颜色的时候全部减去1,当减成-1时,推出集合,永远不再加入集合,处理到最后,集合里的元素都是可以的*/const int Maxn = 1e6+6;set<int> set1,set2;int num[Maxn],ff[Maxn];int main(){ int n,a; scanf("%d%d",&n,&a); int f = 0; for(int i = 0; i < n; i++) { int x; scanf("%d",&x); if(x != a) { if(!f || set2.count(x)) { set1.insert(x); num[x]++; } } else { f = 1; int k = 0; set<int>::iterator it; for(it = set2.begin(); it != set2.end(); it++) { num[*it]--; if(num[*it] == 0) ff[k++] = *it; } for(int i = 0; i < k; i++) set2.erase(ff[i]); set2.insert(set1.begin(),set1.end()); set1.clear(); } } if(!f) { printf("%d\n",*set1.begin()); return 0; } if(set2.empty()) puts("-1"); else printf("%d\n",*set2.begin()); return 0;}
阅读全文
0 0
- 【STL】codeforces 818D Multicolored Cars
- codeforces 818D Multicolored Cars
- Educational Codeforces Round 24 D. Multicolored Cars 补题
- Educational Codeforces Round 24 (B Permutation Game,D. Multicolored Cars)
- Multicolored Cars
- Codeforces 818D Multicolored Car【思维+线段树】
- codeforces818D Multicolored Cars -- 线段树上二分
- Codeforces 620D STL+二分
- codeforces 660D (STL map)
- codeforces 675D (STL set)
- CodeForces 534D Handshakes 【STL】+【贪心】
- CodeForces 246D. Colorful Graph【STL】
- codeforces 200 D Programming Language(stl)
- CodeForces 303A Toy Cars
- codeforces 721D D. Maxim and Array (STL||优先队列)
- codeforces #303 div2 A. Toy Cars
- Codeforces Round #303 A. Toy Cars
- CodeForces - 545A Toy Cars (模拟)
- TypeError: pivot_table() got an unexpected keyword argument 'rows'
- HDD is Outdated Technology
- unity调用外部的exe
- Confusing Date Format
- idea将maven项目打包成war包的方式,以及使用war包
- 【STL】codeforces 818D Multicolored Cars
- HDU 1848[Fibonacci again and again] 题解
- HDU 3264 Open-air shopping malls
- C# 使用 itextsharp 对pdf文件进行分割的几种方法(1)——按页码拷贝分割
- 设计模式:单例模式-懒汉模型和饿汉模型
- JAVA标准异常
- Java选择排序算法
- iOS WebView加载url缓存问题
- bugku 你必须让他停下