LOJ#6085. 「美团 CodeM 资格赛」优惠券(set)
生活随笔
收集整理的這篇文章主要介紹了
LOJ#6085. 「美团 CodeM 资格赛」优惠券(set)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意
題目鏈接
Sol
考慮不合法的情況只有兩種:
進去了 再次進去
沒進去 但是出來了
顯然可以用未知記錄抵消掉
直接開個set維護一下所有未知記錄的位置
最優策略一定是最后一次操作位置的后繼
同時我們需要記錄一下每個人是否在里面
#include<bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; inline int read() {char c = getchar(); int x = 0, f = 1;while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();return x * f; } int M, las[MAXN], op[MAXN];//las上一次進去的時間 op最后一次操作的位置 set<int> ms; signed main() {//freopen("a.in", "r", stdin);M = read();for(int i = 1; i <= M; i++) {char c = 'g';while(c != 'I' && c != 'O' && c != '?') c = getchar();if(c == 'I') {int x = read();if(las[x]) {//在里面 auto pos = ms.upper_bound(op[x]);if(pos == ms.end() || (*pos > i)) return printf("%d", i), 0;else ms.erase(pos);}las[x] = 1;op[x] = i;} else if(c == 'O') {int x = read();if(!las[x]) {auto pos = ms.upper_bound(op[x]);if(pos == ms.end() || (*pos > i)) return printf("%d", i), 0;else ms.erase(pos);}las[x] = 0;op[x] = i;} else ms.insert(i);c = 'g';}puts("-1");return 0; }轉載于:https://www.cnblogs.com/zwfymqz/p/10320183.html
總結
以上是生活随笔為你收集整理的LOJ#6085. 「美团 CodeM 资格赛」优惠券(set)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: selenium 文件上传
- 下一篇: 一封电子邮件的发送和接收的主要步骤