0% found this document useful (0 votes)
53 views2 pages

Prob-A - Suspicious Event

The document describes a problem analyzing a login/logout sequence of users represented by integers. The sequence records login events as positive integers and logout events as negative integers. The task is to count suspicious logout events, where a user logged out without having previously logged in. A sample input/output is provided demonstrating two suspicious logout events in a sequence of 8 events from 5 users.

Uploaded by

blackwidow23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views2 pages

Prob-A - Suspicious Event

The document describes a problem analyzing a login/logout sequence of users represented by integers. The sequence records login events as positive integers and logout events as negative integers. The task is to count suspicious logout events, where a user logged out without having previously logged in. A sample input/output is provided demonstrating two suspicious logout events in a sequence of 8 events from 5 users.

Uploaded by

blackwidow23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Problem A

Suspicious Event

Before you graduate from your beloved university, you managed to secure an internship at a security com-
pany. Your first task is to analyze a login/logout sequence.
You are given a sequence of integers A that represents a record for users login/logout events in chronological
order. Each user is represented by a unique integer. A positive integer x indicates a login event while a
negative integer −x indicates a logout event by user |x|. You are guaranteed that there are no two events
that are the same in A.
Once in a while, you might find from the record, a user who logs out even though that user has never
been logged in previously. This can be due to a bug in the system or a hacking attempt. Nevertheless, it’s
suspicious!
For example, let A1..8 = (8, 3, −8, −6, 7, −3, −1, 6). There are 8 events from 5 distinct users (the users are
1, 3, 6, 7, and 8). The events are as follows.

• A1 = 8 → user 8 log in.

• A2 = 3 → user 3 log in.

• A3 = −8 → user 8 log out.

• A4 = −6 → user 6 log out – suspicious event! (user 6 has not logged in)

• A5 = 7 → user 7 log in.

• A6 = −3 → user 3 log out.

• A7 = −1 → user 1 log out – suspicious event! (user 1 has not logged in)

• A8 = 6 → user 6 log in.

In total, there are 2 suspicious logout events, i.e. A4 = −6 and A7 = −1. Note that although user 6 logs in
at A8 , he has not logged in when he logs out at A4 .
Your task in this problem is to count how many logout suspicious events are there given the login/logout
record.

Input
Input begins with a line containing an integer N (1 ≤ N ≤ 1000) representing the number of events in the
given record. The next line contains N integers Ai (−1000 ≤ Ai ≤ 1000; Ai 6= 0) each representing an event
in chronological order. It is guaranteed that all integers in A are distinct.

Output
Output contains an integer in a line representing the number of suspicious logout events.

ICPC INC 2021 Problem A. Suspicious Event


Sample Input #1
8
8 3 -8 -6 7 -3 -1 6

Sample Output #1
2

Explanation for the sample input/output #1


This is the example from the problem description.

Sample Input #2
4
17 -17 12 -12

Sample Output #2
0

Sample Input #3
4
-317 -1 -20 -300

Sample Output #3
4

Sample Input #4
4
27 108 36 9

Sample Output #4
0

Sample Input #5
4
-100 -200 200 100

Sample Output #5
2

ICPC INC 2021 Problem A. Suspicious Event

You might also like