傳送門
2.對於三個不相交的連續區間a,b
,ca,b,c
a,b,
c,如下所示:
我們可以發現對應排列有以下六種情況:
3.對於上面的每種情況,我們設從左向右分別是x,y
,zx,y,z
x,y,
z。不難想到我們需要在區間[x,
n−z]
[x,n-z]
[x,n−z
]內列舉所有長度為y
yy的線段,問題便轉化為,求區間[1,
n−y−
z][1,n-y-z]
[1,n−y
−z]內每個字首的長度為x
xx的最大區間;求區間[x+
y+1,
n][x+y+1,n]
[x+y+1
,n]內的每個字尾的長度為z
zz的最大區間。那麼我們只需預處理字首字尾,然後預處理長度為x
xx的區間右端點結束的最大值,長度為z
zz的區間左端點起始的最大值。這樣之後在列舉y
yy,就很容易求出答案了
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ins insert
#define lowbit
(x)(x&
(-x)
)#define mkp
(x,y)
make_pair
(x,y)
#define mem
(a,x)
memset
(a,x,sizeof a)
;typedef long
long ll;
typedef long
double ld;
typedef unsigned long
long ull;
typedef pair<
int,
int>
p;const
double eps=
1e-8
;const
double pi=
acos(-
1.0)
;const
int inf=
0x3f3f3f3f
;const ll inf=
1e18
;const
int mod=
1e9+7;
const
int maxn=
1e6+10;
int prime[maxn/3]
,num[maxn]
,fac[maxn]
;ll pre[maxn]
,sub[maxn]
;ll l[maxn]
,r[maxn]
;int cnt,n;
void
euler()
for(
int j=0;
(tmp=i*prime[j]
)}ll solve
(int x,
int y,
int z)
res=0;
for(
int i=n;i-z+
1>=m2;i--
) ll ans=0;
for(
int i=x;i+y<=n-z;i++
)return ans;
}int
main()
pre[0]
=sub[n+1]
=0;for
(int i=
1;i<=n;i++
) pre[i]
=pre[i-1]
+num[i]
;for
(int i=n;i>=
1;i--
) sub[i]
=sub[i+1]
+num[i]
; ll ans=0;
ans=
max(ans,
solve
(a,b,c));
ans=
max(ans,
solve
(a,c,b));
ans=
max(ans,
solve
(b,a,c));
ans=
max(ans,
solve
(b,c,a));
ans=
max(ans,
solve
(c,a,b));
ans=
max(ans,
solve
(c,b,a));
printf
("%lld\n"
,ans);}
return0;
}
FJNUOJ 1053 線段樹or前字尾預處理
時間限制 1 sec 記憶體限制 128 mb 提交 18 解決 5 提交 狀態 討論版 命題人 外部匯入 題目描述 輸入有多組輸入樣例,第一行兩個正整數n,m n m 分別表示黃主任他們的人數和第五排的座位數 n 20,m 1e6 第二行輸入m個整數,第i個數表示第i個座位的觀影值ai 1e9 a...
關於常量的前字尾
常量例如12.5或者hello,在c primer中稱為文字常量,他們通常不可定址,即使他們儲存在記憶體裡,但我們無法訪問他們。文字常量適用於c 的資料分類,廢話?在常量後面加乙個字母來說明其資料型別。預設情況下,整形文字常量被認為是int型,浮點型文字常量被認為是double型。為了改變預設整形常...
c 使用前字尾表示常量的型別
字元或字串常量使用字首 prifix meaning type uunicode 16 character char16 t u.32 32 lwide character wchar t u8utf 8 string literals only char 整型字元常量 suiffix minimu...