http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1335
Test instructions
- Given the height of the N-bridge, the swollen water level AI and the water level bi are given each time the M flood
- Ask how many bridges are flooded more than or equal to K
- The water level at the beginning of the flood was 1.
Ideas
- Each bridge is flooded once: the water level at the beginning is less than the height of the bridge, the water level at the highest point of the flood is not less than the height of the bridge, if there is a bridge with a height of 5, the number of flooding for data 7 6 and 7 3 is 1 (see 5 in the interval (1,7))
- The N-bridge sequence, each flood has an interval of the bridge is flooded, asked the last how many times each bridge was flooded
- This is the bare scan line, or the tree array range to modify a single point of query can also
"AC"
1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <string>5#include <cstring>6 using namespacestd;7typedefLong Longll;8 9 Const intmaxn=1e5+2;Ten intA[MAXN]; One intn,m,k; A intF[MAXN]; - voidInit () - { theMemset (F,0,sizeof(f)); - } - intMain () - { + intcas=0; - while(~SCANF ("%d%d%d",&n,&m,&k)) + { A init (); at for(intI=1; i<=n;i++) - { -scanf"%d",&a[i]); - } -Sort (A +1, a+n+1); - intx, y; in intst=1, ed; - for(intI=1; i<=m;i++) to { +scanf"%d%d",&x,&y); -Ed=x; the intPos1=upper_bound (A +1, A +1+N,ST)-A; * intPos2=upper_bound (A +1, A +1+n,ed)-a-1; $f[pos1]++;Panax Notoginsengf[pos2+1]--; -st=y; the } + intans=0; A ints=0; the for(intI=1; i<=n;i++) + { -s+=F[i]; $ if(s>=k) ans++; $ } -printf"Case %d:%d\n",++Cas,ans); - } the return 0; -}
Scan Line
1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <string>5#include <cstring>6 using namespacestd;7typedefLong Longll;8 9 Const intmaxn=1e5+2;Ten intA[MAXN]; One intTREE[MAXN]; A intn,m,k; - intLowbit (intx) - { the returnx& (-x); - } - voidAddintKintx) - { + while(k<=N) - { +tree[k]+=x; Ak+=Lowbit (k); at } - } - intQueryintk) - { - intres=0; - while(k) in { -res+=Tree[k]; tok-=Lowbit (k); + } - returnRes; the } * voidInit () $ {Panax Notoginsengmemset (Tree,0,sizeof(tree)); - } the intMain () + { A intcas=0; the while(~SCANF ("%d%d%d",&n,&m,&k)) + { - init (); $ for(intI=1; i<=n;i++) $ { -scanf"%d",&a[i]); - } theSort (A +1, a+n+1); - intx, y;Wuyi intst=1, ed; the for(intI=1; i<=m;i++) - { Wuscanf"%d%d",&x,&y); -Ed=x; About intPos1=upper_bound (A +1, A +1+N,ST)-A; $ intPos2=upper_bound (A +1, A +1+n,ed)-a-1; -Add (POS1,1); -Add (pos2+1,-1); -st=y; A } + intans=0; the for(intI=1; i<=n;i++) - { $ if(Query (i) >=k) the { theans++; the } the } -printf"Case %d:%d\n",++Cas,ans); in } the return 0; the}
tree-like array interval modified single point query
"Scan line or tree-like array" CSU 1335 Takahashi and Low bridge