Codeforces 704A (queue emulation) Thor

Source: Internet
Author: User

Title: Here

Test instructions: N app,q operation, when the operand type is 1 indicates y this app pushes you a message, when the operand type is 2 indicates that Y this app has pushed all the messages are read, when the operand is 3

Indicates that the pre-pushed (in chronological order of push) Y messages are read again (regardless of what has been read in the previous Y-message, read it again), and ask what is the number of unread messages per operation?

Use the queue to simulate the good, remember that every time you want to output the total number of messages that are not read by all the app, do not think too thin, read the mark on the line, always think this will time out, but I think this is the third problem of 2, 1

The first question, should not so the card time, all have the courage to write.

1 //The queue simply records the CAs and does not need to record Y2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <cstring>7#include <queue>8 using namespacestd;9 Ten Const intM = 3e5 +Ten; One BOOLVi[m]; Aqueue<pair<int,int> >Q[m]; -  - intMain () the { -     intn,m; -     Long Longans=0; -scanf"%d%d",&n,&m); +     intpo=1, cas=0, r=0; -Memset (VI,false,sizeof(vi)); +      while(m--) A     { at         intx, y; -scanf"%d%d",&x,&y); -         if(x==1) Q[y].push (make_pair<int,int> (Y,++cas)), ans++; -         Else if(x==2) { -              while(!q[y].empty ()) -             { in                 intw=Q[y].front (). Second; -                 if(vi[w]==false) ans--; tovi[w]=true; + Q[y].pop (); -             } the         } *         Else { $              for(intI=po; I<=min (Cas,y); i++)Panax Notoginseng             { -                  if(vi[i]==false) ans--; thevi[i]=true; +             } Apo=Max (po,y); the         } +printf"%i64d\n", ans); -     } $     return 0; $}

Codeforces 704A (queue emulation) Thor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.