codechef Closing the Tweets 题解
来源:互联网 发布:java反射获取类上注解 编辑:程序博客网 时间:2024/04/29 21:12
Little kids, Jack and Evan like playing their favorite game Glass-and-Stone. Today they want to play something new and came across Twitter on their father's laptop.
They saw it for the first time but were already getting bored to see a bunch of sentences having at most 140 characters each. The only thing they liked to play with it is, closing and opening tweets.
There are N tweets on the page and each tweet can be opened by clicking on it, to see some statistics related to that tweet. Initially all the tweets are closed. Clicking on an open tweet closes it and clicking on a closed tweet opens it. There is also a button to close all the open tweets. Given a sequence of K clicks by Jack, Evan has to guess the total number of open tweets just after each click. Please help Evan in this game.
Input
First line contains two integers N K, the number of tweets (numbered 1 to N) and the number of clicks respectively (1 ≤ N, K ≤ 1000). Each of the following K lines has one of the following.
- CLICK X , where X is the tweet number (1 ≤ X ≤ N)
- CLOSEALL
Output
Output K lines, where the ith line should contain the number of open tweets just after the ith click.
Example
Input:3 6CLICK 1CLICK 2CLICK 3CLICK 2CLOSEALLCLICK 1Output:123201
单点更新的题目,记录一个开关数组就可以了。
这里使用bitset来做,bitset是非常好的容器。
最好还是不使用memset吧,因为memset只是清零,要赋予一定值的话,就可能会出错。
#pragma once#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>#include <bitset>using namespace std;class ClosingtheTweets{public:ClosingtheTweets() {int n, m;scanf("%d %d", &n, &m);bitset<1001> arr;char click[9];int num;int ans = 0;while (m--){scanf("%s", click);if (click[3] == 'S'){arr.reset();ans = 0;}else{scanf("%d", &num);if (arr[num] == 0) ans++;else ans--;arr[num] = !arr[num];}printf("%d\n", ans);}}};
- codechef Closing the Tweets 题解
- codechef The Lead Game 题解
- codechef The Morning Commute 题解
- codechef Holes in the text 题解
- codechef - Discrepancies in the Voters List 题解
- codechef Johnny and the Beanstalk 题解
- codechef The Ball And Cups题解
- codechef Chef and The Right Triangles 题解
- 【贪心】CodeChef(PROTEPOI)[Protecting The Poison]题解
- codechef Turbo Sort 题解
- codechef Ambiguous Permutations 题解
- codechef Prime Palindromes 题解
- Codechef Nuclear Reactors 题解
- codechef Cleaning Up 题解
- codechef Permutation Cycles 题解
- codechef Birthday Candles 题解
- codechef Cutting Recipes题解
- codechef Carvans 题解
- 如何在tsung中使用动态参数(一)
- 获取dimens值问题
- 心死了,人还在,怎么办?
- Wireshark和TcpDump抓包分析心得
- 新手求照应
- codechef Closing the Tweets 题解
- MongoDb之MapReduce
- eclipse android开发环境
- $('#checkbox').attr('checked'); 返回的是checked或者是undefined解决办法
- #pragma用法大全
- Java 的JSON、XML转换方法——目录索引(转载)
- 第六周作业1——利用哈夫曼编码英文字母表
- [转] Linux bash 脚本编写
- 关于Devexpress 12.1.x.x如何汉化