problem B: [noip2016 10 even test eighth] descending son of LevinTime Limit:10 Sec Memory limit:512 MB
submit:39 solved:20
[Submit] [Status] [Web Board]
Description
Son of Levin Harmon is fond of thunder, he wants to find magic lightning. Harmon has n wires in a row, each wire has a resistance value, magic light can only from a wire to the higher resistance than it, and must be from the left to the right conduction, of course, the wire does not have to be continuous. Harmon wanted to know how many wires the lightning could pass, and how many of these were there. Input The first row of two integers n and type. Type represents the data type
The second row of n integers represents the resistor.
n<=100000, the resistor value does not exceed 100000 Output The first line an integer indicates how many wires the lightning can pass.
If the type=1 needs to output the second line, indicating the number of scenarios, modulo 123456789.
Sample Input
5 1
1 3 2 5 4
Sample Output
3
4
HINT
"Solving" "the longest ascending subsequence +next Array (good felling, in fact, it should be a line tree, but the data is very weak ...) )】
"O (n log n) to find the longest ascending subsequence, use the heap to do"
#include <cstdio> #include <cstring> #include <algorithm> #define MOD 123456789 using namespace std;
int f[100010],top,g[100010],ans[100010];
int A[100010],nxt[100010],p[100010],num[100010],tot;
int n,opt; inline void Add (int x,int y,int val) {tot++; a[tot]=y; nxt[tot]=p[x]; p[x]=tot; num[tot]=val;} inline void Solve (int
X,int val) {if (x==1) {Add (x,val,1); ans[x]++; return;}
int cnt=0;
For (int. I=p[x-1];i!=-1;i=nxt[i]) if (a[i]>=val) break;
else Cnt+=num[i],cnt%=mod; ans[x]+=cnt;
Ans[x]%=mod;
Add (X,val,cnt%mod);
} inline void Ask (int nm,int len,int x) {int l=1,r=len,mid;
while (l<=r) {mid= (l+r) >>1;
if (f[mid]<x) l=mid+1;
else r=mid-1;
} f[l]=x;
if (opt==1) g[nm]=l,solve (l,x);
} int main () {//freopen ("hamon9.in", "R", stdin);
int i,j;
memset (P,-1,sizeof (p));
memset (nxt,-1,sizeof (NXT));
scanf ("%d%d", &n,&opt);
for (I=1;i<=n;++i) { int x;
scanf ("%d", &x);
if (X>f[top]) {f[++top]=x;
if (opt==1) g[i]=top,solve (top,x);
} else ask (i,top,x);
} if (opt==1) printf ("%d\n%d\n", top,ans[top]%mod);
else printf ("%d\n", top);
return 0; }