Topic Portal
1 /*2 from the big to the small sort, reverse thinking, from the last to consider, no-go sex3 each found a not submerged, to it about the floor of the query whether it is isolated, if + +, if not--4 complexity O (n + m), thought O (n^2) was scared to write half of it.5 */6#include <cstdio>7#include <cstring>8#include <iostream>9#include <algorithm>Ten#include <map> One#include <Set> A#include <string> - using namespacestd; - the Const intMAXN = 1e6 +Ten; - Const intINF =0x3f3f3f3f; - structHight - { + intVal, id; - }H[MAXN]; + intQ[MAXN]; A intVIS[MAXN]; at intANS[MAXN]; - - BOOLCMP (Hight A, Hight b) - { - returnA.val >B.val; - } in - intMainvoid)//Acdream 1205 disappeared Block to { + //freopen ("j.in", "R", stdin); - the intT; * intN, M; $ Panax Notoginsengscanf ("%d", &t); - intCAS =0; the while(t--) + { Amemset (Vis,0,sizeof(Vis)); thescanf ("%d%d", &n, &m); + for(intI=1; i<=n; ++i) - { $scanf ("%d", &h[i].val); $H[i].id =i; - } - for(intI=1; i<=m; ++i) scanf ("%d", &q[i]); the -Sort (H +1, H +1+N, CMP);Wuyi the intCNT =0;intres =0; - for(intI=1, J=m; j>=1; --j) Wu { - for(; i<=n; + +i) About { $ if(H[i].val <= q[j]) Break; - intpos =h[i].id; -Vis[h[i].id] =1; - if(!vis[pos-1] &&!vis[pos+1]) res++; A if(vis[pos-1] && vis[pos+1]) res--; + } theANS[J] =Res; - } $printf ("Case #%d:", ++CAs); the for(intI=1; i<=m; ++i) printf ("%d%c", Ans[i], (i==m)?'\ n':' '); the } the the - return 0; in } the the /* About Case #1:1 1 2 the Case #2:1 2 1 1 0 the */
Sort + Reverse Thinking Acdream 1205 disappeared Block