Title Link: Http://codeforces.com/problemset/problem/216/D
Test instructions
For a trapezoidal area, if the trapezoid left points! = The number of points to the right of the trapezoid, then this trapezoid is red, otherwise green,
Ask:
How many red in a given spider's web.
2 tree-like arrays maintain 2 segments. Then brute-force simulation, because a lot of points but need to use the line tree only 3, so similar to the idea of scrolling array to optimize memory.
#include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include < Vector> #include <set>using namespace std; #define N 10010#define L (x) (x<<1) #define R (x) (x<<1|1) # Define LL intint maxn;struct hehe{int c[100505];void init () {memset (c, 0, sizeof c);} inline int lowbit (int x) {return x& (-X);} void change (int i, int x)//i point increment is x {while (I <= MAXN) {C[i] + = x; i + = Lowbit (i); }} int sum (int x) {//Interval sum [1,x] int ans = 0; for (int i = x; I >= 1; I-= Lowbit (i)) ans + = c[i]; return ans; }}tree[2];int ans;vector<int>l,r,o;void Work () {if (O.size () <=1) Return;tree[0].init (), Tree[1].init (); for ( int i = 0; I < l.size (); i++) Tree[0].change (l[i],1); for (int i = 0; i < r.size (); i++) Tree[1].change (r[i],1); int L = o[0];for (int i = 1; i < o . Size (); i++) {int R = o[i];if (l+1<=r-1) {int Z = tree[0].sum (R-1)-tree[0].sum (l); int Y = Tree[1].sum (R-1)-tree[1].sum (L); ans + = (z!=y);} L = R;}} VECTOR<INT>A,TMP1, Red, TMP2, Tmpend;void Red () {red.clear (); int hhh,eee; scanf ("%d", &hhh), while (hhh--) {scanf ("%d", &eee); Red.push_back (EEE);} Sort (Red.begin (), Red.end ());} int N;int Main () {int i,j,num;maxn = 100010;while (~scanf ("%d", &n)) {ans = 0;l.clear (); R.clear (); Tmp1.clear (); A.clear (); Tmp2.clear (); Tmpend.clear (); Red (); l = TMP1 = red; Red (); tmp2 = O = red;for (i = 3; I <= n; i++) {red (); r = red;if (i==n) tmpend = Red;work (); l = O;o = r;} R = Tmp1;work (); l = Tmpend;o = Tmp1;r = Tmp2;work (); Cout<<ans<<endl;} return 0;} /*32 1 1 3 1 3 2ans:02*//*ll n,m,k;ll a[n];ll gcd (ll x,ll y) {if (x>y) swap (x, y); return y;} int main () {ll I, J, u, V, que;while (cin>>n>>m>>k) {for (i = 1; I <= n; i++) Cin>>a[i];ll _GCD = a[ 1];for (i = 2; I <= n; i++) _gcd = gcd (_gcd,a[i]); for (i = 1; I <= n; i++) a[i]/=_gcd;} return 0;} /**/