hdu1342 learned and Jia Tiecheng

Source: Internet
Author: User

Address: http://acm.uestc.edu.cn/#/problem/show/1342

Topic:

learned and Krabi TiechengTime limit:1500/800ms (java/others) Memory limit:65535/65535kb (java/others)SubmitStatus

The world is driven by the waves of the industrial revolution, and since the modern times, the undead monsters have suddenly appeared. Coated with the skin of the steel, as long as the heart is not destroyed and will not be destroyed, the person bitten by it seems to have died once after the resurrection, and began to attack the human race. These monsters, known as Cabanes, proliferate and cover the world.

The people of the Far Eastern island of Japan, in order to combat the threat of the cat in the local construction called "Yi" city village, and stuck in it, trying to survive. Able to travel between the station only armored steam locomotive (known as June City), between the stations through their production of the facility, and finally to ensure the life.

Live in the production of iron-making and steam engines for the industry of the Yi Steam forge the juvenile, learned. In order to bring down the cat, he developed his own weapon "tube", while looking forward to one day to play their own power.

One day, across the front of June city, a tiecheng came to Yi. Learned, summoned for the purpose of cleaning the vehicle, witnessed an incredible maiden who was exempt from the obligatory Cabanes parade.

That night, learned with the name of the girl who called the Day of the unknown, at this time June city suddenly burst away and broke into a Yi. The attendants all went out, and all became Cabanes!

Cabanes from the display of the Golden Station overflow. The learned run as if to be retrograde in the waves of the man who was attacked by the panic. This time can not escape, I want to use the tube to defeat Cabanes!

So, in order to become a truly shining man, the Battle of learned began.

......

Now in this city there are N cabana, each of which has his own attributes A[i], learned tube can penetrate the [l,r] range of monsters with different properties!

In order to be strong enough to play the strength of their own weapons, learned must know in advance how many monsters can be killed by their disposable tube.

Let's start counting now!

Input

The first line gives you a n,q, indicating that there are N cabana inside, Q Times asked

The second line has n integers, representing the attributes within each of the Kabbah A[i]

The next Q line, two integers per line Li,ri, indicates an inquiry.

1 &lt;= n , q &lt;= 100000 ">1 <=n,q<=100000 1<=n,q<= 100000

1 &lt;= L i &lt;= R i &lt;= n ">1 <=li<=ri<= n 1<=li<=ri<=n

1<=a[i]<=10000 1<=a[i]<=10000

Output

For each inquiry, output the answer!

Sample Input and output
Sample Input Sample Output
5 31 2 3 1 11 31 43 5
332

Ideas:

Ps: The longest topic in all the topics ... See a lot of day, online various find information. IQ-100

The problem is the number of different numbers within the interval.

With a tree-like array, you can do it with a line tree. With Mo team can also, but I did not get out, WA a few hair,,

Start by ordering the right interval for all queries, then sweep all queries from left to right ....

For each property, record where it last occurred, the default is 0 at the beginning, and if it is the first time it is added to the tree array (that is, the value +1), then delete it from the tree array (value-1)

For each inquiry ans=sum (r)-sum (L-1), just sweep all the questions over.

After writing to find Lowbit incredibly after 0,, and then on the Tle,, but put all the numbers right down the good

1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <cmath>5#include <cstring>6#include <queue>7#include <stack>8#include <map>9#include <Set>Ten#include <vector> One#include <cstdlib> A#include <string> -#include <bitset> -  the #definePI ACOs ((double)-1) - #defineE exp (double (1)) - #defineK 100000 - using namespacestd; + structnode - { +     intL,r,id; A }q[k]; at intc[k],a[10009],ans[k+Ten],last[k+Ten]; - intN; - BOOLCMP (node tx,node ty) - { -     if(tx.r==TY.R) -         returntx.l<TY.L; in     returntx.r<TY.R; - } to voidAddintXintv) + { -      while(x<=N) the     { *c[x]+=v; $x+=x& (-x);Panax Notoginseng     } - } the intSumintx) + { A     intret=0; the      while(x>0) +     { -ret+=C[x]; $x-=x& (-x); $     } -     returnret; - } the intMainvoid) - {Wuyi     intm,t=0; theCin>>n>>m; -memset (Q,0,sizeof(q)); WuMemset (Last,0,sizeof(last)); -Memset (A,0,sizeof(a)); About      for(intI=1; i<=n;i++) $         { -scanf"%d",&t); -last[i]=A[t]; -a[t]=i; A         } +      for(intI=0; i<m;i++) thescanf"%d%d", &AMP;Q[I].L,&AMP;Q[I].R), q[i].id=i; -Sort (q,q+m,cmp); $Memset (c,0,sizeof(c)); thet=0; the      for(intI=0; i<m;i++) the     { the          while(t<Q[I].R) -T++,add (last[t]+1,1), Add (t+1,-1); inans[q[i].id]=sum (Q[I].L); the     } the      for(intI=0; i<m;i++) Aboutprintf"%d\n", Ans[i]); the     return 0; the}
View Code

hdu1342 learned and Jia Tiecheng

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.