HDU 4031 Attack (tree array), hdu4031

Source: Internet
Author: User

HDU 4031 Attack (tree array), hdu4031
Problem DescriptionToday is the 10th Annual of "September 11 attacks", the Al Qaeda is about to attack American again. however, American is protected by a high wall this time, which can be treating as a segment with length N. al Qaeda has a super weapon, every second it can attack a continuous range of the wall. american deployed N energy shield. each one defends one unit length of the wall. however, after the shield defends one attack, it needs t seconds to cool down. if the shield defends an attack at kth second, it can't defend any attack between (k + 1) th second and (k + t-1) th second, random Sive. the shield will defend automatically when it is under attack if it is ready.

During the war, it is very important to understand the situation of both self and the enemy. so the commanders of American want to know how much time some part of the wall is successfully attacked. successfully attacked means that the attack is not defended by the shield.
 
InputThe beginning of the data is an integer T (T ≤ 20), the number of test case.
The first line of each test case is three integers, N, Q, t, the length of the wall, the number of attacks and queries, and the time each shield needs to cool down.
The next Q lines each describe one attack or one query. It may be one of the following formats
1. Attack si ti
Al Qaeda attack the wall from si to ti, random Sive. 1 ≤ si ≤ ti ≤ N
2. Query p
How many times the pth unit have been successfully attacked. 1 ≤ p ≤ N
The kth attack happened at the kth second. Queries don't take time.
1 ≤ N, Q ≤ 20000
1 ≤ t ≤ 50
 
OutputFor the ith case, output one line "Case I:" at first. then for each query, output one line containing one integer, the number of time the pth unit was successfully attacked when asked.
Sample Input

23 7 2Attack 1 2Query 2Attack 2 3Query 2Attack 1 3Query 1Query 39 7 3Attack 5 5Attack 4 6Attack 3 7Attack 2 8Attack 1 9Query 5Query 3
 
Sample Output
Case 1:0101Case 2:32
Question:
The United States has established a new defense system. Each point can be automatically defended, but after the defense is completed
It takes a cool-down period, that is, no defense is allowed during this period. Now there are two more operations: 1. Terrorists
Each time a range of attacks is attacked. 2. The Commander inquired about the number of attacks at a certain point.
BIT practice: we know that it takes no time to ask, So we consider designing an array tt [I] to record the I point.
The defense time. When the time t> = tt [I] indicates that the attack can be defended. The number of attacks =
Total number of attacks-Number of defenses.
# Include <cstdio> # include <cstring> # include <algorithm> # include <vector> # include <string> # include <iostream> # include <queue> # include <cmath> # include <map> # include <stack> # include <bitset> using namespace std; # define REPF (I, a, B) for (int I = a; I <= B; ++ I) # define REP (I, n) for (int I = 0; I <n; ++ I) # define CLEAR (a, x) memset (a, x, sizeof a) typedef long LL; const int maxn = 20005; int N, Q, T, t; int c [maxn], d [maxn], tt [maxn]; // tt [I] records the time at which defense can be performed at a certain point. Defense can be performed at a time later than this time; struct node // d [I] records the number of successful defenses at a certain point {int l, r;} e [maxn]; int lowbit (int x) {return x & (-x);} void update (int x, int w) {while (x <maxn) {c [x] + = w; x + = lowbit (x) ;}} int query (int x) {int s = 0; while (x> 0) {s + = c [x]; x-= lowbit (x);} return s;} int main () {int cas = 1; int pos, l, r; char str [5]; scanf ("% d", & t); while (t --) {int cnt = 0; CLEAR (c, 0); CLEAR (tt, 0); CLEAR (d, 0); scanf ("% d", & N, & Q, & T); printf ("Case % d: \ n", cas ++ ); while (Q --) {scanf ("% s", str); if (str [0] = 'A') {scanf ("% d ", & l, & r); e [cnt]. l = l; e [cnt ++]. r = r; update (l, 1); update (r + 1,-1);} else {scanf ("% d", & pos ); for (int I = tt [pos]; I <cnt; I ++) // records the time when a point can be defended, all attacks greater than or equal to this time can be automatically defended {if (pos> = e [I]. l & pos <= e [I]. r) {d [pos] ++; tt [pos] = I + T; I + = T-1;} printf ("% d \ n", query (pos) -d [pos]) ;}} return 0 ;}


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.