题目描述
为了KK周年邀请赛,Admin有N个物品,他们分别放到了N个大小相同的盒子中,由于某种原因,Admin只想选择其中的一些作为比赛的奖品,但是由于物品数量太多,所以请你写一个程序来帮帮他吧!Admin一共需要以下功能:
1.查询是否有物品被选择(初始状态下所有物品都没有被选择)
2.当前选择了多少物品
3.查询编号为id的物品选择情况
4.将编号为id的物品选择情况取反(原先选择变为不选择,原先不选择变为选择)
输入
第一行N,M,表示有N个物品,M个操作,下面共M行,每一行描述一个操作。
如果这行是”any”,则表示第一个操作
如果这行是”count”,则表示第二个操作
如果这行是”find”+id,则表示第三个操作
如果这行是”filp”+id,则表示第四个操作
输出
每个第一、二、三操作,都需要输出一行。对于第一个询问,输出T或者F分别表示有和无,第二个操作输出一个数,第三个操作输出T或F,分别表示选择和没有选择。
样例输入
10 8
any
filp 1
filp 2
count
any
find 2
filp 2
find 2
样例输出
F
2
T
T
F
提示
30%的数据,n<=100
100%的数据,n<=1015,m<=100,0<id<=n
————————————————————————————————————————————————————————————————
题目很水,一波就可以过
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define read read()
const ll inf = 1e15;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define start int wuyt()
#define end return 0
map<ll,ll>num;
start{
ll n=read,m=read;
char judge[10];
ll cnt=0;
while(m--){
cin>>judge+1;
if(judge[3]=='y'){
if(cnt==0) printf("F
");
else if(cnt!=0) printf("T
");
}
else if(judge[3]=='u') printf("%lld
",cnt);
else if(judge[3]=='n'){
ll shu=read;
if(num[shu]==0) printf("F
");
if(num[shu]==1) printf("T
");
}
else if(judge[3]=='l'){
ll temp=read;
if(num[temp]==0){
num[temp]=1;
cnt++;
}
else if(num[temp]==1){
num[temp]=0;
cnt--;
}
}
}
end;
}
/**************************************************************
Language: C++
Result: 正确
Time:2 ms
Memory:2032 kb
****************************************************************/