C-number of Ways
Direct violence was sought in the past. Suppose you find the location of 1/3sum, then Mark + +. Find the 2/3 position, total plus the number of markers.
#include <stdio.h> #include <iostream> #include <stdlib.h> #include <string.h> #include < algorithm> #include <vector> #include <math.h> #include <queue> #include <stack> #include <map> #pragma COMMENT (linker, "/stack:1024000000,1024000000") using namespace std; #define MAXN 550000#define MoD 10000007#define LL __int64ll a[maxn];int main () {int n; while (~SCANF ("%d", &n)) {LL sum=0; for (int i=1;i<=n;i++) {scanf ("%i64d", &a[i]); Sum+=a[i]; } if (sum%3) {cout<< "0" <<endl; Continue } SUM=SUM/3; LL ans=0; LL now=0; LL s=0; for (int i=1;i<n;i++) {now+=a[i]; if (Sum*2==now) {ans+=s; } if (now==sum) {s++; }} cout<<ans<<endl; } return 0;}D-increase Sequence
First, change the An array into an H.
The b array is then derived from the forward difference to the a array.
CNT: Mark to current position, several L do not match R
Suppose B[i]==1:
Indicates the current position has a l,cnt++;
Suppose b[i]==0:
1, there's nothing in the current position.
2, the current position has an L, an R.
Because there is an L, so cnt++.
There is an R. So the total *=cnt,cnt--;
Equivalent to Total *= (cnt+1);
Suppose B[i]==-1:
The current position has an R, so the total *=cnt,cnt--;
Suppose B[i] is not equal to the above three cases, explain no solution!
#include <stdio.h> #include <iostream> #include <stdlib.h> #include <string.h> #include < algorithm> #include <vector> #include <math.h> #include <queue> #include <stack> #include <map> #pragma COMMENT (linker, "/stack:1024000000,1024000000") using namespace std; #define MAXN 550000#define MoD 1000000007#define LL __int64ll A[MAXN]; LL B[maxn];int Main () {int n,h; while (~SCANF ("%d%d", &n,&h)) {for (int i=1;i<=n;i++) scanf ("%i64d", &a[i]); for (int i=1;i<=n;i++) a[i]=h-a[i]; for (int i=1;i<=n+1;i++) {b[i]=a[i]-a[i-1]; } LL Ans=1; LL cnt=0; for (int i=1;i<=n+1;i++) {if (b[i]==1) {cnt++; } else if (b[i]==-1) {ans=ans* (CNT)%mod; cnt--; } else if (b[i]==0) {ans=ans* (cnt+1)%mod; } else {ans=0;break; } Ans=ans%mod; } cout<<ans<<endl; } return 0;}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Codeforces Round #266 (Div. 2)-c,d