題意:給你乙個長度不超過3000的陣列a,計算(i,j,k,l)的數量,其中滿足a[i]==a[k],a[j]==a[l]。
思路:從後到前列舉k,並且記錄每個數字出現的次數字尾和,再從k開始向前列舉i,並且每列舉乙個i、就對這一段中維護答案,最後碰到a[i]==a[k]的情況,就統計答案。
**:
#include
#pragma gcc optimize("ofast")
#define endl '\n'
#define null null
#define ls p<<1
#define rs p<<1|1
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define int long long
#define pii pair
#define pdd pair
#define lowbit(x) x&-x
#define unmap unordered_map
#define all(x) x.begin(),x.end()
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ct cerr<<"time elapsed:"<<1.0*clock()/clocks_per_sec<<"s.\n";
char
*fs,
*ft,buf[
1<<20]
;#define gc() (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<20,stdin),fs==ft))?0:*fs++;
inline
intread()
while
(ch>=
'0'&&ch<=
'9')
return x*f;
}using
namespace std;
const
int n=
1e4+
1000
;const
int inf=
0x3f3f3f3f
;const
int mod=
1e9+7;
const
double eps=
1e-6
;const
double pi=
acos(-
1);int a[n]
,b[n]
;signed
main()
sum+
=b[a[i]];
} b[a[k]]++
;}cout<}}
隨機數計數和計數排序
include include include 隨機數生成 void main for int m 50 m 100 m if count max count 0 printf n d dci num,max 2,計數排序 include intmain void 定義乙個足夠大的陣列,大於使用者輸...
字尾和 推公式
題意 n個數,分為k組,每組的數字的下標是連續的,則分組的代價為 組號 數字 例如3個數1,2,3,分為2組,這麼分組的代價為1 1 1 2 2 3。n,k 3e5。題解 1.假設pi是第i組的第1個數字的下標,sum i 是第i個數到第n個數求和。那麼分組的代價為1 sum p1 sum p2 2...
count and say 計數和發言
the count and say sequence is the sequence of integers beginning as follows 1,11,21,1211,111221,1is read off as one 1 or11.11is read off as two 1s or2...