HDU 4031 Attack (tree-like array)

Source: Internet
Author: User
Tags cas

Problem Descriptiontoday is the 10th annual of "September one attacks", the Al Qaeda is about to attack American again. However, American is protected by a high-wall this time, which can-treating as a segment with length N. Al Qaeda have 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, Inc. Lusive. The shield would defend automatically when it was under attack if it was ready.

During the war, it's 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 are not defended by the shield.

Inputthe beginning of the data is a integer T (t≤20), the number of the test case.
The first line of all test case was three integers, N, Q, T, the length of the wall, the number of attacks and queries, an d 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, inclusive. 1≤si≤ti≤n
2. Query p
How many times the PTH unit has 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 to each query, output one line containing one integer, the number of time the PTH unit is successfully attacked whe N asked.
Sample Input
7 2Attack 1 2Query 2Attack 2 3Query 2Attack 1 3Query 1Query 7 3Attack 5 5Attack 4 6Attack 3 7Attack 2 8Attack 1 9Que Ry 5Query 3

Sample Output
Case 1:0101case 2:32
Test Instructions:
The United States has set up a new defense system. Each point can be automatically defended, but after the defense of that point
A cooling time is required, which means no further defenses can be made during this period. Now there are two operations: 1. Terrorists
Each time a range is attacked. 2. The commander asked how many times a point was attacked
Bit procedure: We know that because of asking for no time, so we consider designing an array tt[i] record I point can
The time of the defense, when time T>=tt[i], indicates that the attack can be defended. Then 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 long Ll;const int max    n = 20005;int n,q,t,t;int c[maxn],d[maxn],tt[maxn];//tt[i] record the time at which a point can be defended, greater than this time, and can be defended; struct node//d[i] records the number of successful defenses of a certain point { int l,r;} E[maxn];int lowbit (int x) {return x& (-X);}        void Update (int x,int W) {while (X&LT;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%d%d", &n,&q,&t);        printf ("Case%d:\n", cas++);            while (q--) {scanf ("%s", str);                if (str[0]== ' A ') {scanf ("%d%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++)//record the time at which a point can be defended, an attack greater than or equal to that time can be automatically defended {if (POS&GT;=E[I].L&A                        MP;&AMP;POS&LT;=E[I].R) {d[pos]++;                        Tt[pos]=i+t;                    i+=t-1;            }} printf ("%d\n", Query (POS)-d[pos]); }}} return 0;}


HDU 4031 Attack (tree-like array)

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.